Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Dec 12, 2024
1 parent d912f43 commit 94d1902
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ export function updateCacheNodeOnNavigation(
// prefetchRsc, via useDeferredValue.
prefetchRsc: oldCacheNode.prefetchRsc,
viewport: oldCacheNode.viewport,
metadata: oldCacheNode.metadata,
prefetchHead: oldCacheNode.prefetchHead,
loading: oldCacheNode.loading,

Expand Down Expand Up @@ -695,6 +696,7 @@ function createPendingCacheNode(
// response is received from the server.
rsc: createDeferredRsc() as React.ReactNode,
viewport: isLeafSegment ? (createDeferredRsc() as React.ReactNode) : null,
metadata: isLeafSegment ? (createDeferredRsc() as React.ReactNode) : null,
}
}

Expand Down Expand Up @@ -880,7 +882,7 @@ function abortPendingCacheNode(
export function updateCacheNodeOnPopstateRestoration(
oldCacheNode: CacheNode,
routerState: FlightRouterState
) {
): ReadyCacheNode {
// A popstate navigation reads data from the local cache. It does not issue
// new network requests (unless the cache entries have been evicted). So, we
// update the cache to drop the prefetch data for any segment whose dynamic
Expand Down Expand Up @@ -928,7 +930,8 @@ export function updateCacheNodeOnPopstateRestoration(
return {
lazyData: null,
rsc,
head: oldCacheNode.viewport,
viewport: oldCacheNode.viewport,
metadata: oldCacheNode.metadata,

prefetchHead: shouldUsePrefetch ? oldCacheNode.prefetchHead : null,
prefetchRsc: shouldUsePrefetch ? oldCacheNode.prefetchRsc : null,
Expand Down
21 changes: 14 additions & 7 deletions packages/next/src/client/components/segment-cache/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ type PendingRouteCacheEntry = RouteCacheEntryShared & {
blockedTasks: Set<PrefetchTask> | null
canonicalUrl: null
tree: null
head: null
viewport: null
metadata: null
isHeadPartial: true
}

Expand All @@ -89,7 +90,8 @@ type RejectedRouteCacheEntry = RouteCacheEntryShared & {
blockedTasks: Set<PrefetchTask> | null
canonicalUrl: null
tree: null
head: null
viewport: null
metadata: null
isHeadPartial: true
}

Expand All @@ -98,7 +100,8 @@ export type FulfilledRouteCacheEntry = RouteCacheEntryShared & {
blockedTasks: null
canonicalUrl: string
tree: TreePrefetch
head: React.ReactNode | null
viewport: React.ReactNode | null
metadata: React.ReactNode | null
isHeadPartial: boolean
}

Expand Down Expand Up @@ -284,7 +287,8 @@ export function requestRouteCacheEntryFromCache(
status: EntryStatus.Pending,
blockedTasks: null,
tree: null,
head: null,
viewport: null,
metadata: null,
isHeadPartial: true,
// If the request takes longer than a minute, a subsequent request should
// retry instead of waiting for this one.
Expand Down Expand Up @@ -424,7 +428,8 @@ function pingBlockedTasks(entry: {
function fulfillRouteCacheEntry(
entry: PendingRouteCacheEntry,
tree: TreePrefetch,
head: React.ReactNode,
viewport: React.ReactNode,
metadata: React.ReactNode,
isHeadPartial: boolean,
staleAt: number,
couldBeIntercepted: boolean,
Expand All @@ -433,7 +438,8 @@ function fulfillRouteCacheEntry(
const fulfilledEntry: FulfilledRouteCacheEntry = entry as any
fulfilledEntry.status = EntryStatus.Fulfilled
fulfilledEntry.tree = tree
fulfilledEntry.head = head
fulfilledEntry.viewport = viewport
fulfilledEntry.metadata = metadata
fulfilledEntry.isHeadPartial = isHeadPartial
fulfilledEntry.staleAt = staleAt
fulfilledEntry.couldBeIntercepted = couldBeIntercepted
Expand Down Expand Up @@ -552,7 +558,8 @@ async function fetchRouteOnCacheMiss(
fulfillRouteCacheEntry(
entry,
serverData.tree,
serverData.head,
serverData.viewport,
serverData.metadata,
serverData.isHeadPartial,
Date.now() + serverData.staleTime,
couldBeIntercepted,
Expand Down
11 changes: 7 additions & 4 deletions packages/next/src/server/app-render/collect-segment-data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import type { LoadingModuleData } from '../../shared/lib/app-router-context.shar
export type RootTreePrefetch = {
buildId: string
tree: TreePrefetch
head: React.ReactNode | null
viewport: React.ReactNode | null
metadata: React.ReactNode | null
isHeadPartial: boolean
staleTime: number
}
Expand Down Expand Up @@ -178,7 +179,8 @@ async function PrefetchTreeData({
}
const flightRouterState: FlightRouterState = flightDataPaths[0][0]
const seedData: CacheNodeSeedData = flightDataPaths[0][1]
const head: React.ReactNode | null = flightDataPaths[0][2]
const viewport: React.ReactNode | null = flightDataPaths[0][2]
const metadata: React.ReactNode | null = flightDataPaths[0][3]

// Compute the route metadata tree by traversing the FlightRouterState. As we
// walk the tree, we will also spawn a task to produce a prefetch response for
Expand All @@ -195,7 +197,7 @@ async function PrefetchTreeData({
segmentTasks
)

const isHeadPartial = await isPartialRSCData(head, clientModules)
const isHeadPartial = await isPartialRSCData(metadata, clientModules)

// Notify the abort controller that we're done processing the route tree.
// Anything async that happens after this point must be due to hanging
Expand All @@ -206,7 +208,8 @@ async function PrefetchTreeData({
const treePrefetch: RootTreePrefetch = {
buildId,
tree,
head,
viewport,
metadata,
isHeadPartial,
staleTime,
}
Expand Down

0 comments on commit 94d1902

Please sign in to comment.