Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion packages/react-router/tests/loaders.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ test('reproducer #4546', async () => {
component: () => {
return (
<>
<div className="p-2 flex gap-2 text-lg">
<div className="flex gap-2 p-2 text-lg">
<Link
data-testid="link-to-index"
to="/"
Expand Down Expand Up @@ -730,6 +730,33 @@ test('clears pendingTimeout when match resolves', async () => {
expect(fooPendingComponentOnMountMock).not.toHaveBeenCalled()
})

test('throw abortError from loader upon initial load with basepath', async () => {
window.history.replaceState(null, 'root', '/app')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretend vite.config.ts's base: 'app'

const rootRoute = createRootRoute({})

const indexRoute = createRoute({
getParentRoute: () => rootRoute,
path: '/',
loader: async () => {
return Promise.reject(new DOMException('Aborted', 'AbortError'))
},
component: () => <div>Index route content</div>,
errorComponent: () => (
<div data-testid="index-error">indexErrorComponent</div>
),
})

const routeTree = rootRoute.addChildren([indexRoute])
const router = createRouter({ routeTree, history, basepath: '/app' })

render(<RouterProvider router={router} />)

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)
})

test('cancelMatches after pending timeout', async () => {
function getPendingComponent(onMount: () => void) {
const PendingComponent = () => {
Expand Down
9 changes: 9 additions & 0 deletions packages/router-core/src/load-matches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,15 @@ const runLoader = async (
} catch (e) {
let error = e

if ((error as any)?.name === 'AbortError') {
inner.updateMatch(matchId, (prev) => ({
...prev,
status: prev.status === 'pending' ? 'success' : prev.status,
isFetching: false,
}))
return
}

const pendingPromise = match._nonReactive.minPendingPromise
if (pendingPromise) await pendingPromise

Expand Down
27 changes: 27 additions & 0 deletions packages/solid-router/tests/loaders.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,33 @@ test('throw error from beforeLoad when navigating to route', async () => {
expect(indexElement).toBeInTheDocument()
})

test('throw abortError from loader upon initial load with basepath', async () => {
window.history.replaceState(null, 'root', '/app')
const rootRoute = createRootRoute({})

const indexRoute = createRoute({
getParentRoute: () => rootRoute,
path: '/',
loader: async () => {
return Promise.reject(new DOMException('Aborted', 'AbortError'))
},
component: () => <div>Index route content</div>,
errorComponent: () => (
<div data-testid="index-error">indexErrorComponent</div>
),
})

const routeTree = rootRoute.addChildren([indexRoute])
const router = createRouter({ routeTree, basepath: '/app' })

render(() => <RouterProvider router={router} />)

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)
})

test('reproducer #4245', async () => {
const LOADER_WAIT_TIME = 500
const rootRoute = createRootRoute({})
Expand Down
Loading