Skip to content

Commit

Permalink
tweak prefetched argument to router cache utils (#61177)
Browse files Browse the repository at this point in the history
No behavior changes here, purely renaming this argument as I found it
confusing while working on a router cache bug. It's not strictly
representing if a cache node was prefetched, but rather if the prefetch
entry exists & can be re-used, since it could be that it was prefetched
but had a prefetch status of stale/expired.

Closes NEXT-2245
  • Loading branch information
ztanner authored Jan 31, 2024
1 parent 41b35f3 commit 5d793e8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function applyFlightData(
existingCache: CacheNode,
cache: CacheNode,
flightDataPath: FlightDataPath,
wasPrefetched: boolean = false
hasReusablePrefetch: boolean = false
): boolean {
// The one before last item is the router state tree patch
const [treePatch, cacheNodeSeedData, head] = flightDataPath.slice(-3)
Expand All @@ -32,7 +32,7 @@ export function applyFlightData(
treePatch,
cacheNodeSeedData,
head,
wasPrefetched
hasReusablePrefetch
)
} else {
// Copy rsc for the root node of the cache.
Expand All @@ -47,7 +47,7 @@ export function applyFlightData(
cache,
existingCache,
flightDataPath,
wasPrefetched
hasReusablePrefetch
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function fillCacheWithNewSubTreeData(
newCache: CacheNode,
existingCache: CacheNode,
flightDataPath: FlightDataPath,
wasPrefetched?: boolean
hasReusablePrefetch?: boolean
): void {
const isLastEntry = flightDataPath.length <= 5
const [parallelRouteKey, segment] = flightDataPath
Expand Down Expand Up @@ -71,7 +71,7 @@ export function fillCacheWithNewSubTreeData(
flightDataPath[2],
seedData,
flightDataPath[4],
wasPrefetched
hasReusablePrefetch
)

childSegmentMap.set(cacheKey, childCacheNode)
Expand Down Expand Up @@ -99,6 +99,6 @@ export function fillCacheWithNewSubTreeData(
childCacheNode,
existingChildCacheNode,
flightDataPath.slice(2),
wasPrefetched
hasReusablePrefetch
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function fillLazyItemsTillLeafWithHead(
routerState: FlightRouterState,
cacheNodeSeedData: CacheNodeSeedData | null,
head: React.ReactNode,
wasPrefetched?: boolean
hasReusablePrefetch?: boolean
): void {
const isLastSegment = Object.keys(routerState[1]).length === 0
if (isLastSegment) {
Expand Down Expand Up @@ -59,9 +59,9 @@ export function fillLazyItemsTillLeafWithHead(
prefetchRsc: null,
parallelRoutes: new Map(existingCacheNode?.parallelRoutes),
}
} else if (wasPrefetched && existingCacheNode) {
} else if (hasReusablePrefetch && existingCacheNode) {
// No new data was sent from the server, but the existing cache node
// was prefetched, so we should reuse that.
// has a non-expired prefetch, so we should reuse that.
newCacheNode = {
lazyData: existingCacheNode.lazyData,
rsc: existingCacheNode.rsc,
Expand All @@ -72,7 +72,7 @@ export function fillLazyItemsTillLeafWithHead(
parallelRoutes: new Map(existingCacheNode.parallelRoutes),
} as CacheNode
} else {
// No data available for this node. This will trigger a lazy fetch
// No data available for this node, or the prefetch entry expired. This will trigger a lazy fetch
// during render.
newCacheNode = {
lazyData: null,
Expand All @@ -91,7 +91,7 @@ export function fillLazyItemsTillLeafWithHead(
parallelRouteState,
parallelSeedData ? parallelSeedData : null,
head,
wasPrefetched
hasReusablePrefetch
)

newCache.parallelRoutes.set(key, parallelRouteCacheNode)
Expand Down Expand Up @@ -133,7 +133,7 @@ export function fillLazyItemsTillLeafWithHead(
parallelRouteState,
parallelSeedData,
head,
wasPrefetched
hasReusablePrefetch
)
}
}

0 comments on commit 5d793e8

Please sign in to comment.