Skip to content

Commit

Permalink
fix(react-router): when ongoing beforeLoad failed, retry next time (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
schiller-manuel authored Dec 8, 2024
1 parent 29619bf commit 52e9d4f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 5 additions & 2 deletions packages/react-router/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2286,6 +2286,7 @@ export class Router<
this.options.defaultPendingComponent)
)

let executeBeforeLoad = true
if (
// If we are in the middle of a load, either of these will be present
// (not to be confused with `loadPromise`, which is always defined)
Expand All @@ -2304,8 +2305,10 @@ export class Router<

// Wait for the beforeLoad to resolve before we continue
await existingMatch.beforeLoadPromise
} else {
// If we are not in the middle of a load, start it
executeBeforeLoad = this.getMatch(matchId)!.status !== 'success'
}
if (executeBeforeLoad) {
// If we are not in the middle of a load OR the previous load failed, start it
try {
updateMatch(matchId, (prev) => ({
...prev,
Expand Down
3 changes: 2 additions & 1 deletion packages/react-router/tests/errorComponent.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,13 @@ describe.each([{ preload: false }, { preload: 'intent' }] as const)(

expect(linkToAbout).toBeInTheDocument()
fireEvent.mouseOver(linkToAbout)
fireEvent.focus(linkToAbout)
fireEvent.click(linkToAbout)

const errorComponent = await screen.findByText(
`Error: error thrown`,
undefined,
{ timeout: 750 },
{ timeout: 1500 },
)
expect(screen.findByText('About route content')).rejects.toThrow()
expect(errorComponent).toBeInTheDocument()
Expand Down

0 comments on commit 52e9d4f

Please sign in to comment.