Skip to content

Commit

Permalink
Fix server islands for prerender-only sites (#12982)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Jan 17, 2025
1 parent 80c6801 commit 429aa75
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/orange-suits-suffer.md
Original file line number Diff line number Diff line change
@@ -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.
13 changes: 7 additions & 6 deletions packages/astro/src/core/routing/manifest/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
10 changes: 1 addition & 9 deletions packages/astro/test/units/routing/manifest.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,6 @@ describe('routing - createRouteManifest', () => {
});

assert.deepEqual(getManifestRoutes(manifest), [
{
route: '/_server-islands/[name]',
type: 'page',
},
{
route: '/_image',
type: 'endpoint',
Expand Down Expand Up @@ -314,10 +310,7 @@ describe('routing - createRouteManifest', () => {
});

assert.deepEqual(getManifestRoutes(manifest), [
{
route: '/_server-islands/[name]',
type: 'page',
},

{
route: '/_image',
type: 'endpoint',
Expand Down Expand Up @@ -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' },
Expand Down

0 comments on commit 429aa75

Please sign in to comment.