Skip to content

Commit 2687842

Browse files
yanghuidongclaude
andcommitted
fix: add null check for match in async loader finally block
Fixes race condition where async loader's finally block executes after navigation has changed, causing match to be undefined when accessing _nonReactive properties. This resolves 11 unhandled rejection errors in unit tests: - TypeError: Cannot read properties of undefined (reading '_nonReactive') - All errors pointed to load-matches.ts:851 in async callback's finally block The fix adds a null check before accessing match._nonReactive to handle cases where the match has been removed from the router during async execution. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
1 parent 5914d25 commit 2687842

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -847,10 +847,13 @@ const loadRouteMatch = async (
847847
// Continue to resolve promises so head() can execute
848848
} finally {
849849
// Always resolve promises (success or error) to allow head() execution
850-
const match = inner.router.getMatch(matchId)!
851-
match._nonReactive.loaderPromise?.resolve()
852-
match._nonReactive.loadPromise?.resolve()
853-
match._nonReactive.loaderPromise = undefined
850+
// Match might be undefined if navigation changed while async loader was running
851+
const match = inner.router.getMatch(matchId)
852+
if (match) {
853+
match._nonReactive.loaderPromise?.resolve()
854+
match._nonReactive.loadPromise?.resolve()
855+
match._nonReactive.loaderPromise = undefined
856+
}
854857
}
855858
})()
856859
} else if (status !== 'success' || (loaderShouldRunAsync && inner.sync)) {

0 commit comments

Comments
 (0)