Skip to content

Commit 0f0762e

Browse files
committed
use match.__beforeLoadContext
1 parent c8c83d8 commit 0f0762e

File tree

5 files changed

+10
-14
lines changed

5 files changed

+10
-14
lines changed

packages/router-core/src/Matches.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,6 @@ export interface RouteMatch<
148148
displayPendingPromise?: Promise<void>
149149
minPendingPromise?: ControlledPromise<void>
150150
dehydrated?: boolean
151-
/** @internal - Stored non-reactively so it can be read immediately even during transitions */
152-
__beforeLoadContext?: Record<string, unknown>
153151
/** @internal - Stored non-reactively so redirect/notFound errors are immediately accessible even during transitions */
154152
error?: unknown
155153
}

packages/router-core/src/load-matches.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ const executeBeforeLoad = (
454454
// Store __beforeLoadContext non-reactively so it's immediately readable even during transitions
455455
const match = inner.router.getMatch(matchId)
456456
if (match) {
457-
match._nonReactive.__beforeLoadContext = beforeLoadContext
457+
match.__beforeLoadContext = beforeLoadContext
458458
}
459459
inner.updateMatch(matchId, (prev) => ({
460460
...prev,
@@ -582,7 +582,7 @@ const getLoaderContext = (
582582
context = {
583583
...context,
584584
...(m.__routeContext ?? {}),
585-
...(m._nonReactive.__beforeLoadContext ?? {}),
585+
...(m.__beforeLoadContext ?? {}),
586586
}
587587
}
588588

packages/router-core/src/router.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,7 +1454,6 @@ export class RouterCore<
14541454
__routeContext: undefined,
14551455
_nonReactive: {
14561456
loadPromise: createControlledPromise(),
1457-
__beforeLoadContext: undefined,
14581457
error: (existingMatch as any)?._nonReactive?.error,
14591458
},
14601459
__beforeLoadContext: undefined,
@@ -1489,7 +1488,7 @@ export class RouterCore<
14891488
match.context = {
14901489
...parentContext,
14911490
...match.__routeContext,
1492-
...match._nonReactive.__beforeLoadContext,
1491+
...match.__beforeLoadContext,
14931492
}
14941493

14951494
matches.push(match)
@@ -1529,7 +1528,7 @@ export class RouterCore<
15291528
match.context = {
15301529
...parentContext,
15311530
...match.__routeContext,
1532-
...match._nonReactive.__beforeLoadContext,
1531+
...match.__beforeLoadContext,
15331532
}
15341533
}
15351534
})
@@ -2298,7 +2297,7 @@ export class RouterCore<
22982297

22992298
updateMatch: UpdateMatchFn = (id, updater) => {
23002299
// Wrap in startTransition to prevent Suspense fallbacks
2301-
// Context is stored in _nonReactive.__beforeLoadContext so it's immediately readable
2300+
// Context is stored in .__beforeLoadContext so it's immediately readable
23022301
this.startTransition(() => {
23032302
const matchesKey = this.state.pendingMatches?.some((d) => d.id === id)
23042303
? 'pendingMatches'

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ function hydrateMatch(
3232
deyhydratedMatch: DehydratedMatch,
3333
): void {
3434
match.id = deyhydratedMatch.i
35-
match._nonReactive.__beforeLoadContext = deyhydratedMatch.b
3635
match.__beforeLoadContext = deyhydratedMatch.b
3736
match.loaderData = deyhydratedMatch.l
3837
match.status = deyhydratedMatch.s
@@ -174,14 +173,14 @@ export async function hydrate(router: AnyRouter): Promise<any> {
174173
const route = router.looseRoutesById[match.routeId]!
175174

176175
// Build parent context by accumulating from all ancestors
177-
// We read from _nonReactive.__beforeLoadContext to avoid issues during transitions
176+
// We read from __beforeLoadContext to avoid issues during transitions
178177
let parentContext = router.options.context ?? {}
179178
for (let i = 0; i < match.index; i++) {
180179
const ancestorMatch = router.state.matches[i]!
181180
parentContext = {
182181
...parentContext,
183182
...ancestorMatch.__routeContext,
184-
...ancestorMatch._nonReactive.__beforeLoadContext,
183+
...ancestorMatch.__beforeLoadContext,
185184
}
186185
}
187186

@@ -208,7 +207,7 @@ export async function hydrate(router: AnyRouter): Promise<any> {
208207
match.context = {
209208
...parentContext,
210209
...match.__routeContext,
211-
...match._nonReactive.__beforeLoadContext,
210+
...match.__beforeLoadContext,
212211
}
213212

214213
const assetContext = {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ export function dehydrateMatch(match: AnyRouteMatch): DehydratedMatch {
3333
s: match.status,
3434
}
3535

36-
if (match._nonReactive.__beforeLoadContext !== undefined) {
37-
dehydratedMatch.b = match._nonReactive.__beforeLoadContext
36+
if (match.__beforeLoadContext !== undefined) {
37+
dehydratedMatch.b = match.__beforeLoadContext
3838
}
3939

4040
const properties = [

0 commit comments

Comments
 (0)