@@ -112,6 +112,13 @@ export type ControllablePromise<T = any> = Promise<T> & {
112112
113113export type InjectedHtmlEntry = Promise < string >
114114
115+ const clearPendingRenderPromise = ( match : AnyRouteMatch | undefined ) => {
116+ if ( match ) {
117+ match . _nonReactive . pendingRenderPromise ?. resolve ( )
118+ match . _nonReactive . pendingRenderPromise = undefined
119+ }
120+ }
121+
115122export interface Register {
116123 // Lots of things on here like...
117124 // router
@@ -2475,6 +2482,19 @@ export class RouterCore<
24752482 * or reloads re-run their loaders instead of reusing the failed/not-found data.
24762483 */
24772484 if ( mountPending ) {
2485+ const pendingMatchesById = new Map (
2486+ pendingMatches . map ( ( match ) => [ match . id , match ] ) ,
2487+ )
2488+
2489+ currentMatches . forEach ( ( currentMatch ) => {
2490+ if (
2491+ pendingMatchesById . get ( currentMatch . id ) ?. status !==
2492+ 'pending'
2493+ ) {
2494+ clearPendingRenderPromise ( currentMatch )
2495+ }
2496+ } )
2497+
24782498 this . stores . setActiveMatches ( pendingMatches )
24792499 this . stores . setPendingMatches ( [ ] )
24802500 this . stores . setCachedMatches ( [
@@ -2634,7 +2654,11 @@ export class RouterCore<
26342654
26352655 const activeMatch = this . stores . activeMatchStoresById . get ( id )
26362656 if ( activeMatch ) {
2637- activeMatch . setState ( updater )
2657+ const next = updater ( activeMatch . state )
2658+ if ( next . status !== 'pending' ) {
2659+ clearPendingRenderPromise ( activeMatch . state )
2660+ }
2661+ activeMatch . setState ( ( ) => next )
26382662 return
26392663 }
26402664
@@ -2696,9 +2720,16 @@ export class RouterCore<
26962720 }
26972721
26982722 this . batch ( ( ) => {
2699- this . stores . setActiveMatches (
2700- this . stores . activeMatchesSnapshot . state . map ( invalidate ) ,
2701- )
2723+ const activeMatches = this . stores . activeMatchesSnapshot . state
2724+ const nextActiveMatches = activeMatches . map ( invalidate )
2725+
2726+ activeMatches . forEach ( ( activeMatch , index ) => {
2727+ if ( nextActiveMatches [ index ] ?. status !== 'pending' ) {
2728+ clearPendingRenderPromise ( activeMatch )
2729+ }
2730+ } )
2731+
2732+ this . stores . setActiveMatches ( nextActiveMatches )
27022733 this . stores . setCachedMatches (
27032734 this . stores . cachedMatchesSnapshot . state . map ( invalidate ) ,
27042735 )
0 commit comments