Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 31 additions & 28 deletions packages/router-core/src/load-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -677,18 +677,19 @@ function settleInto(
result: LoaderOutcome,
preload: boolean,
): asserts match is SettledMatch {
if (result[0 /* kind */] === REDIRECTED) {
return
}
// Reduction installs only the selected terminal failure. Every other
// settled attempt remains a renderable, stale match in that lane.
match.status = 'success'
match.error = undefined
if (result[0 /* kind */] === SUCCESS) {
match.loaderData = result[1 /* data */]
match.error = undefined
match.status = 'success'
match.invalid = false
match.updatedAt = Date.now()
match.preload = preload
} else if (result[0 /* kind */] !== REDIRECTED) {
// Reduction installs only the selected terminal failure. Every other
// settled attempt remains a renderable, stale match in that lane.
match.status = 'success'
match.error = undefined
} else {
match.invalid = true
}
}
Expand Down Expand Up @@ -780,7 +781,7 @@ function createLoaderTask(
reload = true
} else {
const staleAge =
options[4 /* preload */] || match.preload
preload || match.preload
? (route.options.preloadStaleTime ??
router.options.defaultPreloadStaleTime ??
30_000)
Expand All @@ -806,10 +807,11 @@ function createLoaderTask(
reloadFailure = normalizeLaneError(route, cause, options)
}
const routeLoader = route.options.loader
const loader =
typeof routeLoader === 'function' ? routeLoader : routeLoader?.handler
const isLoaderFn = typeof routeLoader === 'function'
const loader = isLoaderFn ? routeLoader : routeLoader?.handler
const preloadable = !preload || route.options.preload !== false
let donor =
(!preload || route.options.preload !== false) &&
preloadable &&
routeLoader &&
!(process.env.NODE_ENV !== 'production' && router._tx?.[6 /* refresh */])
? router._flights?.get(match.id)
Expand All @@ -829,12 +831,10 @@ function createLoaderTask(
match.status === 'success' &&
!preload &&
!options[5 /* sync */] &&
((typeof routeLoader === 'function'
? undefined
: routeLoader?.staleReloadMode) ??
((isLoaderFn ? undefined : routeLoader.staleReloadMode) ??
router.options.defaultStaleReloadMode) !== 'blocking'
)
const loaded = reload && (!preload || route.options.preload !== false)
const loaded = reload && preloadable
const blocking =
loaded && !background && (match.status !== 'success' || !!routeLoader)
const onLazyReady =
Expand Down Expand Up @@ -1248,10 +1248,9 @@ async function executeClientLane(
options[0 /* controller */].signal,
plannedBoundary,
)
if (boundary !== plannedBoundary) {
matches[plannedBoundary]!._notFound = undefined
matches[boundary]!._notFound = true
}
// When the boundary did not move this clears and re-sets the same match.
matches[plannedBoundary]!._notFound = undefined
matches[boundary]!._notFound = true
plannedBoundary = boundary
}
let end = plannedBoundary < 0 ? matches.length : plannedBoundary + 1
Expand Down Expand Up @@ -1419,8 +1418,10 @@ function offerPending(router: CoordinatorRouter, tx: LoadTransaction): void {
continue
}
const route = getRoute(router, match as WorkMatch)
// The continue above already filtered non-presented successes, so a
// success here is a presented pending fallback and reveals immediately.
delay =
(success && presentedPending) || match.invalid
success || match.invalid
? 0
: (route.options.pendingMs ?? router.options.defaultPendingMs)
component =
Expand Down Expand Up @@ -1515,6 +1516,12 @@ function publishMatches(
router.stores.setMatches(matches)
}

/** Release a `commit()` awaiter once its transaction reaches a settled UI. */
function resolveCommit(router: CoordinatorRouter): void {
router._commitPromise?.resolve()
router._commitPromise = undefined
}

function discardLane(router: AnyRouter, lane: ProjectedLane): void {
transferMatchResources(router, lane[1 /* matches */])
discardBackground(router, lane)
Expand Down Expand Up @@ -1673,8 +1680,7 @@ function rollbackPublication(
transferMatchResources(router, discarded, restored)
discardBackground(router, lane)
if (router._tx === tx && router._commitPromise === checkpoint.commitPromise) {
router._commitPromise?.resolve()
router._commitPromise = undefined
resolveCommit(router)
}
return true
}
Expand Down Expand Up @@ -1780,8 +1786,7 @@ function restoreCommitted(
router.stores.setMatches(router._committed)
})
if (router._tx === tx) {
router._commitPromise?.resolve()
router._commitPromise = undefined
resolveCommit(router)
}
}

Expand Down Expand Up @@ -1994,8 +1999,7 @@ async function runClientTransaction(
if (router._tx !== tx) {
return
}
router._commitPromise?.resolve()
router._commitPromise = undefined
resolveCommit(router)
})
}

Expand Down Expand Up @@ -2068,8 +2072,7 @@ export async function loadClientRoute(
router._refreshNextLoad = undefined
}
await awaitCurrent(router)
router._commitPromise?.resolve()
router._commitPromise = undefined
resolveCommit(router)
return
}
await router.navigate({
Expand Down
Loading