Unverified Commit 5adacb69 authored by Andrew Clark's avatar Andrew Clark Committed by GitHub

Add CacheNode.prefetchRsc field (#59537)

Adds a new field `prefetchRsc` to CacheNode that will be used by the PPR
implementation. It represents a static version of the segment that can
be showed immediately, and may or may not contain dynamic holes. It's
prefetched before a navigation occurs. During rendering, we will choose
whether to render `rsc` or `prefetchRsc` with `useDeferredValue`.

As with the `rsc` field, a value of `null` means no value was provided.
In this case, the LayoutRouter will go straight to rendering the `rsc`
value; if that one is also missing, it will suspend and trigger a lazy
fetch.

The non-PPR implementation will never set this value.

This PR adds the field to the CacheNode type but doesn't implement any
of the behavior yet. Mostly this involves updating the router reducer
unit tests.

Closes NEXT-1855
parent b441cff7
...@@ -147,11 +147,14 @@ function HistoryUpdater({ ...@@ -147,11 +147,14 @@ function HistoryUpdater({
return null return null
} }
export const createEmptyCacheNode = () => ({ export function createEmptyCacheNode(): CacheNode {
lazyData: null, return {
rsc: null, lazyData: null,
parallelRoutes: new Map(), rsc: null,
}) prefetchRsc: null,
parallelRoutes: new Map(),
}
}
function useServerActionDispatcher(dispatch: React.Dispatch<ReducerActions>) { function useServerActionDispatcher(dispatch: React.Dispatch<ReducerActions>) {
const serverActionDispatcher: ServerActionDispatcher = useCallback( const serverActionDispatcher: ServerActionDispatcher = useCallback(
......
...@@ -353,6 +353,9 @@ function InnerLayoutRouter({ ...@@ -353,6 +353,9 @@ function InnerLayoutRouter({
// TODO-APP: remove '' // TODO-APP: remove ''
const refetchTree = walkAddRefetch(['', ...segmentPath], fullTree) const refetchTree = walkAddRefetch(['', ...segmentPath], fullTree)
// TODO: Since this case always suspends indefinitely, and the only thing
// we're doing here is setting `lazyData`, it would be fine to mutate the
// current cache node (if it exists) rather than cloning it.
childNode = { childNode = {
lazyData: fetchServerResponse( lazyData: fetchServerResponse(
new URL(url, location.origin), new URL(url, location.origin),
...@@ -361,6 +364,7 @@ function InnerLayoutRouter({ ...@@ -361,6 +364,7 @@ function InnerLayoutRouter({
buildId buildId
), ),
rsc: null, rsc: null,
prefetchRsc: childNode ? childNode.prefetchRsc : null,
head: childNode ? childNode.head : undefined, head: childNode ? childNode.head : undefined,
parallelRoutes: childNode ? childNode.parallelRoutes : new Map(), parallelRoutes: childNode ? childNode.parallelRoutes : new Map(),
} }
......
...@@ -20,6 +20,12 @@ export function applyFlightData( ...@@ -20,6 +20,12 @@ export function applyFlightData(
if (flightDataPath.length === 3) { if (flightDataPath.length === 3) {
const rsc = cacheNodeSeedData[2] const rsc = cacheNodeSeedData[2]
cache.rsc = rsc cache.rsc = rsc
// This is a PPR-only field. When PPR is enabled, we shouldn't hit
// this path during a navigation, but until PPR is fully implemented
// yet it's possible the existing node does have a non-null
// `prefetchRsc`. As an incremental step, we'll just de-opt to the
// old behavior — no PPR value.
cache.prefetchRsc = null
fillLazyItemsTillLeafWithHead( fillLazyItemsTillLeafWithHead(
cache, cache,
existingCache, existingCache,
...@@ -31,6 +37,10 @@ export function applyFlightData( ...@@ -31,6 +37,10 @@ export function applyFlightData(
} else { } else {
// Copy rsc for the root node of the cache. // Copy rsc for the root node of the cache.
cache.rsc = existingCache.rsc cache.rsc = existingCache.rsc
// This is a PPR-only field. Unlike the previous branch, since we're
// just cloning the existing cache node, we might as well keep the
// PPR value, if it exists.
cache.prefetchRsc = existingCache.prefetchRsc
cache.parallelRoutes = new Map(existingCache.parallelRoutes) cache.parallelRoutes = new Map(existingCache.parallelRoutes)
// Create a copy of the existing cache with the rsc applied. // Create a copy of the existing cache with the rsc applied.
fillCacheWithNewSubTreeData( fillCacheWithNewSubTreeData(
......
...@@ -57,6 +57,7 @@ describe('createInitialRouterState', () => { ...@@ -57,6 +57,7 @@ describe('createInitialRouterState', () => {
const expectedCache: CacheNode = { const expectedCache: CacheNode = {
lazyData: null, lazyData: null,
rsc: children, rsc: children,
prefetchRsc: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -73,6 +74,7 @@ describe('createInitialRouterState', () => { ...@@ -73,6 +74,7 @@ describe('createInitialRouterState', () => {
{ {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
head: <title>Test</title>, head: <title>Test</title>,
}, },
...@@ -82,6 +84,7 @@ describe('createInitialRouterState', () => { ...@@ -82,6 +84,7 @@ describe('createInitialRouterState', () => {
]), ]),
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null,
}, },
], ],
]), ]),
......
...@@ -35,6 +35,7 @@ export function createInitialRouterState({ ...@@ -35,6 +35,7 @@ export function createInitialRouterState({
const cache: CacheNode = { const cache: CacheNode = {
lazyData: null, lazyData: null,
rsc: rsc, rsc: rsc,
prefetchRsc: null,
// The cache gets seeded during the first render. `initialParallelRoutes` ensures the cache from the first render is there during the second render. // The cache gets seeded during the first render. `initialParallelRoutes` ensures the cache from the first render is there during the second render.
parallelRoutes: isServer ? new Map() : initialParallelRoutes, parallelRoutes: isServer ? new Map() : initialParallelRoutes,
} }
......
...@@ -24,11 +24,13 @@ describe('fillCacheWithDataProperty', () => { ...@@ -24,11 +24,13 @@ describe('fillCacheWithDataProperty', () => {
const cache: CacheNode = { const cache: CacheNode = {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
} }
const existingCache: CacheNode = { const existingCache: CacheNode = {
lazyData: null, lazyData: null,
rsc: <>Root layout</>, rsc: <>Root layout</>,
prefetchRsc: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -38,6 +40,7 @@ describe('fillCacheWithDataProperty', () => { ...@@ -38,6 +40,7 @@ describe('fillCacheWithDataProperty', () => {
{ {
lazyData: null, lazyData: null,
rsc: <>Linking</>, rsc: <>Linking</>,
prefetchRsc: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -47,6 +50,7 @@ describe('fillCacheWithDataProperty', () => { ...@@ -47,6 +50,7 @@ describe('fillCacheWithDataProperty', () => {
{ {
lazyData: null, lazyData: null,
rsc: <>Page</>, rsc: <>Page</>,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -76,12 +80,14 @@ describe('fillCacheWithDataProperty', () => { ...@@ -76,12 +80,14 @@ describe('fillCacheWithDataProperty', () => {
"" => { "" => {
"lazyData": null, "lazyData": null,
"parallelRoutes": Map {}, "parallelRoutes": Map {},
"prefetchRsc": null,
"rsc": <React.Fragment> "rsc": <React.Fragment>
Page Page
</React.Fragment>, </React.Fragment>,
}, },
}, },
}, },
"prefetchRsc": null,
"rsc": <React.Fragment> "rsc": <React.Fragment>
Linking Linking
</React.Fragment>, </React.Fragment>,
...@@ -89,10 +95,12 @@ describe('fillCacheWithDataProperty', () => { ...@@ -89,10 +95,12 @@ describe('fillCacheWithDataProperty', () => {
"dashboard" => { "dashboard" => {
"lazyData": Promise {}, "lazyData": Promise {},
"parallelRoutes": Map {}, "parallelRoutes": Map {},
"prefetchRsc": null,
"rsc": null, "rsc": null,
}, },
}, },
}, },
"prefetchRsc": null,
"rsc": null, "rsc": null,
} }
`) `)
......
...@@ -40,6 +40,7 @@ export function fillCacheWithDataProperty( ...@@ -40,6 +40,7 @@ export function fillCacheWithDataProperty(
childSegmentMap.set(cacheKey, { childSegmentMap.set(cacheKey, {
lazyData: fetchResponse(), lazyData: fetchResponse(),
rsc: null, rsc: null,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}) })
} }
...@@ -52,6 +53,7 @@ export function fillCacheWithDataProperty( ...@@ -52,6 +53,7 @@ export function fillCacheWithDataProperty(
childSegmentMap.set(cacheKey, { childSegmentMap.set(cacheKey, {
lazyData: fetchResponse(), lazyData: fetchResponse(),
rsc: null, rsc: null,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}) })
} }
...@@ -62,6 +64,7 @@ export function fillCacheWithDataProperty( ...@@ -62,6 +64,7 @@ export function fillCacheWithDataProperty(
childCacheNode = { childCacheNode = {
lazyData: childCacheNode.lazyData, lazyData: childCacheNode.lazyData,
rsc: childCacheNode.rsc, rsc: childCacheNode.rsc,
prefetchRsc: childCacheNode.prefetchRsc,
parallelRoutes: new Map(childCacheNode.parallelRoutes), parallelRoutes: new Map(childCacheNode.parallelRoutes),
} as CacheNode } as CacheNode
childSegmentMap.set(cacheKey, childCacheNode) childSegmentMap.set(cacheKey, childCacheNode)
......
...@@ -29,11 +29,13 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -29,11 +29,13 @@ describe('fillCacheWithNewSubtreeData', () => {
const cache: CacheNode = { const cache: CacheNode = {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
} }
const existingCache: CacheNode = { const existingCache: CacheNode = {
lazyData: null, lazyData: null,
rsc: <>Root layout</>, rsc: <>Root layout</>,
prefetchRsc: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -43,6 +45,7 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -43,6 +45,7 @@ describe('fillCacheWithNewSubtreeData', () => {
{ {
lazyData: null, lazyData: null,
rsc: <>Linking</>, rsc: <>Linking</>,
prefetchRsc: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -52,6 +55,7 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -52,6 +55,7 @@ describe('fillCacheWithNewSubtreeData', () => {
{ {
lazyData: null, lazyData: null,
rsc: <>Page</>, rsc: <>Page</>,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -79,6 +83,7 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -79,6 +83,7 @@ describe('fillCacheWithNewSubtreeData', () => {
const expectedCache: CacheNode = { const expectedCache: CacheNode = {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -88,6 +93,7 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -88,6 +93,7 @@ describe('fillCacheWithNewSubtreeData', () => {
{ {
lazyData: null, lazyData: null,
rsc: <>Linking</>, rsc: <>Linking</>,
prefetchRsc: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -98,6 +104,7 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -98,6 +104,7 @@ describe('fillCacheWithNewSubtreeData', () => {
{ {
lazyData: null, lazyData: null,
rsc: <>Page</>, rsc: <>Page</>,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -114,6 +121,7 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -114,6 +121,7 @@ describe('fillCacheWithNewSubtreeData', () => {
{ {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
head: ( head: (
<> <>
...@@ -126,6 +134,7 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -126,6 +134,7 @@ describe('fillCacheWithNewSubtreeData', () => {
], ],
]), ]),
rsc: <h1>SubTreeData Injected!</h1>, rsc: <h1>SubTreeData Injected!</h1>,
prefetchRsc: null,
}, },
], ],
]), ]),
......
...@@ -50,6 +50,7 @@ export function fillCacheWithNewSubTreeData( ...@@ -50,6 +50,7 @@ export function fillCacheWithNewSubTreeData(
childCacheNode = { childCacheNode = {
lazyData: null, lazyData: null,
rsc, rsc,
prefetchRsc: null,
// Ensure segments other than the one we got data for are preserved. // Ensure segments other than the one we got data for are preserved.
parallelRoutes: existingChildCacheNode parallelRoutes: existingChildCacheNode
? new Map(existingChildCacheNode.parallelRoutes) ? new Map(existingChildCacheNode.parallelRoutes)
...@@ -88,6 +89,7 @@ export function fillCacheWithNewSubTreeData( ...@@ -88,6 +89,7 @@ export function fillCacheWithNewSubTreeData(
childCacheNode = { childCacheNode = {
lazyData: childCacheNode.lazyData, lazyData: childCacheNode.lazyData,
rsc: childCacheNode.rsc, rsc: childCacheNode.rsc,
prefetchRsc: childCacheNode.prefetchRsc,
parallelRoutes: new Map(childCacheNode.parallelRoutes), parallelRoutes: new Map(childCacheNode.parallelRoutes),
} as CacheNode } as CacheNode
childSegmentMap.set(cacheKey, childCacheNode) childSegmentMap.set(cacheKey, childCacheNode)
......
...@@ -38,11 +38,13 @@ describe('fillLazyItemsTillLeafWithHead', () => { ...@@ -38,11 +38,13 @@ describe('fillLazyItemsTillLeafWithHead', () => {
const cache: CacheNode = { const cache: CacheNode = {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
} }
const existingCache: CacheNode = { const existingCache: CacheNode = {
lazyData: null, lazyData: null,
rsc: <>Root layout</>, rsc: <>Root layout</>,
prefetchRsc: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -52,6 +54,7 @@ describe('fillLazyItemsTillLeafWithHead', () => { ...@@ -52,6 +54,7 @@ describe('fillLazyItemsTillLeafWithHead', () => {
{ {
lazyData: null, lazyData: null,
rsc: <>Linking</>, rsc: <>Linking</>,
prefetchRsc: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -61,6 +64,7 @@ describe('fillLazyItemsTillLeafWithHead', () => { ...@@ -61,6 +64,7 @@ describe('fillLazyItemsTillLeafWithHead', () => {
{ {
lazyData: null, lazyData: null,
rsc: <>Page</>, rsc: <>Page</>,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -94,6 +98,7 @@ describe('fillLazyItemsTillLeafWithHead', () => { ...@@ -94,6 +98,7 @@ describe('fillLazyItemsTillLeafWithHead', () => {
const expectedCache: CacheNode = { const expectedCache: CacheNode = {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -103,6 +108,7 @@ describe('fillLazyItemsTillLeafWithHead', () => { ...@@ -103,6 +108,7 @@ describe('fillLazyItemsTillLeafWithHead', () => {
{ {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -120,6 +126,7 @@ describe('fillLazyItemsTillLeafWithHead', () => { ...@@ -120,6 +126,7 @@ describe('fillLazyItemsTillLeafWithHead', () => {
{ {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
head: ( head: (
<> <>
...@@ -132,6 +139,7 @@ describe('fillLazyItemsTillLeafWithHead', () => { ...@@ -132,6 +139,7 @@ describe('fillLazyItemsTillLeafWithHead', () => {
], ],
]), ]),
rsc: null, rsc: null,
prefetchRsc: null,
}, },
], ],
[ [
...@@ -139,6 +147,7 @@ describe('fillLazyItemsTillLeafWithHead', () => { ...@@ -139,6 +147,7 @@ describe('fillLazyItemsTillLeafWithHead', () => {
{ {
lazyData: null, lazyData: null,
rsc: <>Page</>, rsc: <>Page</>,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
......
...@@ -53,6 +53,12 @@ export function fillLazyItemsTillLeafWithHead( ...@@ -53,6 +53,12 @@ export function fillLazyItemsTillLeafWithHead(
newCacheNode = { newCacheNode = {
lazyData: null, lazyData: null,
rsc: seedNode, rsc: seedNode,
// This is a PPR-only field. When PPR is enabled, we shouldn't hit
// this path during a navigation, but until PPR is fully implemented
// yet it's possible the existing node does have a non-null
// `prefetchRsc`. As an incremental step, we'll just de-opt to the
// old behavior — no PPR value.
prefetchRsc: null,
parallelRoutes: new Map(existingCacheNode?.parallelRoutes), parallelRoutes: new Map(existingCacheNode?.parallelRoutes),
} }
} else if (wasPrefetched && existingCacheNode) { } else if (wasPrefetched && existingCacheNode) {
...@@ -61,6 +67,10 @@ export function fillLazyItemsTillLeafWithHead( ...@@ -61,6 +67,10 @@ export function fillLazyItemsTillLeafWithHead(
newCacheNode = { newCacheNode = {
lazyData: existingCacheNode.lazyData, lazyData: existingCacheNode.lazyData,
rsc: existingCacheNode.rsc, rsc: existingCacheNode.rsc,
// This is a PPR-only field. Unlike the previous branch, since we're
// just cloning the existing cache node, we might as well keep the
// PPR value, if it exists.
prefetchRsc: existingCacheNode.prefetchRsc,
parallelRoutes: new Map(existingCacheNode.parallelRoutes), parallelRoutes: new Map(existingCacheNode.parallelRoutes),
} as CacheNode } as CacheNode
} else { } else {
...@@ -69,6 +79,7 @@ export function fillLazyItemsTillLeafWithHead( ...@@ -69,6 +79,7 @@ export function fillLazyItemsTillLeafWithHead(
newCacheNode = { newCacheNode = {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null,
parallelRoutes: new Map(existingCacheNode?.parallelRoutes), parallelRoutes: new Map(existingCacheNode?.parallelRoutes),
} }
} }
...@@ -97,6 +108,7 @@ export function fillLazyItemsTillLeafWithHead( ...@@ -97,6 +108,7 @@ export function fillLazyItemsTillLeafWithHead(
newCacheNode = { newCacheNode = {
lazyData: null, lazyData: null,
rsc: seedNode, rsc: seedNode,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
} }
} else { } else {
...@@ -105,6 +117,7 @@ export function fillLazyItemsTillLeafWithHead( ...@@ -105,6 +117,7 @@ export function fillLazyItemsTillLeafWithHead(
newCacheNode = { newCacheNode = {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
} }
} }
......
...@@ -30,11 +30,13 @@ describe('invalidateCacheBelowFlightSegmentPath', () => { ...@@ -30,11 +30,13 @@ describe('invalidateCacheBelowFlightSegmentPath', () => {
const cache: CacheNode = { const cache: CacheNode = {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
} }
const existingCache: CacheNode = { const existingCache: CacheNode = {
lazyData: null, lazyData: null,
rsc: <>Root layout</>, rsc: <>Root layout</>,
prefetchRsc: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -44,6 +46,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => { ...@@ -44,6 +46,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => {
{ {
lazyData: null, lazyData: null,
rsc: <>Linking</>, rsc: <>Linking</>,
prefetchRsc: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -53,6 +56,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => { ...@@ -53,6 +56,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => {
{ {
lazyData: null, lazyData: null,
rsc: <>Page</>, rsc: <>Page</>,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -78,6 +82,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => { ...@@ -78,6 +82,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => {
// Copy rsc for the root node of the cache. // Copy rsc for the root node of the cache.
cache.rsc = existingCache.rsc cache.rsc = existingCache.rsc
cache.prefetchRsc = existingCache.prefetchRsc
// Create a copy of the existing cache with the rsc applied. // Create a copy of the existing cache with the rsc applied.
fillCacheWithNewSubTreeData(cache, existingCache, flightDataPath, false) fillCacheWithNewSubTreeData(cache, existingCache, flightDataPath, false)
...@@ -108,18 +113,21 @@ describe('invalidateCacheBelowFlightSegmentPath', () => { ...@@ -108,18 +113,21 @@ describe('invalidateCacheBelowFlightSegmentPath', () => {
lazyData: null, lazyData: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
rsc: <React.Fragment>Page</React.Fragment>, rsc: <React.Fragment>Page</React.Fragment>,
prefetchRsc: null,
}, },
], ],
]), ]),
], ],
]), ]),
rsc: <React.Fragment>Linking</React.Fragment>, rsc: <React.Fragment>Linking</React.Fragment>,
prefetchRsc: null,
}, },
], ],
]), ]),
], ],
]), ]),
rsc: <>Root layout</>, rsc: <>Root layout</>,
prefetchRsc: null,
} }
expect(cache).toMatchObject(expectedCache) expect(cache).toMatchObject(expectedCache)
......
...@@ -49,6 +49,7 @@ export function invalidateCacheBelowFlightSegmentPath( ...@@ -49,6 +49,7 @@ export function invalidateCacheBelowFlightSegmentPath(
childCacheNode = { childCacheNode = {
lazyData: childCacheNode.lazyData, lazyData: childCacheNode.lazyData,
rsc: childCacheNode.rsc, rsc: childCacheNode.rsc,
prefetchRsc: childCacheNode.prefetchRsc,
parallelRoutes: new Map(childCacheNode.parallelRoutes), parallelRoutes: new Map(childCacheNode.parallelRoutes),
} as CacheNode } as CacheNode
childSegmentMap.set(cacheKey, childCacheNode) childSegmentMap.set(cacheKey, childCacheNode)
......
...@@ -8,11 +8,13 @@ describe('invalidateCacheByRouterState', () => { ...@@ -8,11 +8,13 @@ describe('invalidateCacheByRouterState', () => {
const cache: CacheNode = { const cache: CacheNode = {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
} }
const existingCache: CacheNode = { const existingCache: CacheNode = {
lazyData: null, lazyData: null,
rsc: <>Root layout</>, rsc: <>Root layout</>,
prefetchRsc: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -22,6 +24,7 @@ describe('invalidateCacheByRouterState', () => { ...@@ -22,6 +24,7 @@ describe('invalidateCacheByRouterState', () => {
{ {
lazyData: null, lazyData: null,
rsc: <>Linking</>, rsc: <>Linking</>,
prefetchRsc: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -31,6 +34,7 @@ describe('invalidateCacheByRouterState', () => { ...@@ -31,6 +34,7 @@ describe('invalidateCacheByRouterState', () => {
{ {
lazyData: null, lazyData: null,
rsc: <>Page</>, rsc: <>Page</>,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -69,6 +73,7 @@ describe('invalidateCacheByRouterState', () => { ...@@ -69,6 +73,7 @@ describe('invalidateCacheByRouterState', () => {
const expectedCache: CacheNode = { const expectedCache: CacheNode = {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null,
parallelRoutes: new Map([['children', new Map()]]), parallelRoutes: new Map([['children', new Map()]]),
} }
......
...@@ -28,6 +28,7 @@ describe('findHeadInCache', () => { ...@@ -28,6 +28,7 @@ describe('findHeadInCache', () => {
const cache: CacheNode = { const cache: CacheNode = {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -37,6 +38,7 @@ describe('findHeadInCache', () => { ...@@ -37,6 +38,7 @@ describe('findHeadInCache', () => {
{ {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -54,6 +56,7 @@ describe('findHeadInCache', () => { ...@@ -54,6 +56,7 @@ describe('findHeadInCache', () => {
{ {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
head: ( head: (
<> <>
...@@ -66,6 +69,7 @@ describe('findHeadInCache', () => { ...@@ -66,6 +69,7 @@ describe('findHeadInCache', () => {
], ],
]), ]),
rsc: null, rsc: null,
prefetchRsc: null,
}, },
], ],
// TODO-APP: this segment should be preserved when creating the new cache // TODO-APP: this segment should be preserved when creating the new cache
...@@ -74,6 +78,7 @@ describe('findHeadInCache', () => { ...@@ -74,6 +78,7 @@ describe('findHeadInCache', () => {
// { // {
// lazyData: null, // lazyData: null,
// rsc: <>Page</>, // rsc: <>Page</>,
// prefetchRsc: null,
// parallelRoutes: new Map(), // parallelRoutes: new Map(),
// }, // },
// ], // ],
......
...@@ -78,6 +78,7 @@ function addRefetchToLeafSegments( ...@@ -78,6 +78,7 @@ function addRefetchToLeafSegments(
let appliedPatch = false let appliedPatch = false
newCache.rsc = currentCache.rsc newCache.rsc = currentCache.rsc
newCache.prefetchRsc = currentCache.prefetchRsc
newCache.parallelRoutes = new Map(currentCache.parallelRoutes) newCache.parallelRoutes = new Map(currentCache.parallelRoutes)
const segmentPathsToFill = generateSegmentsFromPatch(treePatch).map( const segmentPathsToFill = generateSegmentsFromPatch(treePatch).map(
...@@ -239,6 +240,7 @@ export function navigateReducer( ...@@ -239,6 +240,7 @@ export function navigateReducer(
if (hardNavigate) { if (hardNavigate) {
// Copy rsc for the root node of the cache. // Copy rsc for the root node of the cache.
cache.rsc = currentCache.rsc cache.rsc = currentCache.rsc
cache.prefetchRsc = currentCache.prefetchRsc
invalidateCacheBelowFlightSegmentPath( invalidateCacheBelowFlightSegmentPath(
cache, cache,
......
...@@ -95,6 +95,7 @@ describe('prefetchReducer', () => { ...@@ -95,6 +95,7 @@ describe('prefetchReducer', () => {
{ {
lazyData: null, lazyData: null,
rsc: <>Linking page</>, rsc: <>Linking page</>,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -103,6 +104,7 @@ describe('prefetchReducer', () => { ...@@ -103,6 +104,7 @@ describe('prefetchReducer', () => {
]), ]),
lazyData: null, lazyData: null,
rsc: <>Linking layout level</>, rsc: <>Linking layout level</>,
prefetchRsc: null,
}, },
], ],
]), ]),
...@@ -187,6 +189,7 @@ describe('prefetchReducer', () => { ...@@ -187,6 +189,7 @@ describe('prefetchReducer', () => {
<body>Root layout</body> <body>Root layout</body>
</html> </html>
), ),
prefetchRsc: null,
parallelRoutes: initialParallelRoutes, parallelRoutes: initialParallelRoutes,
}, },
tree: [ tree: [
...@@ -234,6 +237,7 @@ describe('prefetchReducer', () => { ...@@ -234,6 +237,7 @@ describe('prefetchReducer', () => {
{ {
lazyData: null, lazyData: null,
rsc: <>Linking page</>, rsc: <>Linking page</>,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -242,6 +246,7 @@ describe('prefetchReducer', () => { ...@@ -242,6 +246,7 @@ describe('prefetchReducer', () => {
]), ]),
lazyData: null, lazyData: null,
rsc: <>Linking layout level</>, rsc: <>Linking layout level</>,
prefetchRsc: null,
}, },
], ],
]), ]),
...@@ -340,6 +345,7 @@ describe('prefetchReducer', () => { ...@@ -340,6 +345,7 @@ describe('prefetchReducer', () => {
<body>Root layout</body> <body>Root layout</body>
</html> </html>
), ),
prefetchRsc: null,
parallelRoutes: initialParallelRoutes, parallelRoutes: initialParallelRoutes,
}, },
tree: [ tree: [
......
...@@ -106,6 +106,7 @@ describe('refreshReducer', () => { ...@@ -106,6 +106,7 @@ describe('refreshReducer', () => {
{ {
lazyData: null, lazyData: null,
rsc: <>Linking page</>, rsc: <>Linking page</>,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -114,6 +115,7 @@ describe('refreshReducer', () => { ...@@ -114,6 +115,7 @@ describe('refreshReducer', () => {
]), ]),
lazyData: null, lazyData: null,
rsc: <>Linking layout level</>, rsc: <>Linking layout level</>,
prefetchRsc: null,
}, },
], ],
]), ]),
...@@ -165,6 +167,7 @@ describe('refreshReducer', () => { ...@@ -165,6 +167,7 @@ describe('refreshReducer', () => {
</body> </body>
</html> </html>
), ),
prefetchRsc: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -181,6 +184,7 @@ describe('refreshReducer', () => { ...@@ -181,6 +184,7 @@ describe('refreshReducer', () => {
{ {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
head: ( head: (
<> <>
...@@ -194,6 +198,7 @@ describe('refreshReducer', () => { ...@@ -194,6 +198,7 @@ describe('refreshReducer', () => {
]), ]),
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null,
}, },
], ],
]), ]),
...@@ -244,6 +249,7 @@ describe('refreshReducer', () => { ...@@ -244,6 +249,7 @@ describe('refreshReducer', () => {
{ {
lazyData: null, lazyData: null,
rsc: <>Linking page</>, rsc: <>Linking page</>,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -252,6 +258,7 @@ describe('refreshReducer', () => { ...@@ -252,6 +258,7 @@ describe('refreshReducer', () => {
]), ]),
lazyData: null, lazyData: null,
rsc: <>Linking layout level</>, rsc: <>Linking layout level</>,
prefetchRsc: null,
}, },
], ],
]), ]),
...@@ -317,6 +324,7 @@ describe('refreshReducer', () => { ...@@ -317,6 +324,7 @@ describe('refreshReducer', () => {
</body> </body>
</html> </html>
), ),
prefetchRsc: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -333,6 +341,7 @@ describe('refreshReducer', () => { ...@@ -333,6 +341,7 @@ describe('refreshReducer', () => {
{ {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
head: ( head: (
<> <>
...@@ -346,6 +355,7 @@ describe('refreshReducer', () => { ...@@ -346,6 +355,7 @@ describe('refreshReducer', () => {
]), ]),
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null,
}, },
], ],
]), ]),
...@@ -396,6 +406,7 @@ describe('refreshReducer', () => { ...@@ -396,6 +406,7 @@ describe('refreshReducer', () => {
{ {
lazyData: null, lazyData: null,
rsc: <>Linking page</>, rsc: <>Linking page</>,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -404,6 +415,7 @@ describe('refreshReducer', () => { ...@@ -404,6 +415,7 @@ describe('refreshReducer', () => {
]), ]),
lazyData: null, lazyData: null,
rsc: <>Linking layout level</>, rsc: <>Linking layout level</>,
prefetchRsc: null,
}, },
], ],
[ [
...@@ -418,6 +430,7 @@ describe('refreshReducer', () => { ...@@ -418,6 +430,7 @@ describe('refreshReducer', () => {
{ {
lazyData: null, lazyData: null,
rsc: <>About page</>, rsc: <>About page</>,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -426,6 +439,7 @@ describe('refreshReducer', () => { ...@@ -426,6 +439,7 @@ describe('refreshReducer', () => {
]), ]),
lazyData: null, lazyData: null,
rsc: <>About layout level</>, rsc: <>About layout level</>,
prefetchRsc: null,
}, },
], ],
]), ]),
...@@ -491,6 +505,7 @@ describe('refreshReducer', () => { ...@@ -491,6 +505,7 @@ describe('refreshReducer', () => {
</body> </body>
</html> </html>
), ),
prefetchRsc: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -507,6 +522,7 @@ describe('refreshReducer', () => { ...@@ -507,6 +522,7 @@ describe('refreshReducer', () => {
{ {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
head: ( head: (
<> <>
...@@ -520,6 +536,7 @@ describe('refreshReducer', () => { ...@@ -520,6 +536,7 @@ describe('refreshReducer', () => {
]), ]),
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null,
}, },
], ],
]), ]),
...@@ -570,6 +587,7 @@ describe('refreshReducer', () => { ...@@ -570,6 +587,7 @@ describe('refreshReducer', () => {
{ {
lazyData: null, lazyData: null,
rsc: <>Linking page</>, rsc: <>Linking page</>,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -578,6 +596,7 @@ describe('refreshReducer', () => { ...@@ -578,6 +596,7 @@ describe('refreshReducer', () => {
]), ]),
lazyData: null, lazyData: null,
rsc: <>Linking layout level</>, rsc: <>Linking layout level</>,
prefetchRsc: null,
}, },
], ],
[ [
...@@ -592,6 +611,7 @@ describe('refreshReducer', () => { ...@@ -592,6 +611,7 @@ describe('refreshReducer', () => {
{ {
lazyData: null, lazyData: null,
rsc: <>About page</>, rsc: <>About page</>,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -600,6 +620,7 @@ describe('refreshReducer', () => { ...@@ -600,6 +620,7 @@ describe('refreshReducer', () => {
]), ]),
lazyData: null, lazyData: null,
rsc: <>About layout level</>, rsc: <>About layout level</>,
prefetchRsc: null,
}, },
], ],
]), ]),
...@@ -714,6 +735,7 @@ describe('refreshReducer', () => { ...@@ -714,6 +735,7 @@ describe('refreshReducer', () => {
</body> </body>
</html> </html>
), ),
prefetchRsc: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -730,6 +752,7 @@ describe('refreshReducer', () => { ...@@ -730,6 +752,7 @@ describe('refreshReducer', () => {
{ {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
head: ( head: (
<> <>
...@@ -743,6 +766,7 @@ describe('refreshReducer', () => { ...@@ -743,6 +766,7 @@ describe('refreshReducer', () => {
]), ]),
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null,
}, },
], ],
]), ]),
......
...@@ -96,6 +96,7 @@ export function refreshReducer( ...@@ -96,6 +96,7 @@ export function refreshReducer(
if (cacheNodeSeedData !== null) { if (cacheNodeSeedData !== null) {
const rsc = cacheNodeSeedData[2] const rsc = cacheNodeSeedData[2]
cache.rsc = rsc cache.rsc = rsc
cache.prefetchRsc = null
fillLazyItemsTillLeafWithHead( fillLazyItemsTillLeafWithHead(
cache, cache,
// Existing cache is not passed in as `router.refresh()` has to invalidate the entire cache. // Existing cache is not passed in as `router.refresh()` has to invalidate the entire cache.
......
...@@ -62,6 +62,7 @@ describe('serverPatchReducer', () => { ...@@ -62,6 +62,7 @@ describe('serverPatchReducer', () => {
{ {
lazyData: null, lazyData: null,
rsc: <>Linking page</>, rsc: <>Linking page</>,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -70,6 +71,7 @@ describe('serverPatchReducer', () => { ...@@ -70,6 +71,7 @@ describe('serverPatchReducer', () => {
]), ]),
lazyData: null, lazyData: null,
rsc: <>Linking layout level</>, rsc: <>Linking layout level</>,
prefetchRsc: null,
}, },
], ],
]), ]),
...@@ -138,6 +140,7 @@ describe('serverPatchReducer', () => { ...@@ -138,6 +140,7 @@ describe('serverPatchReducer', () => {
<body>Root layout</body> <body>Root layout</body>
</html> </html>
), ),
prefetchRsc: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -154,6 +157,7 @@ describe('serverPatchReducer', () => { ...@@ -154,6 +157,7 @@ describe('serverPatchReducer', () => {
{ {
lazyData: null, lazyData: null,
rsc: <>Linking page</>, rsc: <>Linking page</>,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -162,6 +166,7 @@ describe('serverPatchReducer', () => { ...@@ -162,6 +166,7 @@ describe('serverPatchReducer', () => {
]), ]),
lazyData: null, lazyData: null,
rsc: <>Linking layout level</>, rsc: <>Linking layout level</>,
prefetchRsc: null,
}, },
], ],
]), ]),
...@@ -212,6 +217,7 @@ describe('serverPatchReducer', () => { ...@@ -212,6 +217,7 @@ describe('serverPatchReducer', () => {
{ {
lazyData: null, lazyData: null,
rsc: <>Linking page</>, rsc: <>Linking page</>,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -220,6 +226,7 @@ describe('serverPatchReducer', () => { ...@@ -220,6 +226,7 @@ describe('serverPatchReducer', () => {
]), ]),
lazyData: null, lazyData: null,
rsc: <>Linking layout level</>, rsc: <>Linking layout level</>,
prefetchRsc: null,
}, },
], ],
]), ]),
...@@ -301,6 +308,7 @@ describe('serverPatchReducer', () => { ...@@ -301,6 +308,7 @@ describe('serverPatchReducer', () => {
<body>Root layout</body> <body>Root layout</body>
</html> </html>
), ),
prefetchRsc: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -317,6 +325,7 @@ describe('serverPatchReducer', () => { ...@@ -317,6 +325,7 @@ describe('serverPatchReducer', () => {
{ {
lazyData: null, lazyData: null,
rsc: <>Linking page</>, rsc: <>Linking page</>,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -325,6 +334,7 @@ describe('serverPatchReducer', () => { ...@@ -325,6 +334,7 @@ describe('serverPatchReducer', () => {
]), ]),
lazyData: null, lazyData: null,
rsc: <>Linking layout level</>, rsc: <>Linking layout level</>,
prefetchRsc: null,
}, },
], ],
]), ]),
......
...@@ -244,6 +244,7 @@ export function serverActionReducer( ...@@ -244,6 +244,7 @@ export function serverActionReducer(
if (rsc !== null) { if (rsc !== null) {
const cache: CacheNode = createEmptyCacheNode() const cache: CacheNode = createEmptyCacheNode()
cache.rsc = rsc cache.rsc = rsc
cache.prefetchRsc = null
fillLazyItemsTillLeafWithHead( fillLazyItemsTillLeafWithHead(
cache, cache,
// Existing cache is not passed in as `router.refresh()` has to invalidate the entire cache. // Existing cache is not passed in as `router.refresh()` has to invalidate the entire cache.
......
...@@ -113,6 +113,7 @@ describe('serverPatchReducer', () => { ...@@ -113,6 +113,7 @@ describe('serverPatchReducer', () => {
{ {
lazyData: null, lazyData: null,
rsc: <>Linking page</>, rsc: <>Linking page</>,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -121,6 +122,7 @@ describe('serverPatchReducer', () => { ...@@ -121,6 +122,7 @@ describe('serverPatchReducer', () => {
]), ]),
lazyData: null, lazyData: null,
rsc: <>Linking layout level</>, rsc: <>Linking layout level</>,
prefetchRsc: null,
}, },
], ],
]), ]),
...@@ -173,6 +175,7 @@ describe('serverPatchReducer', () => { ...@@ -173,6 +175,7 @@ describe('serverPatchReducer', () => {
"" => { "" => {
"lazyData": null, "lazyData": null,
"parallelRoutes": Map {}, "parallelRoutes": Map {},
"prefetchRsc": null,
"rsc": <React.Fragment> "rsc": <React.Fragment>
Linking page Linking page
</React.Fragment>, </React.Fragment>,
...@@ -189,22 +192,26 @@ describe('serverPatchReducer', () => { ...@@ -189,22 +192,26 @@ describe('serverPatchReducer', () => {
</React.Fragment>, </React.Fragment>,
"lazyData": null, "lazyData": null,
"parallelRoutes": Map {}, "parallelRoutes": Map {},
"prefetchRsc": null,
"rsc": null, "rsc": null,
}, },
}, },
}, },
"prefetchRsc": null,
"rsc": <h1> "rsc": <h1>
Somewhere Page! Somewhere Page!
</h1>, </h1>,
}, },
}, },
}, },
"prefetchRsc": null,
"rsc": <React.Fragment> "rsc": <React.Fragment>
Linking layout level Linking layout level
</React.Fragment>, </React.Fragment>,
}, },
}, },
}, },
"prefetchRsc": null,
"rsc": <html> "rsc": <html>
<head /> <head />
<body> <body>
...@@ -277,6 +284,7 @@ describe('serverPatchReducer', () => { ...@@ -277,6 +284,7 @@ describe('serverPatchReducer', () => {
{ {
lazyData: null, lazyData: null,
rsc: <>Linking page</>, rsc: <>Linking page</>,
prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -285,6 +293,7 @@ describe('serverPatchReducer', () => { ...@@ -285,6 +293,7 @@ describe('serverPatchReducer', () => {
]), ]),
lazyData: null, lazyData: null,
rsc: <>Linking layout level</>, rsc: <>Linking layout level</>,
prefetchRsc: null,
}, },
], ],
]), ]),
...@@ -349,6 +358,7 @@ describe('serverPatchReducer', () => { ...@@ -349,6 +358,7 @@ describe('serverPatchReducer', () => {
"" => { "" => {
"lazyData": null, "lazyData": null,
"parallelRoutes": Map {}, "parallelRoutes": Map {},
"prefetchRsc": null,
"rsc": <React.Fragment> "rsc": <React.Fragment>
Linking page Linking page
</React.Fragment>, </React.Fragment>,
...@@ -365,10 +375,12 @@ describe('serverPatchReducer', () => { ...@@ -365,10 +375,12 @@ describe('serverPatchReducer', () => {
</React.Fragment>, </React.Fragment>,
"lazyData": null, "lazyData": null,
"parallelRoutes": Map {}, "parallelRoutes": Map {},
"prefetchRsc": null,
"rsc": null, "rsc": null,
}, },
}, },
}, },
"prefetchRsc": null,
"rsc": <h1> "rsc": <h1>
About Page! About Page!
</h1>, </h1>,
...@@ -385,22 +397,26 @@ describe('serverPatchReducer', () => { ...@@ -385,22 +397,26 @@ describe('serverPatchReducer', () => {
</React.Fragment>, </React.Fragment>,
"lazyData": null, "lazyData": null,
"parallelRoutes": Map {}, "parallelRoutes": Map {},
"prefetchRsc": null,
"rsc": null, "rsc": null,
}, },
}, },
}, },
"prefetchRsc": null,
"rsc": <h1> "rsc": <h1>
Somewhere Page! Somewhere Page!
</h1>, </h1>,
}, },
}, },
}, },
"prefetchRsc": null,
"rsc": <React.Fragment> "rsc": <React.Fragment>
Linking layout level Linking layout level
</React.Fragment>, </React.Fragment>,
}, },
}, },
}, },
"prefetchRsc": null,
"rsc": <html> "rsc": <html>
<head /> <head />
<body> <body>
......
...@@ -31,8 +31,16 @@ export type LazyCacheNode = { ...@@ -31,8 +31,16 @@ export type LazyCacheNode = {
*/ */
rsc: null rsc: null
// TODO: Add prefetchRsc field. /**
// prefetchRsc: null * A prefetched version of the segment data. See explanation in corresponding
* field of ReadyCacheNode (below).
*
* Since LazyCacheNode mostly only exists in the non-PPR implementation, this
* will usually be null, but it could have been cloned from a previous
* CacheNode that was created by the PPR implementation. Eventually we want
* to migrate everything away from LazyCacheNode entirely.
*/
prefetchRsc: React.ReactNode
/** /**
* A pending response for the lazy data fetch. If this is not present * A pending response for the lazy data fetch. If this is not present
...@@ -61,8 +69,18 @@ export type ReadyCacheNode = { ...@@ -61,8 +69,18 @@ export type ReadyCacheNode = {
*/ */
rsc: React.ReactNode rsc: React.ReactNode
// TODO: Add prefetchRsc field. /**
// prefetchRsc: React.ReactNode * Represents a static version of the segment that can be shown immediately,
* and may or may not contain dynamic holes. It's prefetched before a
* navigation occurs.
*
* During rendering, we will choose whether to render `rsc` or `prefetchRsc`
* with `useDeferredValue`. As with the `rsc` field, a value of `null` means
* no value was provided. In this case, the LayoutRouter will go straight to
* rendering the `rsc` value; if that one is also missing, it will suspend and
* trigger a lazy fetch.
*/
prefetchRsc: React.ReactNode
/** /**
* There should never be a lazy data request in this case. * There should never be a lazy data request in this case.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment