Skip to content

Commit 4b1a9dd

Browse files
yanghuidongclaude
andcommitted
revert: move promise resolution back to try block
Moving the promise resolution from finally block back to try block. This ensures promises are only resolved on successful loader completion, not on errors or redirects. Resolving on redirect was incorrect because we're navigating away from the route, so head() re-execution for the old route doesn't make sense. The null check is kept as a safety measure since this code still runs in an async callback where navigation could theoretically change. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
1 parent 2687842 commit 4b1a9dd

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -839,21 +839,17 @@ const loadRouteMatch = async (
839839
try {
840840
await runLoader(inner, matchId, index, route)
841841
commitContext()
842-
} catch (err) {
843-
if (isRedirect(err)) {
844-
await inner.router.navigate(err.options)
845-
}
846-
// Errors are already stored in match by runLoader
847-
// Continue to resolve promises so head() can execute
848-
} finally {
849-
// Always resolve promises (success or error) to allow head() execution
850842
// Match might be undefined if navigation changed while async loader was running
851843
const match = inner.router.getMatch(matchId)
852844
if (match) {
853845
match._nonReactive.loaderPromise?.resolve()
854846
match._nonReactive.loadPromise?.resolve()
855847
match._nonReactive.loaderPromise = undefined
856848
}
849+
} catch (err) {
850+
if (isRedirect(err)) {
851+
await inner.router.navigate(err.options)
852+
}
857853
}
858854
})()
859855
} else if (status !== 'success' || (loaderShouldRunAsync && inner.sync)) {

0 commit comments

Comments
 (0)