diff --git a/packages/react-router/src/router.ts b/packages/react-router/src/router.ts index b06691bd4b..fbc1d3283e 100644 --- a/packages/react-router/src/router.ts +++ b/packages/react-router/src/router.ts @@ -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) @@ -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, diff --git a/packages/react-router/tests/errorComponent.test.tsx b/packages/react-router/tests/errorComponent.test.tsx index ccb9be1d4d..fd6a5fa8ca 100644 --- a/packages/react-router/tests/errorComponent.test.tsx +++ b/packages/react-router/tests/errorComponent.test.tsx @@ -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()