Repository: withastro/astro
File: packages/astro/src/manifest/serialized.ts (TypeScript)

Code before:
			if (id === SERIALIZED_MANIFEST_RESOLVED_ID) {
				let manifestData: string;
				if (command === 'build') {
					// Emit placeholder token that will be replaced by plugin-manifest.ts in build:post
					// See plugin-manifest.ts for full architecture explanation
					manifestData = `'${MANIFEST_REPLACE}'`;
				} else {
					const serialized = await createSerializedManifest(settings);
					manifestData = JSON.stringify(serialized);
				}
				const code = `
					import { deserializeManifest as _deserializeManifest } from 'astro/app';
					import { renderers } from '${ASTRO_RENDERERS_MODULE_ID}';
					import { routes } from '${ASTRO_ROUTES_MODULE_ID}';
					import { pageMap } from '${VIRTUAL_PAGES_MODULE_ID}';

					const _manifest = _deserializeManifest((${manifestData}));
					const manifest = Object.assign(_manifest, {
					  renderers,
					  actions: () => import('${ACTIONS_ENTRYPOINT_VIRTUAL_MODULE_ID}'),
					  middleware: () => import('${MIDDLEWARE_MODULE_ID}'),
					  sessionDriver: () => import('${VIRTUAL_SESSION_DRIVER_ID}'),
					  serverIslandMappings: () => import('${SERVER_ISLAND_MANIFEST}'),
					  routes: _manifest.routes ?? routes,
					  pageMap,
					});
					export { manifest };
				`;
				return { code };
			}
		},
	};
}

async function createSerializedManifest(settings: AstroSettings): Promise<SerializedSSRManifest> {
	let i18nManifest: SSRManifestI18n | undefined;
	let csp: SSRManifestCSP | undefined;
	if (settings.config.i18n) {
		i18nManifest = {
			fallback: settings.config.i18n.fallback,
			strategy: toRoutingStrategy(settings.config.i18n.routing, settings.config.i18n.domains),
			defaultLocale: settings.config.i18n.defaultLocale,
			locales: settings.config.i18n.locales,
			domainLookupTable: {},
			fallbackType: toFallbackType(settings.config.i18n.routing),
			domains: settings.config.i18n.domains,
		};
	}

	if (shouldTrackCspHashes(settings.config.experimental.csp)) {
		csp = {

Review comment (bug):
Why was this changed? It doesn't seem correct to me, since `routes` should already have ALL the routes. I think if we're doing this, then there's a bug somewhere else. 

Code after:
			if (id === SERIALIZED_MANIFEST_RESOLVED_ID) {
				let manifestData: string;
				if (command === 'build') {
					// Emit placeholder token that will be replaced by plugin-manifest.ts in build:post
					// See plugin-manifest.ts for full architecture explanation
					manifestData = `'${MANIFEST_REPLACE}'`;
				} else {
					const serialized = await createSerializedManifest(settings);
					manifestData = JSON.stringify(serialized);
				}
				const code = `
					import { deserializeManifest as _deserializeManifest } from 'astro/app';
					import { renderers } from '${ASTRO_RENDERERS_MODULE_ID}';
					import { routes } from '${ASTRO_ROUTES_MODULE_ID}';
					import { pageMap } from '${VIRTUAL_PAGES_MODULE_ID}';

					const _manifest = _deserializeManifest((${manifestData}));
					const manifest = Object.assign(_manifest, {
					  renderers,
					  actions: () => import('${ACTIONS_ENTRYPOINT_VIRTUAL_MODULE_ID}'),
					  middleware: () => import('${MIDDLEWARE_MODULE_ID}'),
					  sessionDriver: () => import('${VIRTUAL_SESSION_DRIVER_ID}'),
					  serverIslandMappings: () => import('${SERVER_ISLAND_MANIFEST}'),
					  // _manifest.routes contains enriched route info with scripts and styles,
					  // while routes only has raw route data. Fallback to routes if _manifest.routes is not available.
					  routes: _manifest.routes ?? routes,
					  pageMap,
					});
					export { manifest };
				`;
				return { code };
			}
		},
	};
}

async function createSerializedManifest(settings: AstroSettings): Promise<SerializedSSRManifest> {
	let i18nManifest: SSRManifestI18n | undefined;
	let csp: SSRManifestCSP | undefined;
	if (settings.config.i18n) {
		i18nManifest = {
			fallback: settings.config.i18n.fallback,
			strategy: toRoutingStrategy(settings.config.i18n.routing, settings.config.i18n.domains),
			defaultLocale: settings.config.i18n.defaultLocale,
			locales: settings.config.i18n.locales,
			domainLookupTable: {},
			fallbackType: toFallbackType(settings.config.i18n.routing),
			domains: settings.config.i18n.domains,
		};
	}