Skip to content

Commit afdafcf

Browse files
fix: pending component handling for initial load (#4044)
1 parent fff6941 commit afdafcf

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

packages/router-core/src/router.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2274,10 +2274,6 @@ export class RouterCore<
22742274
return !!(allPreload && !this.state.matches.find((d) => d.id === matchId))
22752275
}
22762276

2277-
if (!this.isServer && !this.state.matches.length) {
2278-
triggerOnReady()
2279-
}
2280-
22812277
const handleRedirectAndNotFound = (match: AnyRouteMatch, err: any) => {
22822278
if (isResolvedRedirect(err)) {
22832279
if (!err.reloadDocument) {
@@ -2383,7 +2379,9 @@ export class RouterCore<
23832379
onReady &&
23842380
!this.isServer &&
23852381
!resolvePreload(matchId) &&
2386-
(route.options.loader || route.options.beforeLoad) &&
2382+
(route.options.loader ||
2383+
route.options.beforeLoad ||
2384+
routeNeedsPreload(route)) &&
23872385
typeof pendingMs === 'number' &&
23882386
pendingMs !== Infinity &&
23892387
(route.options.pendingComponent ??
@@ -2668,6 +2666,10 @@ export class RouterCore<
26682666
loaderData,
26692667
})
26702668

2669+
// Last but not least, wait for the the components
2670+
// to be preloaded before we resolve the match
2671+
await route._componentsPromise
2672+
26712673
updateMatch(matchId, (prev) => ({
26722674
...prev,
26732675
error: undefined,
@@ -2710,10 +2712,6 @@ export class RouterCore<
27102712
router: this,
27112713
match: this.getMatch(matchId)!,
27122714
})
2713-
2714-
// Last but not least, wait for the the components
2715-
// to be preloaded before we resolve the match
2716-
await route._componentsPromise
27172715
} catch (err) {
27182716
updateMatch(matchId, (prev) => ({
27192717
...prev,

packages/solid-router/src/Transitioner.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ export function Transitioner() {
3131
const previousIsPagePending = usePrevious(isPagePending)
3232

3333
if (!router.isServer) {
34-
router.startTransition = (fn: () => void) => {
34+
router.startTransition = async (fn: () => void | Promise<void>) => {
3535
setIsTransitioning(true)
36-
fn()
36+
await fn()
3737
setIsTransitioning(false)
3838
}
3939
}

0 commit comments

Comments
 (0)