Skip to content

Commit

Permalink
fix(react-router): if loader is running async for revalidation, do no…
Browse files Browse the repository at this point in the history
…t overwrite `isFetching` (#2239)
  • Loading branch information
schiller-manuel authored Sep 1, 2024
1 parent a57398e commit 2c93e4b
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions packages/react-router/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2133,7 +2133,7 @@ export class Router<
(async () => {
const { loaderPromise: prevLoaderPromise } =
this.getMatch(matchId)!

let loaderRunningAsync = false
if (prevLoaderPromise) {
await prevLoaderPromise
} else {
Expand Down Expand Up @@ -2328,13 +2328,12 @@ export class Router<

// If the route is successful and still fresh, just resolve
const { status, invalid } = this.getMatch(matchId)!

if (preload && route.options.preload === false) {
// Do nothing
} else if (
loaderRunningAsync =
status === 'success' &&
(invalid || (shouldReload ?? age > staleAge))
) {
if (preload && route.options.preload === false) {
// Do nothing
} else if (loaderRunningAsync) {
;(async () => {
try {
await runLoader()
Expand All @@ -2353,7 +2352,7 @@ export class Router<

updateMatch(matchId, (prev) => ({
...prev,
isFetching: false,
isFetching: loaderRunningAsync ? prev.isFetching : false,
loaderPromise: undefined,
}))
})(),
Expand Down

0 comments on commit 2c93e4b

Please sign in to comment.