diff --git a/packages/router-core/src/ssr/ssr-server.ts b/packages/router-core/src/ssr/ssr-server.ts index 8854b36b24b..85d03824983 100644 --- a/packages/router-core/src/ssr/ssr-server.ts +++ b/packages/router-core/src/ssr/ssr-server.ts @@ -156,13 +156,33 @@ export function attachRouterServerSsrUtils({ const matches = matchesToDehydrate.map(dehydrateMatch) let manifestToDehydrate: Manifest | undefined = undefined - // only send manifest of the current routes to the client + // For currently matched routes, send full manifest (preloads + assets) + // For all other routes, only send assets (no preloads as they are handled via dynamic imports) if (manifest) { + const currentRouteIds = new Set( + router.state.matches.map((k) => k.routeId), + ) const filteredRoutes = Object.fromEntries( - router.state.matches.map((k) => [ - k.routeId, - manifest.routes[k.routeId], - ]), + Object.entries(manifest.routes).flatMap( + ([routeId, routeManifest]) => { + if (currentRouteIds.has(routeId)) { + return [[routeId, routeManifest]] + } else if ( + routeManifest.assets && + routeManifest.assets.length > 0 + ) { + return [ + [ + routeId, + { + assets: routeManifest.assets, + }, + ], + ] + } + return [] + }, + ), ) manifestToDehydrate = { routes: filteredRoutes, diff --git a/packages/start-server-core/src/router-manifest.ts b/packages/start-server-core/src/router-manifest.ts index f5249f454e2..8e6f268f977 100644 --- a/packages/start-server-core/src/router-manifest.ts +++ b/packages/start-server-core/src/router-manifest.ts @@ -36,7 +36,7 @@ export async function getStartManifest() { const manifest = { routes: Object.fromEntries( - Object.entries(startManifest.routes).map(([k, v]) => { + Object.entries(startManifest.routes).flatMap(([k, v]) => { const result = {} as { preloads?: Array assets?: Array @@ -53,7 +53,7 @@ export async function getStartManifest() { if (!hasData) { return [] } - return [k, result] + return [[k, result]] }), ), }