Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tweak prefetched argument to router cache utils #61177

Merged
Show file tree
Hide file tree
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
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
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function navigateReducer_noPPR(
prefetchQueue.bump(data!)

return data!.then(
([flightData, canonicalUrlOverride, postponed]) => {
([flightData, canonicalUrlOverride]) => {
// we only want to mark this once
if (prefetchValues && !prefetchValues.lastUsedTime) {
// important: we should only mark the cache node as dirty after we unsuspend from the call above
Expand Down Expand Up @@ -226,11 +226,8 @@ function navigateReducer_noPPR(
)

if (
(!applied &&
prefetchEntryCacheStatus === PrefetchCacheEntryStatus.stale) ||
// TODO-APP: If the prefetch was postponed, we don't want to apply it
// until we land router changes to handle the postponed case.
postponed
!applied &&
prefetchEntryCacheStatus === PrefetchCacheEntryStatus.stale
) {
applied = addRefetchToLeafSegments(
cache,
Expand Down
Loading