From b8fe14708aad74aa5fd5219d3d5f0c83b472ac11 Mon Sep 17 00:00:00 2001 From: Manuel Schiller Date: Tue, 25 Nov 2025 20:59:28 +0100 Subject: [PATCH 1/2] fix: no remounting with ssr:false fixes #5956 --- packages/router-core/src/router.ts | 1 + packages/router-core/src/ssr/ssr-client.ts | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/packages/router-core/src/router.ts b/packages/router-core/src/router.ts index 8507ba9cdc..4efaa61b7b 100644 --- a/packages/router-core/src/router.ts +++ b/packages/router-core/src/router.ts @@ -1446,6 +1446,7 @@ export class RouterCore< match = { id: matchId, + ssr: this.isServer ? undefined : route.options.ssr, index, routeId: route.id, params: previousMatch diff --git a/packages/router-core/src/ssr/ssr-client.ts b/packages/router-core/src/ssr/ssr-client.ts index 4f52ca66a2..419782beb4 100644 --- a/packages/router-core/src/ssr/ssr-client.ts +++ b/packages/router-core/src/ssr/ssr-client.ts @@ -136,6 +136,12 @@ export async function hydrate(router: AnyRouter): Promise { } } + function setRouteSsr(match: AnyRouteMatch) { + const route = router.looseRoutesById[match.routeId] + if (route) { + route.options.ssr = match.ssr + } + } // Right after hydration and before the first render, we need to rehydrate each match // First step is to reyhdrate loaderData and __beforeLoadContext let firstNonSsrMatchIndex: number | undefined = undefined @@ -146,10 +152,12 @@ export async function hydrate(router: AnyRouter): Promise { if (!dehydratedMatch) { match._nonReactive.dehydrated = false match.ssr = false + setRouteSsr(match) return } hydrateMatch(match, dehydratedMatch) + setRouteSsr(match) match._nonReactive.dehydrated = match.ssr !== false From fba306fb1ace51feb0c12b931bb3f0754923e081 Mon Sep 17 00:00:00 2001 From: Manuel Schiller Date: Tue, 25 Nov 2025 21:01:11 +0100 Subject: [PATCH 2/2] fix tests --- e2e/react-start/selective-ssr/src/routes/__root.tsx | 7 ------- e2e/react-start/selective-ssr/src/routes/posts.$postId.tsx | 7 ------- e2e/react-start/selective-ssr/src/routes/posts.tsx | 7 ------- e2e/solid-start/selective-ssr/src/routes/__root.tsx | 7 ------- e2e/solid-start/selective-ssr/src/routes/posts.$postId.tsx | 7 ------- e2e/solid-start/selective-ssr/src/routes/posts.tsx | 7 ------- 6 files changed, 42 deletions(-) diff --git a/e2e/react-start/selective-ssr/src/routes/__root.tsx b/e2e/react-start/selective-ssr/src/routes/__root.tsx index 943c852ecb..1672e3ff68 100644 --- a/e2e/react-start/selective-ssr/src/routes/__root.tsx +++ b/e2e/react-start/selective-ssr/src/routes/__root.tsx @@ -42,13 +42,6 @@ export const Route = createRootRoute({ } }, beforeLoad: ({ search }) => { - if (typeof window !== 'undefined') { - if (Route.options.ssr !== undefined) { - const error = `ssr() for ${Route.id} should have been deleted from the Route options on the client` - console.error(error) - throw new Error(error) - } - } console.log( `beforeLoad for ${Route.id} called on the ${typeof window !== 'undefined' ? 'client' : 'server'}`, ) diff --git a/e2e/react-start/selective-ssr/src/routes/posts.$postId.tsx b/e2e/react-start/selective-ssr/src/routes/posts.$postId.tsx index b0380c9008..91fd9a0329 100644 --- a/e2e/react-start/selective-ssr/src/routes/posts.$postId.tsx +++ b/e2e/react-start/selective-ssr/src/routes/posts.$postId.tsx @@ -15,13 +15,6 @@ export const Route = createFileRoute('/posts/$postId')({ } }, beforeLoad: ({ search }) => { - if (typeof window !== 'undefined') { - if (Route.options.ssr !== undefined) { - const error = `ssr() for ${Route.id} should have been deleted from the Route options on the client` - console.error(error) - throw new Error(error) - } - } console.log( `beforeLoad for ${Route.id} called on the ${typeof window !== 'undefined' ? 'client' : 'server'}`, ) diff --git a/e2e/react-start/selective-ssr/src/routes/posts.tsx b/e2e/react-start/selective-ssr/src/routes/posts.tsx index 70eceb9306..fd8fda20b2 100644 --- a/e2e/react-start/selective-ssr/src/routes/posts.tsx +++ b/e2e/react-start/selective-ssr/src/routes/posts.tsx @@ -15,13 +15,6 @@ export const Route = createFileRoute('/posts')({ } }, beforeLoad: ({ search }) => { - if (typeof window !== 'undefined') { - if (Route.options.ssr !== undefined) { - const error = `ssr() for ${Route.id} should have been deleted from the Route options on the client` - console.error(error) - throw new Error(error) - } - } console.log( `beforeLoad for ${Route.id} called on the ${typeof window !== 'undefined' ? 'client' : 'server'}`, ) diff --git a/e2e/solid-start/selective-ssr/src/routes/__root.tsx b/e2e/solid-start/selective-ssr/src/routes/__root.tsx index 767dcb3651..59fc3c9082 100644 --- a/e2e/solid-start/selective-ssr/src/routes/__root.tsx +++ b/e2e/solid-start/selective-ssr/src/routes/__root.tsx @@ -42,13 +42,6 @@ export const Route = createRootRoute({ } }, beforeLoad: ({ search }) => { - if (typeof window !== 'undefined') { - if (Route.options.ssr !== undefined) { - const error = `ssr() for ${Route.id} should have been deleted from the Route options on the client` - console.error(error) - throw new Error(error) - } - } console.log( `beforeLoad for ${Route.id} called on the ${typeof window !== 'undefined' ? 'client' : 'server'}`, ) diff --git a/e2e/solid-start/selective-ssr/src/routes/posts.$postId.tsx b/e2e/solid-start/selective-ssr/src/routes/posts.$postId.tsx index 340667540d..cd07480c92 100644 --- a/e2e/solid-start/selective-ssr/src/routes/posts.$postId.tsx +++ b/e2e/solid-start/selective-ssr/src/routes/posts.$postId.tsx @@ -15,13 +15,6 @@ export const Route = createFileRoute('/posts/$postId')({ } }, beforeLoad: ({ search }) => { - if (typeof window !== 'undefined') { - if (Route.options.ssr !== undefined) { - const error = `ssr() for ${Route.id} should have been deleted from the Route options on the client` - console.error(error) - throw new Error(error) - } - } console.log( `beforeLoad for ${Route.id} called on the ${typeof window !== 'undefined' ? 'client' : 'server'}`, ) diff --git a/e2e/solid-start/selective-ssr/src/routes/posts.tsx b/e2e/solid-start/selective-ssr/src/routes/posts.tsx index 8cdd24c4cf..a3e5b6a6b8 100644 --- a/e2e/solid-start/selective-ssr/src/routes/posts.tsx +++ b/e2e/solid-start/selective-ssr/src/routes/posts.tsx @@ -15,13 +15,6 @@ export const Route = createFileRoute('/posts')({ } }, beforeLoad: ({ search }) => { - if (typeof window !== 'undefined') { - if (Route.options.ssr !== undefined) { - const error = `ssr() for ${Route.id} should have been deleted from the Route options on the client` - console.error(error) - throw new Error(error) - } - } console.log( `beforeLoad for ${Route.id} called on the ${typeof window !== 'undefined' ? 'client' : 'server'}`, )