Skip to content

Commit

Permalink
tweak prefetched argument to router cache utils
Browse files Browse the repository at this point in the history
  • Loading branch information
ztanner committed Jan 30, 2024
1 parent 8fbf043 commit 9f2c41f
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 9f2c41f

Please sign in to comment.