From 938b41e98fdf670807812cb8dd67285ad98aed88 Mon Sep 17 00:00:00 2001 From: leesb971204 Date: Thu, 3 Jul 2025 14:12:31 +0900 Subject: [PATCH 1/3] fix(router-core): handle AbortError in router execution flow Signed-off-by: leesb971204 --- packages/router-core/src/router.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/router-core/src/router.ts b/packages/router-core/src/router.ts index 41d15a0933..559417187b 100644 --- a/packages/router-core/src/router.ts +++ b/packages/router-core/src/router.ts @@ -2511,6 +2511,22 @@ export class RouterCore< ...head, })) } catch (e) { + if ( + e instanceof DOMException && + e.name === 'AbortError' + ) { + const head = await executeHead() + updateMatch(matchId, (prev) => ({ + ...prev, + status: + prev.status === 'pending' + ? 'success' + : prev.status, + ...head, + })) + return + } + let error = e await potentialPendingMinPromise() From e2a807429375b098049eef234465900645987a2f Mon Sep 17 00:00:00 2001 From: leesb971204 Date: Fri, 4 Jul 2025 16:38:02 +0900 Subject: [PATCH 2/3] test(react-router): add test for AbortError handling in loader with basepath Signed-off-by: leesb971204 --- packages/react-router/tests/loaders.test.tsx | 28 +++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/react-router/tests/loaders.test.tsx b/packages/react-router/tests/loaders.test.tsx index 8d92506468..0eee1d54ae 100644 --- a/packages/react-router/tests/loaders.test.tsx +++ b/packages/react-router/tests/loaders.test.tsx @@ -429,7 +429,7 @@ test('reproducer #4546', async () => { component: () => { return ( <> -
+
{ expect(loaderData).toHaveTextContent('5') } }) + +test('throw abortError from loader upon initial load with basepath', async () => { + const rootRoute = createRootRoute({}) + + const indexRoute = createRoute({ + getParentRoute: () => rootRoute, + path: '/', + loader: async () => { + return Promise.reject(new DOMException('Aborted', 'AbortError')) + }, + component: () =>
Index route content
, + errorComponent: () => ( +
indexErrorComponent
+ ), + }) + + const routeTree = rootRoute.addChildren([indexRoute]) + const router = createRouter({ routeTree, history, basepath: '/app' }) + + render() + + const indexElement = await screen.findByText('Index route content') + expect(indexElement).toBeInTheDocument() + expect(screen.queryByTestId('index-error')).not.toBeInTheDocument() + expect(window.location.pathname.startsWith('/app')).toBe(true) +}) From 8c8f463fe0ac99e92b9e10975529dd250d4e385f Mon Sep 17 00:00:00 2001 From: leesb971204 Date: Mon, 14 Jul 2025 10:06:25 +0900 Subject: [PATCH 3/3] test(solid-router): add test for AbortError handling in loader with basepath Signed-off-by: leesb971204 --- packages/solid-router/tests/loaders.test.tsx | 26 ++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/packages/solid-router/tests/loaders.test.tsx b/packages/solid-router/tests/loaders.test.tsx index 103bde1646..c301977181 100644 --- a/packages/solid-router/tests/loaders.test.tsx +++ b/packages/solid-router/tests/loaders.test.tsx @@ -317,3 +317,29 @@ test('throw error from beforeLoad when navigating to route', async () => { const indexElement = await screen.findByText('fooErrorComponent') expect(indexElement).toBeInTheDocument() }) + +test('throw abortError from loader upon initial load with basepath', async () => { + const rootRoute = createRootRoute({}) + + const indexRoute = createRoute({ + getParentRoute: () => rootRoute, + path: '/', + loader: async () => { + return Promise.reject(new DOMException('Aborted', 'AbortError')) + }, + component: () =>
Index route content
, + errorComponent: () => ( +
indexErrorComponent
+ ), + }) + + const routeTree = rootRoute.addChildren([indexRoute]) + const router = createRouter({ routeTree, basepath: '/app' }) + + render(() => ) + + const indexElement = await screen.findByText('Index route content') + expect(indexElement).toBeInTheDocument() + expect(screen.queryByTestId('index-error')).not.toBeInTheDocument() + expect(window.location.pathname.startsWith('/app')).toBe(true) +})