Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions packages/router-core/src/ssr/ssr-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/start-server-core/src/router-manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>
assets?: Array<RouterManagedTag>
Expand All @@ -53,7 +53,7 @@ export async function getStartManifest() {
if (!hasData) {
return []
}
return [k, result]
return [[k, result]]
}),
),
}
Expand Down
Loading