Skip to content

Commit 05b5122

Browse files
committed
forgot a file in the commit
1 parent a6dde01 commit 05b5122

File tree

1 file changed

+33
-24
lines changed

1 file changed

+33
-24
lines changed

packages/router-core/src/router.ts

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2697,10 +2697,12 @@ export class RouterCore<
26972697
this.getMatch(matchId),
26982698
loaderData,
26992699
)
2700-
innerLoadContext.updateMatch(matchId, (prev) => ({
2701-
...prev,
2702-
loaderData,
2703-
}))
2700+
if (loaderData !== undefined) {
2701+
innerLoadContext.updateMatch(matchId, (prev) => ({
2702+
...prev,
2703+
loaderData,
2704+
}))
2705+
}
27042706
}
27052707

27062708
// Lazy option can modify the route options,
@@ -2837,14 +2839,18 @@ export class RouterCore<
28372839
)
28382840
: shouldReloadOption
28392841

2840-
innerLoadContext.updateMatch(matchId, (prev) => {
2841-
prev._nonReactive.loaderPromise = createControlledPromise<void>()
2842-
return {
2843-
...prev,
2844-
preload:
2845-
!!preload && !this.state.matches.some((d) => d.id === matchId),
2846-
}
2847-
})
2842+
const nextPreload =
2843+
!!preload && !this.state.matches.some((d) => d.id === matchId)
2844+
const match = this.getMatch(matchId)!
2845+
match._nonReactive.loaderPromise = createControlledPromise<void>()
2846+
if (nextPreload !== match.preload) {
2847+
innerLoadContext.updateMatch(matchId, (prev) => {
2848+
return {
2849+
...prev,
2850+
preload: nextPreload,
2851+
}
2852+
})
2853+
}
28482854

28492855
// If the route is successful and still fresh, just resolve
28502856
const { status, invalid } = this.getMatch(matchId)!
@@ -2886,23 +2892,26 @@ export class RouterCore<
28862892
}
28872893
}
28882894
}
2895+
const match = this.getMatch(matchId)!
28892896
if (!loaderIsRunningAsync) {
2890-
const match = this.getMatch(matchId)!
28912897
match._nonReactive.loaderPromise?.resolve()
28922898
match._nonReactive.loadPromise?.resolve()
28932899
}
28942900

2895-
innerLoadContext.updateMatch(matchId, (prev) => {
2896-
clearTimeout(prev._nonReactive.pendingTimeout)
2897-
prev._nonReactive.pendingTimeout = undefined
2898-
if (!loaderIsRunningAsync) prev._nonReactive.loaderPromise = undefined
2899-
prev._nonReactive.dehydrated = undefined
2900-
return {
2901-
...prev,
2902-
isFetching: loaderIsRunningAsync ? prev.isFetching : false,
2903-
invalid: false,
2904-
}
2905-
})
2901+
clearTimeout(match._nonReactive.pendingTimeout)
2902+
match._nonReactive.pendingTimeout = undefined
2903+
if (!loaderIsRunningAsync) match._nonReactive.loaderPromise = undefined
2904+
match._nonReactive.dehydrated = undefined
2905+
const nextIsFetching = loaderIsRunningAsync ? match.isFetching : false
2906+
if (nextIsFetching !== match.isFetching || match.invalid !== false) {
2907+
innerLoadContext.updateMatch(matchId, (prev) => {
2908+
return {
2909+
...prev,
2910+
isFetching: nextIsFetching,
2911+
invalid: false,
2912+
}
2913+
})
2914+
}
29062915
return this.getMatch(matchId)!
29072916
}
29082917

0 commit comments

Comments
 (0)