diff options
author | 2025-01-17 23:25:51 +0800 | |
---|---|---|
committer | 2025-01-17 23:25:51 +0800 | |
commit | 429aa7547572915b5f7f9a4146529e704069128b (patch) | |
tree | f1d623dc169341e57d545385fc86916b8a56aad0 | |
parent | 80c6801b4f2b9da44ed69d6da7e4dbd4d65aae69 (diff) | |
download | astro-429aa7547572915b5f7f9a4146529e704069128b.tar.gz astro-429aa7547572915b5f7f9a4146529e704069128b.tar.zst astro-429aa7547572915b5f7f9a4146529e704069128b.zip |
Fix server islands for prerender-only sites (#12982)
-rw-r--r-- | .changeset/orange-suits-suffer.md | 5 | ||||
-rw-r--r-- | packages/astro/src/core/routing/manifest/create.ts | 13 | ||||
-rw-r--r-- | packages/astro/test/units/routing/manifest.test.js | 10 |
3 files changed, 13 insertions, 15 deletions
diff --git a/.changeset/orange-suits-suffer.md b/.changeset/orange-suits-suffer.md new file mode 100644 index 000000000..a2681beb5 --- /dev/null +++ b/.changeset/orange-suits-suffer.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fixes an issue where server islands do not work in projects that use an adapter but only have prerendered pages. If an adapter is added, the server island endpoint will now be added by default. diff --git a/packages/astro/src/core/routing/manifest/create.ts b/packages/astro/src/core/routing/manifest/create.ts index b0495a682..466876ee8 100644 --- a/packages/astro/src/core/routing/manifest/create.ts +++ b/packages/astro/src/core/routing/manifest/create.ts @@ -718,12 +718,13 @@ export async function createRouteManifest( } if (dev || settings.buildOutput === 'server') { injectImageEndpoint(settings, { routes }, dev ? 'dev' : 'build'); - // Ideally we would only inject the server islands route if server islands are used in the project. - // Unfortunately, there is a "circular dependency": to know if server islands are used, we need to run - // the build but the build relies on the routes manifest. - // This situation also means we cannot update the buildOutput based on whether or not server islands - // are used in the project. If server islands are detected after the build but the buildOutput is - // static, we fail the build. + } + + // If an adapter is added, we unconditionally inject the server islands route. + // Ideally we would only inject the server islands route if server islands are used in the project. + // Unfortunately, there is a "circular dependency": to know if server islands are used, we need to run + // the build but the build relies on the routes manifest. + if (dev || settings.config.adapter) { injectServerIslandRoute(settings.config, { routes }); } await runHookRoutesResolved({ routes, settings, logger }); diff --git a/packages/astro/test/units/routing/manifest.test.js b/packages/astro/test/units/routing/manifest.test.js index a981b8719..1567126b8 100644 --- a/packages/astro/test/units/routing/manifest.test.js +++ b/packages/astro/test/units/routing/manifest.test.js @@ -261,10 +261,6 @@ describe('routing - createRouteManifest', () => { assert.deepEqual(getManifestRoutes(manifest), [ { - route: '/_server-islands/[name]', - type: 'page', - }, - { route: '/_image', type: 'endpoint', }, @@ -314,10 +310,7 @@ describe('routing - createRouteManifest', () => { }); assert.deepEqual(getManifestRoutes(manifest), [ - { - route: '/_server-islands/[name]', - type: 'page', - }, + { route: '/_image', type: 'endpoint', @@ -457,7 +450,6 @@ describe('routing - createRouteManifest', () => { }); assert.deepEqual(getManifestRoutes(manifest), [ - { type: 'page', route: '/_server-islands/[name]' }, { type: 'endpoint', route: '/_image' }, { type: 'endpoint', route: '/blog/a-[b].233' }, { type: 'redirect', route: '/posts/a-[b].233' }, |