Repository: withastro/astro
File: packages/astro/src/core/routing/manifest/create.ts (TypeScript)

Code before:
									pathname,
									route,
									segments,
									generate,
									pattern: getPattern(segments, config.base, config.trailingSlash),
									type: 'fallback',
									fallbackRoutes: [],
								};
								const routeData = routes[index];
								routeData.fallbackRoutes.push(fallbackRoute);
							}
						}
					}
				}
			}
		}
	}

	if (dev) {
		// In SSR, a 404 route is injected in the App directly for some special handling,
		// it must not appear in the manifest
		ensure404Route({ routes });
	}
	if (dev || settings.buildOutput === 'server') {
		injectImageEndpoint(settings, { routes }, dev ? 'dev' : 'build');
		// During the build build, we can't only inject this route when server islands are used because:
		// - To know if we use serve islands, we need to build
		// - The build runs before we can inject the server island route
		injectServerIslandRoute(settings.config, { routes });
	}
	await runHookRoutesResolved({ routes, settings, logger });

	return {
		routes,
	};
}

export function resolveInjectedRoute(entrypoint: string, root: URL, cwd?: string) {
	let resolved;
	try {
		resolved = require.resolve(entrypoint, { paths: [cwd || fileURLToPath(root)] });
	} catch {
		resolved = fileURLToPath(new URL(entrypoint, root));
	}

	return {
		resolved: resolved,
		component: slash(path.relative(cwd || fileURLToPath(root), resolved)),
	};
}


Review comment (bug):
this comments a little confusing.

I'm not sure what happens today if you have a static project with only server islands. Does it generate a server build or not? If it does, then I think this change will break it. If not, that's a bug but probably not one that this affects.

Could you test this and confirm what happens?

Code after:
									pathname,
									route,
									segments,
									generate,
									pattern: getPattern(segments, config.base, config.trailingSlash),
									type: 'fallback',
									fallbackRoutes: [],
								};
								const routeData = routes[index];
								routeData.fallbackRoutes.push(fallbackRoute);
							}
						}
					}
				}
			}
		}
	}

	if (dev) {
		// In SSR, a 404 route is injected in the App directly for some special handling,
		// it must not appear in the manifest
		ensure404Route({ routes });
	}
	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.
		// Unforunately, 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 wether 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.
		injectServerIslandRoute(settings.config, { routes });
	}
	await runHookRoutesResolved({ routes, settings, logger });

	return {
		routes,
	};
}

export function resolveInjectedRoute(entrypoint: string, root: URL, cwd?: string) {
	let resolved;
	try {
		resolved = require.resolve(entrypoint, { paths: [cwd || fileURLToPath(root)] });
	} catch {
		resolved = fileURLToPath(new URL(entrypoint, root));
	}

	return {
		resolved: resolved,
		component: slash(path.relative(cwd || fileURLToPath(root), resolved)),