@@ -2371,24 +2371,27 @@ export class RouterCore<
2371
2371
) : void | Promise < void > => {
2372
2372
const match = this . getMatch ( matchId ) !
2373
2373
const abortController = new AbortController ( )
2374
+ const parentMatchId = innerLoadContext . matches [ index - 1 ] ?. id
2375
+ const parentMatch = parentMatchId
2376
+ ? this . getMatch ( parentMatchId ) !
2377
+ : undefined
2378
+ const parentMatchContext =
2379
+ parentMatch ?. context ?? this . options . context ?? undefined
2380
+ const context = {
2381
+ ...parentMatchContext ,
2382
+ ...match . __routeContext ,
2383
+ }
2374
2384
2375
- const pending = ( ) => {
2376
- const parentMatchId = innerLoadContext . matches [ index - 1 ] ?. id
2377
- const parentMatch = parentMatchId
2378
- ? this . getMatch ( parentMatchId ) !
2379
- : undefined
2380
- const parentMatchContext =
2381
- parentMatch ?. context ?? this . options . context ?? undefined
2385
+ let isPending = false
2382
2386
2387
+ const pending = ( ) => {
2388
+ isPending = true
2383
2389
innerLoadContext . updateMatch ( matchId , ( prev ) => ( {
2384
2390
...prev ,
2385
2391
isFetching : 'beforeLoad' ,
2386
2392
fetchCount : prev . fetchCount + 1 ,
2387
2393
abortController,
2388
- context : {
2389
- ...parentMatchContext ,
2390
- ...prev . __routeContext ,
2391
- } ,
2394
+ context,
2392
2395
} ) )
2393
2396
}
2394
2397
@@ -2439,11 +2442,12 @@ export class RouterCore<
2439
2442
return
2440
2443
}
2441
2444
2442
- pending ( )
2443
-
2444
2445
const updateContext = ( beforeLoadContext : any ) => {
2445
2446
if ( beforeLoadContext === undefined ) {
2446
- resolve ( )
2447
+ batch ( ( ) => {
2448
+ if ( ! isPending ) pending ( )
2449
+ resolve ( )
2450
+ } )
2447
2451
return
2448
2452
}
2449
2453
if ( isRedirect ( beforeLoadContext ) || isNotFound ( beforeLoadContext ) ) {
@@ -2455,6 +2459,7 @@ export class RouterCore<
2455
2459
)
2456
2460
}
2457
2461
batch ( ( ) => {
2462
+ if ( ! isPending ) pending ( )
2458
2463
innerLoadContext . updateMatch ( matchId , ( prev ) => ( {
2459
2464
...prev ,
2460
2465
__beforeLoadContext : beforeLoadContext ,
@@ -2466,7 +2471,7 @@ export class RouterCore<
2466
2471
resolve ( )
2467
2472
} )
2468
2473
}
2469
- const { search, params, context , cause } = this . getMatch ( matchId ) !
2474
+ const { search, params, cause } = match
2470
2475
const preload = this . resolvePreload ( innerLoadContext , matchId )
2471
2476
const beforeLoadFnContext : BeforeLoadContextOptions <
2472
2477
any ,
@@ -2493,6 +2498,7 @@ export class RouterCore<
2493
2498
try {
2494
2499
const beforeLoadContext = route . options . beforeLoad ( beforeLoadFnContext )
2495
2500
if ( isPromise ( beforeLoadContext ) ) {
2501
+ pending ( )
2496
2502
return beforeLoadContext . then ( updateContext ) . catch ( ( err ) => {
2497
2503
this . handleSerialError ( innerLoadContext , index , err , 'BEFORE_LOAD' )
2498
2504
} )
0 commit comments