Skip to content

Commit 369a09b

Browse files
fix: no remounting with ssr:false (#5964)
1 parent e41cdf2 commit 369a09b

File tree

8 files changed

+9
-42
lines changed

8 files changed

+9
-42
lines changed

e2e/react-start/selective-ssr/src/routes/__root.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@ export const Route = createRootRoute({
4242
}
4343
},
4444
beforeLoad: ({ search }) => {
45-
if (typeof window !== 'undefined') {
46-
if (Route.options.ssr !== undefined) {
47-
const error = `ssr() for ${Route.id} should have been deleted from the Route options on the client`
48-
console.error(error)
49-
throw new Error(error)
50-
}
51-
}
5245
console.log(
5346
`beforeLoad for ${Route.id} called on the ${typeof window !== 'undefined' ? 'client' : 'server'}`,
5447
)

e2e/react-start/selective-ssr/src/routes/posts.$postId.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ export const Route = createFileRoute('/posts/$postId')({
1515
}
1616
},
1717
beforeLoad: ({ search }) => {
18-
if (typeof window !== 'undefined') {
19-
if (Route.options.ssr !== undefined) {
20-
const error = `ssr() for ${Route.id} should have been deleted from the Route options on the client`
21-
console.error(error)
22-
throw new Error(error)
23-
}
24-
}
2518
console.log(
2619
`beforeLoad for ${Route.id} called on the ${typeof window !== 'undefined' ? 'client' : 'server'}`,
2720
)

e2e/react-start/selective-ssr/src/routes/posts.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ export const Route = createFileRoute('/posts')({
1515
}
1616
},
1717
beforeLoad: ({ search }) => {
18-
if (typeof window !== 'undefined') {
19-
if (Route.options.ssr !== undefined) {
20-
const error = `ssr() for ${Route.id} should have been deleted from the Route options on the client`
21-
console.error(error)
22-
throw new Error(error)
23-
}
24-
}
2518
console.log(
2619
`beforeLoad for ${Route.id} called on the ${typeof window !== 'undefined' ? 'client' : 'server'}`,
2720
)

e2e/solid-start/selective-ssr/src/routes/__root.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,6 @@ export const Route = createRootRoute({
4242
}
4343
},
4444
beforeLoad: ({ search }) => {
45-
if (typeof window !== 'undefined') {
46-
if (Route.options.ssr !== undefined) {
47-
const error = `ssr() for ${Route.id} should have been deleted from the Route options on the client`
48-
console.error(error)
49-
throw new Error(error)
50-
}
51-
}
5245
console.log(
5346
`beforeLoad for ${Route.id} called on the ${typeof window !== 'undefined' ? 'client' : 'server'}`,
5447
)

e2e/solid-start/selective-ssr/src/routes/posts.$postId.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ export const Route = createFileRoute('/posts/$postId')({
1515
}
1616
},
1717
beforeLoad: ({ search }) => {
18-
if (typeof window !== 'undefined') {
19-
if (Route.options.ssr !== undefined) {
20-
const error = `ssr() for ${Route.id} should have been deleted from the Route options on the client`
21-
console.error(error)
22-
throw new Error(error)
23-
}
24-
}
2518
console.log(
2619
`beforeLoad for ${Route.id} called on the ${typeof window !== 'undefined' ? 'client' : 'server'}`,
2720
)

e2e/solid-start/selective-ssr/src/routes/posts.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ export const Route = createFileRoute('/posts')({
1515
}
1616
},
1717
beforeLoad: ({ search }) => {
18-
if (typeof window !== 'undefined') {
19-
if (Route.options.ssr !== undefined) {
20-
const error = `ssr() for ${Route.id} should have been deleted from the Route options on the client`
21-
console.error(error)
22-
throw new Error(error)
23-
}
24-
}
2518
console.log(
2619
`beforeLoad for ${Route.id} called on the ${typeof window !== 'undefined' ? 'client' : 'server'}`,
2720
)

packages/router-core/src/router.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,6 +1446,7 @@ export class RouterCore<
14461446

14471447
match = {
14481448
id: matchId,
1449+
ssr: this.isServer ? undefined : route.options.ssr,
14491450
index,
14501451
routeId: route.id,
14511452
params: previousMatch

packages/router-core/src/ssr/ssr-client.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ export async function hydrate(router: AnyRouter): Promise<any> {
136136
}
137137
}
138138

139+
function setRouteSsr(match: AnyRouteMatch) {
140+
const route = router.looseRoutesById[match.routeId]
141+
if (route) {
142+
route.options.ssr = match.ssr
143+
}
144+
}
139145
// Right after hydration and before the first render, we need to rehydrate each match
140146
// First step is to reyhdrate loaderData and __beforeLoadContext
141147
let firstNonSsrMatchIndex: number | undefined = undefined
@@ -146,10 +152,12 @@ export async function hydrate(router: AnyRouter): Promise<any> {
146152
if (!dehydratedMatch) {
147153
match._nonReactive.dehydrated = false
148154
match.ssr = false
155+
setRouteSsr(match)
149156
return
150157
}
151158

152159
hydrateMatch(match, dehydratedMatch)
160+
setRouteSsr(match)
153161

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

0 commit comments

Comments
 (0)