Fix server islands for prerender-only sites (#12982)

This commit is contained in:
Bjorn Lu 2025-01-17 23:25:51 +08:00 committed by GitHub
parent 80c6801b4f
commit 429aa75475
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 15 deletions

View file

@ -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.

View file

@ -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 });

View file

@ -260,10 +260,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' },