Skip to content

Commit a64f926

Browse files
committed
move ssr to _nonReactive
1 parent ced2dbd commit a64f926

7 files changed

Lines changed: 36 additions & 37 deletions

File tree

‎docs/router/framework/react/api/router/RouteMatchType.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,5 @@ interface RouteMatch {
2424
fetchedAt: number
2525
abortController: AbortController
2626
cause: 'enter' | 'stay'
27-
ssr?: boolean | 'data-only'
2827
}
2928
```

‎packages/react-router/src/Match.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const Match = React.memo(function MatchImpl({
3838
)
3939
return {
4040
routeId: match.routeId,
41-
ssr: match.ssr,
41+
ssr: match._nonReactive.ssr,
4242
_displayPending: match._displayPending,
4343
}
4444
},

‎packages/router-core/src/Matches.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ export interface RouteMatch<
147147
displayPendingPromise?: Promise<void>
148148
minPendingPromise?: ControlledPromise<void>
149149
dehydrated?: boolean
150+
ssr?: boolean | 'data-only'
150151
}
151152
loaderData?: TLoaderData
152153
/** @internal */
@@ -165,7 +166,6 @@ export interface RouteMatch<
165166
headers?: Record<string, string>
166167
globalNotFound?: boolean
167168
staticData: StaticDataRouteOption
168-
ssr?: boolean | 'data-only'
169169
_forcePending?: boolean
170170
_displayPending?: boolean
171171
}

‎packages/router-core/src/router.ts‎

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,10 +2174,8 @@ export class RouterCore<
21742174
return true
21752175
}
21762176

2177-
if (this.isServer) {
2178-
if (match.ssr === false) {
2179-
return true
2180-
}
2177+
if (this.isServer && match._nonReactive.ssr === false) {
2178+
return true
21812179
}
21822180
return false
21832181
}
@@ -2248,15 +2246,13 @@ export class RouterCore<
22482246
ssr = matchId === rootRouteId
22492247
} else {
22502248
const defaultSsr = this.options.defaultSsr ?? true
2251-
if (parentMatch?.ssr === false) {
2249+
if (parentMatch?._nonReactive.ssr === false) {
22522250
ssr = false
22532251
} else {
22542252
let tempSsr: boolean | 'data-only'
22552253
if (route.options.ssr === undefined) {
22562254
tempSsr = defaultSsr
22572255
} else if (typeof route.options.ssr === 'function') {
2258-
const { search, params } = this.getMatch(matchId)!
2259-
22602256
function makeMaybe(value: any, error: any) {
22612257
if (error) {
22622258
return { status: 'error' as const, error }
@@ -2265,8 +2261,14 @@ export class RouterCore<
22652261
}
22662262

22672263
const ssrFnContext: SsrContextOptions<any, any, any> = {
2268-
search: makeMaybe(search, existingMatch.searchError),
2269-
params: makeMaybe(params, existingMatch.paramsError),
2264+
search: makeMaybe(
2265+
existingMatch.search,
2266+
existingMatch.searchError,
2267+
),
2268+
params: makeMaybe(
2269+
existingMatch.params,
2270+
existingMatch.paramsError,
2271+
),
22702272
location,
22712273
matches: matches.map((match) => ({
22722274
index: match.index,
@@ -2277,7 +2279,7 @@ export class RouterCore<
22772279
routeId: match.routeId,
22782280
search: makeMaybe(match.search, match.searchError),
22792281
params: makeMaybe(match.params, match.paramsError),
2280-
ssr: match.ssr,
2282+
ssr: match._nonReactive.ssr,
22812283
})),
22822284
}
22832285
tempSsr =
@@ -2286,17 +2288,17 @@ export class RouterCore<
22862288
tempSsr = route.options.ssr
22872289
}
22882290

2289-
if (tempSsr === true && parentMatch?.ssr === 'data-only') {
2291+
if (
2292+
tempSsr === true &&
2293+
parentMatch?._nonReactive.ssr === 'data-only'
2294+
) {
22902295
ssr = 'data-only'
22912296
} else {
22922297
ssr = tempSsr
22932298
}
22942299
}
22952300
}
2296-
updateMatch(matchId, (prev) => ({
2297-
...prev,
2298-
ssr,
2299-
}))
2301+
existingMatch._nonReactive.ssr = ssr
23002302
}
23012303

23022304
if (shouldSkipLoader(matchId)) {
@@ -2609,7 +2611,7 @@ export class RouterCore<
26092611
if (
26102612
!this.isServer ||
26112613
(this.isServer &&
2612-
this.getMatch(matchId)!.ssr === true)
2614+
this.getMatch(matchId)!._nonReactive.ssr === true)
26132615
) {
26142616
this.loadRouteChunk(route)
26152617
}

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function hydrateMatch(
2727
match.__beforeLoadContext = deyhydratedMatch.b
2828
match.loaderData = deyhydratedMatch.l
2929
match.status = deyhydratedMatch.s
30-
match.ssr = deyhydratedMatch.ssr
30+
match._nonReactive.ssr = deyhydratedMatch.ssr
3131
match.updatedAt = deyhydratedMatch.u
3232
match.error = deyhydratedMatch.e
3333
}
@@ -38,7 +38,7 @@ export interface DehydratedMatch {
3838
e?: MakeRouteMatch['error']
3939
u: MakeRouteMatch['updatedAt']
4040
s: MakeRouteMatch['status']
41-
ssr?: MakeRouteMatch['ssr']
41+
ssr?: MakeRouteMatch['_nonReactive']['ssr']
4242
}
4343

4444
export interface DehydratedRouter {
@@ -105,15 +105,18 @@ export async function hydrate(router: AnyRouter): Promise<any> {
105105
)
106106
if (!dehydratedMatch) {
107107
match._nonReactive.dehydrated = false
108-
match.ssr = false
108+
match._nonReactive.ssr = false
109109
return
110110
}
111111

112112
hydrateMatch(match, dehydratedMatch)
113113

114-
match._nonReactive.dehydrated = match.ssr !== false
114+
match._nonReactive.dehydrated = match._nonReactive.ssr !== false
115115

116-
if (match.ssr === 'data-only' || match.ssr === false) {
116+
if (
117+
match._nonReactive.ssr === 'data-only' ||
118+
match._nonReactive.ssr === false
119+
) {
117120
if (firstNonSsrMatchIndex === undefined) {
118121
firstNonSsrMatchIndex = match.index
119122
setMatchForcePending(match)
@@ -183,7 +186,7 @@ export async function hydrate(router: AnyRouter): Promise<any> {
183186
)
184187

185188
const isSpaMode = matches[matches.length - 1]!.id !== lastMatchId
186-
const hasSsrFalseMatches = matches.some((m) => m.ssr === false)
189+
const hasSsrFalseMatches = matches.some((m) => m._nonReactive.ssr === false)
187190
// all matches have data from the server and we are not in SPA mode so we don't need to kick of router.load()
188191
if (!hasSsrFalseMatches && !isSpaMode) {
189192
matches.forEach((match) => {

‎packages/router-core/src/ssr/ssr-server.ts‎

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,13 @@ export function dehydrateMatch(match: AnyRouteMatch): DehydratedMatch {
3232
s: match.status,
3333
}
3434

35-
const properties = [
36-
['__beforeLoadContext', 'b'],
37-
['loaderData', 'l'],
38-
['error', 'e'],
39-
['ssr', 'ssr'],
40-
] as const
35+
if (match.__beforeLoadContext !== undefined)
36+
dehydratedMatch.b = match.__beforeLoadContext
37+
if (match.loaderData !== undefined) dehydratedMatch.l = match.loaderData
38+
if (match.error !== undefined) dehydratedMatch.e = match.error
39+
if (match._nonReactive.ssr !== undefined)
40+
dehydratedMatch.ssr = match._nonReactive.ssr
4141

42-
for (const [key, shorthand] of properties) {
43-
if (match[key] !== undefined) {
44-
dehydratedMatch[shorthand] = match[key]
45-
}
46-
}
4742
return dehydratedMatch
4843
}
4944

‎packages/solid-router/src/Match.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const Match = (props: { matchId: string }) => {
3131
)
3232
return {
3333
routeId: match.routeId,
34-
ssr: match.ssr,
34+
ssr: match._nonReactive.ssr,
3535
_displayPending: match._displayPending,
3636
}
3737
},

0 commit comments

Comments
 (0)