From 66772ea29592cce45689df2cd8fc697c85e9345b Mon Sep 17 00:00:00 2001 From: Sheraff Date: Mon, 18 Aug 2025 21:33:56 +0200 Subject: [PATCH 1/2] refactor(router-core): shouldExecuteBeforeLoad is always true --- packages/router-core/src/load-matches.ts | 37 +++++++++--------------- 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/packages/router-core/src/load-matches.ts b/packages/router-core/src/load-matches.ts index 3abfbe1f5d..269681aa2b 100644 --- a/packages/router-core/src/load-matches.ts +++ b/packages/router-core/src/load-matches.ts @@ -147,11 +147,10 @@ const shouldSkipLoader = ( return true } - if (inner.router.isServer) { - if (match.ssr === false) { - return true - } + if (inner.router.isServer && match.ssr === false) { + return true } + return false } @@ -302,11 +301,11 @@ const setupPendingTimeout = ( } } -const shouldExecuteBeforeLoad = ( +const preBeforeLoadSetup = ( inner: InnerLoadContext, matchId: string, route: AnyRoute, -): boolean | Promise => { +): void | Promise => { const existingMatch = inner.router.getMatch(matchId)! // If we are in the middle of a load, either of these will be present @@ -315,25 +314,21 @@ const shouldExecuteBeforeLoad = ( !existingMatch._nonReactive.beforeLoadPromise && !existingMatch._nonReactive.loaderPromise ) - return true + return setupPendingTimeout(inner, matchId, route, existingMatch) const then = () => { - let result = true const match = inner.router.getMatch(matchId)! - if (match.status === 'error') { - result = true - } else if ( + if ( match.preload && (match.status === 'redirected' || match.status === 'notFound') ) { handleRedirectAndNotFound(inner, match, match.error) } - return result } - // Wait for the beforeLoad to resolve before we continue + // Wait for the previous beforeLoad to resolve before we continue return existingMatch._nonReactive.beforeLoadPromise ? existingMatch._nonReactive.beforeLoadPromise.then(then) : then() @@ -494,23 +489,17 @@ const handleBeforeLoad = ( const queueExecution = () => { if (shouldSkipLoader(inner, matchId)) return - const shouldExecuteBeforeLoadResult = shouldExecuteBeforeLoad( + const result = preBeforeLoadSetup( inner, matchId, route, ) - return isPromise(shouldExecuteBeforeLoadResult) - ? shouldExecuteBeforeLoadResult.then(execute) - : execute(shouldExecuteBeforeLoadResult) + return isPromise(result) + ? result.then(execute) + : execute() } - const execute = (shouldExec: boolean) => { - if (shouldExec) { - // If we are not in the middle of a load OR the previous load failed, start it - return executeBeforeLoad(inner, matchId, index, route) - } - return - } + const execute = () => executeBeforeLoad(inner, matchId, index, route) return serverSsr() } From 0dcac361fa0c7b6741766dd8d08d5689725c9f06 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Mon, 18 Aug 2025 19:36:14 +0000 Subject: [PATCH 2/2] ci: apply automated fixes --- packages/router-core/src/load-matches.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/router-core/src/load-matches.ts b/packages/router-core/src/load-matches.ts index 269681aa2b..c1edd5648f 100644 --- a/packages/router-core/src/load-matches.ts +++ b/packages/router-core/src/load-matches.ts @@ -489,14 +489,8 @@ const handleBeforeLoad = ( const queueExecution = () => { if (shouldSkipLoader(inner, matchId)) return - const result = preBeforeLoadSetup( - inner, - matchId, - route, - ) - return isPromise(result) - ? result.then(execute) - : execute() + const result = preBeforeLoadSetup(inner, matchId, route) + return isPromise(result) ? result.then(execute) : execute() } const execute = () => executeBeforeLoad(inner, matchId, index, route)