Skip to content

Commit c55f431

Browse files
fix
1 parent 3cb972f commit c55f431

5 files changed

Lines changed: 19 additions & 11 deletions

File tree

‎packages/react-router/tests/redirect.test.tsx‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
1111

1212
import {
1313
Link,
14-
Outlet,
1514
RouterProvider,
1615
createBrowserHistory,
1716
createMemoryHistory,

‎packages/router-core/src/load-matches.ts‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,13 +283,19 @@ const handleSerialError = (
283283
inner.firstBadMatchIndex ??= index
284284
match.__beforeLoadContext = undefined
285285

286-
handleRedirectOrNotFound(inner, inner.router.getMatch(matchId), err)
286+
const currentMatch = inner.router.getMatch(matchId)
287+
if (currentMatch) {
288+
currentMatch.__beforeLoadContext = undefined
289+
}
290+
291+
handleRedirectOrNotFound(inner, currentMatch, err)
287292

288293
try {
289294
route.options.onError?.(err)
290295
} catch (errorHandlerErr) {
291296
err = errorHandlerErr
292-
handleRedirectOrNotFound(inner, inner.router.getMatch(matchId), err)
297+
// The current match's pending beforeLoad context was already cleared above.
298+
handleRedirectOrNotFound(inner, currentMatch, err)
293299
}
294300

295301
// A match that errors during the beforeLoad phase never reaches the loader
@@ -304,9 +310,9 @@ const handleSerialError = (
304310
abortController: new AbortController(),
305311
})
306312

307-
const currentMatch = inner.router.getMatch(matchId)
308-
if (currentMatch) {
309-
clearMatchPromises(currentMatch)
313+
const updatedMatch = inner.router.getMatch(matchId)
314+
if (updatedMatch) {
315+
clearMatchPromises(updatedMatch)
310316
}
311317

312318
if (!inner.preload) {
@@ -1161,10 +1167,11 @@ export async function loadMatches(arg: {
11611167

11621168
notFoundToThrow.routeId = boundaryMatch.routeId
11631169

1164-
patchMatch(
1170+
commitMatch(
11651171
inner,
11661172
boundaryMatch.id,
1167-
boundaryMatch.routeId === inner.router.routeTree.id
1173+
renderedBoundaryIndex,
1174+
boundaryMatch.routeId === rootRouteId
11681175
? // For root boundary, use globalNotFound so the root component's
11691176
// shell still renders and <Outlet> handles the not-found display,
11701177
// instead of replacing the entire root shell via status='notFound'.

‎packages/router-core/src/router.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2879,7 +2879,11 @@ export class RouterCore<
28792879
continue
28802880
}
28812881

2882-
await this.getMatch(id)?._nonReactive.beforeLoadPromise
2882+
const beforeLoadPromise =
2883+
this.getMatch(id)?._nonReactive.beforeLoadPromise
2884+
if (beforeLoadPromise) {
2885+
await beforeLoadPromise
2886+
}
28832887

28842888
const settledMatch = this.getMatch(id)
28852889
if (

‎packages/solid-router/tests/redirect.test.tsx‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
44

55
import {
66
Link,
7-
Outlet,
87
RouterProvider,
98
createBrowserHistory,
109
createMemoryHistory,

‎packages/vue-router/tests/redirect.test.tsx‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { afterEach, describe, expect, test, vi } from 'vitest'
44

55
import {
66
Link,
7-
Outlet,
87
RouterProvider,
98
createMemoryHistory,
109
createRootRoute,

0 commit comments

Comments
 (0)