diff --git a/.changeset/healthy-ads-scream.md b/.changeset/healthy-ads-scream.md new file mode 100644 index 000000000000..f78bd6d5212d --- /dev/null +++ b/.changeset/healthy-ads-scream.md @@ -0,0 +1,13 @@ +--- +'astro': patch +--- + +Use GET requests with preloading for Server Islands + +Server Island requests include the props used to render the island as well as any slots passed in (excluding the fallback slot). Since browsers have a max 4mb URL length we default to using a POST request to avoid overflowing this length. + +However in reality most usage of Server Islands are fairly isolated and won't exceed this limit, so a GET request is possible by passing this same information via search parameters. + +Using GET means we can also include a `` tag to speed up the request. + +This change implements this, with safe fallback to POST. diff --git a/packages/astro/e2e/fixtures/server-islands/src/components/Island.astro b/packages/astro/e2e/fixtures/server-islands/src/components/Island.astro index 5eab0dc4dfc3..3daa55615e7d 100644 --- a/packages/astro/e2e/fixtures/server-islands/src/components/Island.astro +++ b/packages/astro/e2e/fixtures/server-islands/src/components/Island.astro @@ -1,6 +1,7 @@ --- const { secret } = Astro.props; --- -

I am an island

+ +

I am an island

-

{secret}

+

{secret}

diff --git a/packages/astro/e2e/fixtures/server-islands/src/lorem.ts b/packages/astro/e2e/fixtures/server-islands/src/lorem.ts new file mode 100644 index 000000000000..74210474cd02 --- /dev/null +++ b/packages/astro/e2e/fixtures/server-islands/src/lorem.ts @@ -0,0 +1,9 @@ +const content = `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.`; + +export function generateLongText(paragraphs = 5) { + let arr = new Array(paragraphs); + for(let i = 0; i < paragraphs; i++) { + arr[i] = content; + } + return arr.join('\n'); +} diff --git a/packages/astro/e2e/fixtures/server-islands/src/pages/index.astro b/packages/astro/e2e/fixtures/server-islands/src/pages/index.astro index eff5df25e940..70a4fcabcb66 100644 --- a/packages/astro/e2e/fixtures/server-islands/src/pages/index.astro +++ b/packages/astro/e2e/fixtures/server-islands/src/pages/index.astro @@ -2,6 +2,9 @@ import Island from '../components/Island.astro'; import Self from '../components/Self.astro'; import HTMLError from '../components/HTMLError.astro'; +import { generateLongText } from '../lorem'; + +const content = generateLongText(5); --- @@ -9,11 +12,18 @@ import HTMLError from '../components/HTMLError.astro'; - -

children

-
+
+ +

children

+
+
+ +
+ +
+