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
7 changes: 0 additions & 7 deletions e2e/react-start/selective-ssr/src/routes/__root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'}`,
)
Expand Down
7 changes: 0 additions & 7 deletions e2e/react-start/selective-ssr/src/routes/posts.$postId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'}`,
)
Expand Down
7 changes: 0 additions & 7 deletions e2e/react-start/selective-ssr/src/routes/posts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'}`,
)
Expand Down
7 changes: 0 additions & 7 deletions e2e/solid-start/selective-ssr/src/routes/__root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'}`,
)
Expand Down
7 changes: 0 additions & 7 deletions e2e/solid-start/selective-ssr/src/routes/posts.$postId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'}`,
)
Expand Down
7 changes: 0 additions & 7 deletions e2e/solid-start/selective-ssr/src/routes/posts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'}`,
)
Expand Down
1 change: 1 addition & 0 deletions packages/router-core/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,7 @@ export class RouterCore<

match = {
id: matchId,
ssr: this.isServer ? undefined : route.options.ssr,
index,
routeId: route.id,
params: previousMatch
Expand Down
8 changes: 8 additions & 0 deletions packages/router-core/src/ssr/ssr-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ export async function hydrate(router: AnyRouter): Promise<any> {
}
}

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
Expand All @@ -146,10 +152,12 @@ export async function hydrate(router: AnyRouter): Promise<any> {
if (!dehydratedMatch) {
match._nonReactive.dehydrated = false
match.ssr = false
setRouteSsr(match)
return
}

hydrateMatch(match, dehydratedMatch)
setRouteSsr(match)

match._nonReactive.dehydrated = match.ssr !== false

Expand Down
Loading