@@ -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'.
0 commit comments