diff --git a/e2e/react-start/selective-ssr/src/routes/__root.tsx b/e2e/react-start/selective-ssr/src/routes/__root.tsx index 943c852ecbd..1672e3ff687 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 b0380c90081..91fd9a03291 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 70eceb9306f..fd8fda20b21 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 767dcb36517..59fc3c90822 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 340667540d3..cd07480c92f 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 8cdd24c4cf7..a3e5b6a6b85 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'}`, ) diff --git a/packages/router-core/src/router.ts b/packages/router-core/src/router.ts index 8507ba9cdcd..4efaa61b7b7 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 4f52ca66a24..419782beb44 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