Unverified Commit 9663d78b authored by Andrew Clark's avatar Andrew Clark Committed by GitHub

Rename CacheNode.subTreeData -> .rsc (#59491)

I want to give this field a name that's bit less generic and
distinguishes it from `lazyData` (because that one has a different type
and is a special case we want to eventually remove).

I'm also about to add an optional `prefetchRsc` field that represents a
prefetched version of the same value. The common suffix is meant to
communicate how they are related.

Doing this rename in its own PR because it's a pure find-and-replace,
whereas the later steps are not.

Closes NEXT-1846
parent 2dbd4e75
...@@ -149,7 +149,7 @@ function HistoryUpdater({ ...@@ -149,7 +149,7 @@ function HistoryUpdater({
export const createEmptyCacheNode = () => ({ export const createEmptyCacheNode = () => ({
lazyData: null, lazyData: null,
subTreeData: null, rsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}) })
...@@ -546,7 +546,7 @@ function Router({ ...@@ -546,7 +546,7 @@ function Router({
let content = ( let content = (
<RedirectBoundary> <RedirectBoundary>
{head} {head}
{cache.subTreeData} {cache.rsc}
<AppRouterAnnouncer tree={tree} /> <AppRouterAnnouncer tree={tree} />
</RedirectBoundary> </RedirectBoundary>
) )
......
...@@ -345,7 +345,7 @@ function InnerLayoutRouter({ ...@@ -345,7 +345,7 @@ function InnerLayoutRouter({
// data request. // data request.
// //
// TODO: An eventual goal of PPR is to remove this case entirely. // TODO: An eventual goal of PPR is to remove this case entirely.
(childNode.subTreeData === null && childNode.lazyData === null) (childNode.rsc === null && childNode.lazyData === null)
) { ) {
/** /**
* Router state with refetch marker added * Router state with refetch marker added
...@@ -360,7 +360,7 @@ function InnerLayoutRouter({ ...@@ -360,7 +360,7 @@ function InnerLayoutRouter({
context.nextUrl, context.nextUrl,
buildId buildId
), ),
subTreeData: null, rsc: null,
head: childNode ? childNode.head : undefined, head: childNode ? childNode.head : undefined,
parallelRoutes: childNode ? childNode.parallelRoutes : new Map(), parallelRoutes: childNode ? childNode.parallelRoutes : new Map(),
} }
...@@ -377,8 +377,8 @@ function InnerLayoutRouter({ ...@@ -377,8 +377,8 @@ function InnerLayoutRouter({
} }
// This case should never happen so it throws an error. It indicates there's a bug in the Next.js. // This case should never happen so it throws an error. It indicates there's a bug in the Next.js.
if (childNode.subTreeData && childNode.lazyData) { if (childNode.rsc && childNode.lazyData) {
throw new Error('Child node should not have both subTreeData and lazyData') throw new Error('Child node should not have both rsc and lazyData')
} }
// If cache node has a data request we have to unwrap response by `use` and update the cache. // If cache node has a data request we have to unwrap response by `use` and update the cache.
...@@ -402,9 +402,9 @@ function InnerLayoutRouter({ ...@@ -402,9 +402,9 @@ function InnerLayoutRouter({
use(createInfinitePromise()) use(createInfinitePromise())
} }
// If cache node has no subTreeData and no lazy data request we have to infinitely suspend as the data will likely flow in from another place. // If cache node has no rsc and no lazy data request we have to infinitely suspend as the data will likely flow in from another place.
// TODO-APP: double check users can't return null in a component that will kick in here. // TODO-APP: double check users can't return null in a component that will kick in here.
if (!childNode.subTreeData) { if (!childNode.rsc) {
use(createInfinitePromise()) use(createInfinitePromise())
} }
...@@ -418,7 +418,7 @@ function InnerLayoutRouter({ ...@@ -418,7 +418,7 @@ function InnerLayoutRouter({
url: url, url: url,
}} }}
> >
{childNode.subTreeData} {childNode.rsc}
</LayoutRouterContext.Provider> </LayoutRouterContext.Provider>
) )
// Ensure root layout is not wrapped in a div as the root layout renders `<html>` // Ensure root layout is not wrapped in a div as the root layout renders `<html>`
......
...@@ -18,8 +18,8 @@ export function applyFlightData( ...@@ -18,8 +18,8 @@ export function applyFlightData(
} }
if (flightDataPath.length === 3) { if (flightDataPath.length === 3) {
const subTreeData = cacheNodeSeedData[2] const rsc = cacheNodeSeedData[2]
cache.subTreeData = subTreeData cache.rsc = rsc
fillLazyItemsTillLeafWithHead( fillLazyItemsTillLeafWithHead(
cache, cache,
existingCache, existingCache,
...@@ -29,10 +29,10 @@ export function applyFlightData( ...@@ -29,10 +29,10 @@ export function applyFlightData(
wasPrefetched wasPrefetched
) )
} else { } else {
// Copy subTreeData for the root node of the cache. // Copy rsc for the root node of the cache.
cache.subTreeData = existingCache.subTreeData cache.rsc = existingCache.rsc
cache.parallelRoutes = new Map(existingCache.parallelRoutes) cache.parallelRoutes = new Map(existingCache.parallelRoutes)
// Create a copy of the existing cache with the subTreeData applied. // Create a copy of the existing cache with the rsc applied.
fillCacheWithNewSubTreeData( fillCacheWithNewSubTreeData(
cache, cache,
existingCache, existingCache,
......
...@@ -56,7 +56,7 @@ describe('createInitialRouterState', () => { ...@@ -56,7 +56,7 @@ describe('createInitialRouterState', () => {
const expectedCache: CacheNode = { const expectedCache: CacheNode = {
lazyData: null, lazyData: null,
subTreeData: children, rsc: children,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -72,7 +72,7 @@ describe('createInitialRouterState', () => { ...@@ -72,7 +72,7 @@ describe('createInitialRouterState', () => {
'', '',
{ {
lazyData: null, lazyData: null,
subTreeData: null, rsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
head: <title>Test</title>, head: <title>Test</title>,
}, },
...@@ -81,7 +81,7 @@ describe('createInitialRouterState', () => { ...@@ -81,7 +81,7 @@ describe('createInitialRouterState', () => {
], ],
]), ]),
lazyData: null, lazyData: null,
subTreeData: null, rsc: null,
}, },
], ],
]), ]),
......
...@@ -30,11 +30,11 @@ export function createInitialRouterState({ ...@@ -30,11 +30,11 @@ export function createInitialRouterState({
location, location,
initialHead, initialHead,
}: InitialRouterStateParameters) { }: InitialRouterStateParameters) {
const subTreeData = initialSeedData[2] const rsc = initialSeedData[2]
const cache: CacheNode = { const cache: CacheNode = {
lazyData: null, lazyData: null,
subTreeData: subTreeData, rsc: rsc,
// 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,
} }
......
...@@ -23,12 +23,12 @@ describe('fillCacheWithDataProperty', () => { ...@@ -23,12 +23,12 @@ describe('fillCacheWithDataProperty', () => {
const cache: CacheNode = { const cache: CacheNode = {
lazyData: null, lazyData: null,
subTreeData: null, rsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
} }
const existingCache: CacheNode = { const existingCache: CacheNode = {
lazyData: null, lazyData: null,
subTreeData: <>Root layout</>, rsc: <>Root layout</>,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -37,7 +37,7 @@ describe('fillCacheWithDataProperty', () => { ...@@ -37,7 +37,7 @@ describe('fillCacheWithDataProperty', () => {
'linking', 'linking',
{ {
lazyData: null, lazyData: null,
subTreeData: <>Linking</>, rsc: <>Linking</>,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -46,7 +46,7 @@ describe('fillCacheWithDataProperty', () => { ...@@ -46,7 +46,7 @@ describe('fillCacheWithDataProperty', () => {
'', '',
{ {
lazyData: null, lazyData: null,
subTreeData: <>Page</>, rsc: <>Page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -76,24 +76,24 @@ describe('fillCacheWithDataProperty', () => { ...@@ -76,24 +76,24 @@ describe('fillCacheWithDataProperty', () => {
"" => { "" => {
"lazyData": null, "lazyData": null,
"parallelRoutes": Map {}, "parallelRoutes": Map {},
"subTreeData": <React.Fragment> "rsc": <React.Fragment>
Page Page
</React.Fragment>, </React.Fragment>,
}, },
}, },
}, },
"subTreeData": <React.Fragment> "rsc": <React.Fragment>
Linking Linking
</React.Fragment>, </React.Fragment>,
}, },
"dashboard" => { "dashboard" => {
"lazyData": Promise {}, "lazyData": Promise {},
"parallelRoutes": Map {}, "parallelRoutes": Map {},
"subTreeData": null, "rsc": null,
}, },
}, },
}, },
"subTreeData": null, "rsc": null,
} }
`) `)
}) })
......
...@@ -39,7 +39,7 @@ export function fillCacheWithDataProperty( ...@@ -39,7 +39,7 @@ export function fillCacheWithDataProperty(
) { ) {
childSegmentMap.set(cacheKey, { childSegmentMap.set(cacheKey, {
lazyData: fetchResponse(), lazyData: fetchResponse(),
subTreeData: null, rsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}) })
} }
...@@ -51,7 +51,7 @@ export function fillCacheWithDataProperty( ...@@ -51,7 +51,7 @@ export function fillCacheWithDataProperty(
if (!childCacheNode) { if (!childCacheNode) {
childSegmentMap.set(cacheKey, { childSegmentMap.set(cacheKey, {
lazyData: fetchResponse(), lazyData: fetchResponse(),
subTreeData: null, rsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}) })
} }
...@@ -61,7 +61,7 @@ export function fillCacheWithDataProperty( ...@@ -61,7 +61,7 @@ export function fillCacheWithDataProperty(
if (childCacheNode === existingChildCacheNode) { if (childCacheNode === existingChildCacheNode) {
childCacheNode = { childCacheNode = {
lazyData: childCacheNode.lazyData, lazyData: childCacheNode.lazyData,
subTreeData: childCacheNode.subTreeData, rsc: childCacheNode.rsc,
parallelRoutes: new Map(childCacheNode.parallelRoutes), parallelRoutes: new Map(childCacheNode.parallelRoutes),
} as CacheNode } as CacheNode
childSegmentMap.set(cacheKey, childCacheNode) childSegmentMap.set(cacheKey, childCacheNode)
......
...@@ -25,15 +25,15 @@ const getFlightData = (): FlightData => { ...@@ -25,15 +25,15 @@ const getFlightData = (): FlightData => {
} }
describe('fillCacheWithNewSubtreeData', () => { describe('fillCacheWithNewSubtreeData', () => {
it('should apply subTreeData and head property', () => { it('should apply rsc and head property', () => {
const cache: CacheNode = { const cache: CacheNode = {
lazyData: null, lazyData: null,
subTreeData: null, rsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
} }
const existingCache: CacheNode = { const existingCache: CacheNode = {
lazyData: null, lazyData: null,
subTreeData: <>Root layout</>, rsc: <>Root layout</>,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -42,7 +42,7 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -42,7 +42,7 @@ describe('fillCacheWithNewSubtreeData', () => {
'linking', 'linking',
{ {
lazyData: null, lazyData: null,
subTreeData: <>Linking</>, rsc: <>Linking</>,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -51,7 +51,7 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -51,7 +51,7 @@ describe('fillCacheWithNewSubtreeData', () => {
'', '',
{ {
lazyData: null, lazyData: null,
subTreeData: <>Page</>, rsc: <>Page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -78,7 +78,7 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -78,7 +78,7 @@ describe('fillCacheWithNewSubtreeData', () => {
const expectedCache: CacheNode = { const expectedCache: CacheNode = {
lazyData: null, lazyData: null,
subTreeData: null, rsc: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -87,7 +87,7 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -87,7 +87,7 @@ describe('fillCacheWithNewSubtreeData', () => {
'linking', 'linking',
{ {
lazyData: null, lazyData: null,
subTreeData: <>Linking</>, rsc: <>Linking</>,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -97,7 +97,7 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -97,7 +97,7 @@ describe('fillCacheWithNewSubtreeData', () => {
'', '',
{ {
lazyData: null, lazyData: null,
subTreeData: <>Page</>, rsc: <>Page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -113,7 +113,7 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -113,7 +113,7 @@ describe('fillCacheWithNewSubtreeData', () => {
'', '',
{ {
lazyData: null, lazyData: null,
subTreeData: null, rsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
head: ( head: (
<> <>
...@@ -125,7 +125,7 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -125,7 +125,7 @@ describe('fillCacheWithNewSubtreeData', () => {
]), ]),
], ],
]), ]),
subTreeData: <h1>SubTreeData Injected!</h1>, rsc: <h1>SubTreeData Injected!</h1>,
}, },
], ],
]), ]),
......
...@@ -8,7 +8,7 @@ import { fillLazyItemsTillLeafWithHead } from './fill-lazy-items-till-leaf-with- ...@@ -8,7 +8,7 @@ import { fillLazyItemsTillLeafWithHead } from './fill-lazy-items-till-leaf-with-
import { createRouterCacheKey } from './create-router-cache-key' import { createRouterCacheKey } from './create-router-cache-key'
/** /**
* Fill cache with subTreeData based on flightDataPath * Fill cache with rsc based on flightDataPath
*/ */
export function fillCacheWithNewSubTreeData( export function fillCacheWithNewSubTreeData(
newCache: CacheNode, newCache: CacheNode,
...@@ -46,10 +46,10 @@ export function fillCacheWithNewSubTreeData( ...@@ -46,10 +46,10 @@ export function fillCacheWithNewSubTreeData(
childCacheNode === existingChildCacheNode childCacheNode === existingChildCacheNode
) { ) {
const seedData: CacheNodeSeedData = flightDataPath[3] const seedData: CacheNodeSeedData = flightDataPath[3]
const subTreeData = seedData[2] const rsc = seedData[2]
childCacheNode = { childCacheNode = {
lazyData: null, lazyData: null,
subTreeData, rsc,
// 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)
...@@ -87,7 +87,7 @@ export function fillCacheWithNewSubTreeData( ...@@ -87,7 +87,7 @@ export function fillCacheWithNewSubTreeData(
if (childCacheNode === existingChildCacheNode) { if (childCacheNode === existingChildCacheNode) {
childCacheNode = { childCacheNode = {
lazyData: childCacheNode.lazyData, lazyData: childCacheNode.lazyData,
subTreeData: childCacheNode.subTreeData, rsc: childCacheNode.rsc,
parallelRoutes: new Map(childCacheNode.parallelRoutes), parallelRoutes: new Map(childCacheNode.parallelRoutes),
} as CacheNode } as CacheNode
childSegmentMap.set(cacheKey, childCacheNode) childSegmentMap.set(cacheKey, childCacheNode)
......
...@@ -37,12 +37,12 @@ describe('fillLazyItemsTillLeafWithHead', () => { ...@@ -37,12 +37,12 @@ describe('fillLazyItemsTillLeafWithHead', () => {
it('should fill lazy items till leaf with head', () => { it('should fill lazy items till leaf with head', () => {
const cache: CacheNode = { const cache: CacheNode = {
lazyData: null, lazyData: null,
subTreeData: null, rsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
} }
const existingCache: CacheNode = { const existingCache: CacheNode = {
lazyData: null, lazyData: null,
subTreeData: <>Root layout</>, rsc: <>Root layout</>,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -51,7 +51,7 @@ describe('fillLazyItemsTillLeafWithHead', () => { ...@@ -51,7 +51,7 @@ describe('fillLazyItemsTillLeafWithHead', () => {
'linking', 'linking',
{ {
lazyData: null, lazyData: null,
subTreeData: <>Linking</>, rsc: <>Linking</>,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -60,7 +60,7 @@ describe('fillLazyItemsTillLeafWithHead', () => { ...@@ -60,7 +60,7 @@ describe('fillLazyItemsTillLeafWithHead', () => {
'', '',
{ {
lazyData: null, lazyData: null,
subTreeData: <>Page</>, rsc: <>Page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -93,7 +93,7 @@ describe('fillLazyItemsTillLeafWithHead', () => { ...@@ -93,7 +93,7 @@ describe('fillLazyItemsTillLeafWithHead', () => {
const expectedCache: CacheNode = { const expectedCache: CacheNode = {
lazyData: null, lazyData: null,
subTreeData: null, rsc: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -102,7 +102,7 @@ describe('fillLazyItemsTillLeafWithHead', () => { ...@@ -102,7 +102,7 @@ describe('fillLazyItemsTillLeafWithHead', () => {
'linking', 'linking',
{ {
lazyData: null, lazyData: null,
subTreeData: null, rsc: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -119,7 +119,7 @@ describe('fillLazyItemsTillLeafWithHead', () => { ...@@ -119,7 +119,7 @@ describe('fillLazyItemsTillLeafWithHead', () => {
'', '',
{ {
lazyData: null, lazyData: null,
subTreeData: null, rsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
head: ( head: (
<> <>
...@@ -131,14 +131,14 @@ describe('fillLazyItemsTillLeafWithHead', () => { ...@@ -131,14 +131,14 @@ describe('fillLazyItemsTillLeafWithHead', () => {
]), ]),
], ],
]), ]),
subTreeData: null, rsc: null,
}, },
], ],
[ [
'', '',
{ {
lazyData: null, lazyData: null,
subTreeData: <>Page</>, rsc: <>Page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
......
...@@ -18,7 +18,7 @@ export function fillLazyItemsTillLeafWithHead( ...@@ -18,7 +18,7 @@ export function fillLazyItemsTillLeafWithHead(
newCache.head = head newCache.head = head
return return
} }
// Remove segment that we got data for so that it is filled in during rendering of subTreeData. // Remove segment that we got data for so that it is filled in during rendering of rsc.
for (const key in routerState[1]) { for (const key in routerState[1]) {
const parallelRouteState = routerState[1][key] const parallelRouteState = routerState[1][key]
const segmentForParallelRoute = parallelRouteState[0] const segmentForParallelRoute = parallelRouteState[0]
...@@ -52,7 +52,7 @@ export function fillLazyItemsTillLeafWithHead( ...@@ -52,7 +52,7 @@ export function fillLazyItemsTillLeafWithHead(
const seedNode = parallelSeedData[2] const seedNode = parallelSeedData[2]
newCacheNode = { newCacheNode = {
lazyData: null, lazyData: null,
subTreeData: seedNode, rsc: seedNode,
parallelRoutes: new Map(existingCacheNode?.parallelRoutes), parallelRoutes: new Map(existingCacheNode?.parallelRoutes),
} }
} else if (wasPrefetched && existingCacheNode) { } else if (wasPrefetched && existingCacheNode) {
...@@ -60,7 +60,7 @@ export function fillLazyItemsTillLeafWithHead( ...@@ -60,7 +60,7 @@ export function fillLazyItemsTillLeafWithHead(
// was prefetched, so we should reuse that. // was prefetched, so we should reuse that.
newCacheNode = { newCacheNode = {
lazyData: existingCacheNode.lazyData, lazyData: existingCacheNode.lazyData,
subTreeData: existingCacheNode.subTreeData, rsc: existingCacheNode.rsc,
parallelRoutes: new Map(existingCacheNode.parallelRoutes), parallelRoutes: new Map(existingCacheNode.parallelRoutes),
} as CacheNode } as CacheNode
} else { } else {
...@@ -68,7 +68,7 @@ export function fillLazyItemsTillLeafWithHead( ...@@ -68,7 +68,7 @@ export function fillLazyItemsTillLeafWithHead(
// during render. // during render.
newCacheNode = { newCacheNode = {
lazyData: null, lazyData: null,
subTreeData: null, rsc: null,
parallelRoutes: new Map(existingCacheNode?.parallelRoutes), parallelRoutes: new Map(existingCacheNode?.parallelRoutes),
} }
} }
...@@ -96,7 +96,7 @@ export function fillLazyItemsTillLeafWithHead( ...@@ -96,7 +96,7 @@ export function fillLazyItemsTillLeafWithHead(
const seedNode = parallelSeedData[2] const seedNode = parallelSeedData[2]
newCacheNode = { newCacheNode = {
lazyData: null, lazyData: null,
subTreeData: seedNode, rsc: seedNode,
parallelRoutes: new Map(), parallelRoutes: new Map(),
} }
} else { } else {
...@@ -104,7 +104,7 @@ export function fillLazyItemsTillLeafWithHead( ...@@ -104,7 +104,7 @@ export function fillLazyItemsTillLeafWithHead(
// during render. // during render.
newCacheNode = { newCacheNode = {
lazyData: null, lazyData: null,
subTreeData: null, rsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
} }
} }
......
...@@ -29,12 +29,12 @@ describe('invalidateCacheBelowFlightSegmentPath', () => { ...@@ -29,12 +29,12 @@ describe('invalidateCacheBelowFlightSegmentPath', () => {
it('should invalidate cache below flight segment path', () => { it('should invalidate cache below flight segment path', () => {
const cache: CacheNode = { const cache: CacheNode = {
lazyData: null, lazyData: null,
subTreeData: null, rsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
} }
const existingCache: CacheNode = { const existingCache: CacheNode = {
lazyData: null, lazyData: null,
subTreeData: <>Root layout</>, rsc: <>Root layout</>,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -43,7 +43,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => { ...@@ -43,7 +43,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => {
'linking', 'linking',
{ {
lazyData: null, lazyData: null,
subTreeData: <>Linking</>, rsc: <>Linking</>,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -52,7 +52,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => { ...@@ -52,7 +52,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => {
'', '',
{ {
lazyData: null, lazyData: null,
subTreeData: <>Page</>, rsc: <>Page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -76,9 +76,9 @@ describe('invalidateCacheBelowFlightSegmentPath', () => { ...@@ -76,9 +76,9 @@ describe('invalidateCacheBelowFlightSegmentPath', () => {
const flightDataPath = flightData[0] const flightDataPath = flightData[0]
const flightSegmentPath = flightDataPath.slice(0, -3) const flightSegmentPath = flightDataPath.slice(0, -3)
// Copy subTreeData for the root node of the cache. // Copy rsc for the root node of the cache.
cache.subTreeData = existingCache.subTreeData cache.rsc = existingCache.rsc
// Create a copy of the existing cache with the subTreeData applied. // Create a copy of the existing cache with the rsc applied.
fillCacheWithNewSubTreeData(cache, existingCache, flightDataPath, false) fillCacheWithNewSubTreeData(cache, existingCache, flightDataPath, false)
// Invalidate the cache below the flight segment path. This should remove the 'about' node. // Invalidate the cache below the flight segment path. This should remove the 'about' node.
...@@ -107,19 +107,19 @@ describe('invalidateCacheBelowFlightSegmentPath', () => { ...@@ -107,19 +107,19 @@ describe('invalidateCacheBelowFlightSegmentPath', () => {
{ {
lazyData: null, lazyData: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
subTreeData: <React.Fragment>Page</React.Fragment>, rsc: <React.Fragment>Page</React.Fragment>,
}, },
], ],
]), ]),
], ],
]), ]),
subTreeData: <React.Fragment>Linking</React.Fragment>, rsc: <React.Fragment>Linking</React.Fragment>,
}, },
], ],
]), ]),
], ],
]), ]),
subTreeData: <>Root layout</>, rsc: <>Root layout</>,
} }
expect(cache).toMatchObject(expectedCache) expect(cache).toMatchObject(expectedCache)
......
...@@ -48,7 +48,7 @@ export function invalidateCacheBelowFlightSegmentPath( ...@@ -48,7 +48,7 @@ export function invalidateCacheBelowFlightSegmentPath(
if (childCacheNode === existingChildCacheNode) { if (childCacheNode === existingChildCacheNode) {
childCacheNode = { childCacheNode = {
lazyData: childCacheNode.lazyData, lazyData: childCacheNode.lazyData,
subTreeData: childCacheNode.subTreeData, rsc: childCacheNode.rsc,
parallelRoutes: new Map(childCacheNode.parallelRoutes), parallelRoutes: new Map(childCacheNode.parallelRoutes),
} as CacheNode } as CacheNode
childSegmentMap.set(cacheKey, childCacheNode) childSegmentMap.set(cacheKey, childCacheNode)
......
...@@ -7,12 +7,12 @@ describe('invalidateCacheByRouterState', () => { ...@@ -7,12 +7,12 @@ describe('invalidateCacheByRouterState', () => {
it('should invalidate the cache by router state', () => { it('should invalidate the cache by router state', () => {
const cache: CacheNode = { const cache: CacheNode = {
lazyData: null, lazyData: null,
subTreeData: null, rsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
} }
const existingCache: CacheNode = { const existingCache: CacheNode = {
lazyData: null, lazyData: null,
subTreeData: <>Root layout</>, rsc: <>Root layout</>,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -21,7 +21,7 @@ describe('invalidateCacheByRouterState', () => { ...@@ -21,7 +21,7 @@ describe('invalidateCacheByRouterState', () => {
'linking', 'linking',
{ {
lazyData: null, lazyData: null,
subTreeData: <>Linking</>, rsc: <>Linking</>,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -30,7 +30,7 @@ describe('invalidateCacheByRouterState', () => { ...@@ -30,7 +30,7 @@ describe('invalidateCacheByRouterState', () => {
'', '',
{ {
lazyData: null, lazyData: null,
subTreeData: <>Page</>, rsc: <>Page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -68,7 +68,7 @@ describe('invalidateCacheByRouterState', () => { ...@@ -68,7 +68,7 @@ describe('invalidateCacheByRouterState', () => {
const expectedCache: CacheNode = { const expectedCache: CacheNode = {
lazyData: null, lazyData: null,
subTreeData: null, rsc: null,
parallelRoutes: new Map([['children', new Map()]]), parallelRoutes: new Map([['children', new Map()]]),
} }
......
...@@ -10,7 +10,7 @@ export function invalidateCacheByRouterState( ...@@ -10,7 +10,7 @@ export function invalidateCacheByRouterState(
existingCache: CacheNode, existingCache: CacheNode,
routerState: FlightRouterState routerState: FlightRouterState
): void { ): void {
// Remove segment that we got data for so that it is filled in during rendering of subTreeData. // Remove segment that we got data for so that it is filled in during rendering of rsc.
for (const key in routerState[1]) { for (const key in routerState[1]) {
const segmentForParallelRoute = routerState[1][key][0] const segmentForParallelRoute = routerState[1][key][0]
const cacheKey = createRouterCacheKey(segmentForParallelRoute) const cacheKey = createRouterCacheKey(segmentForParallelRoute)
......
...@@ -61,7 +61,7 @@ function fastRefreshReducerImpl( ...@@ -61,7 +61,7 @@ function fastRefreshReducerImpl(
return state return state
} }
// Given the path can only have two items the items are only the router state and subTreeData for the root. // Given the path can only have two items the items are only the router state and rsc for the root.
const [treePatch] = flightDataPath const [treePatch] = flightDataPath
const newTree = applyRouterStatePatchToTree( const newTree = applyRouterStatePatchToTree(
// TODO-APP: remove '' // TODO-APP: remove ''
......
...@@ -27,7 +27,7 @@ describe('findHeadInCache', () => { ...@@ -27,7 +27,7 @@ describe('findHeadInCache', () => {
const cache: CacheNode = { const cache: CacheNode = {
lazyData: null, lazyData: null,
subTreeData: null, rsc: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -36,7 +36,7 @@ describe('findHeadInCache', () => { ...@@ -36,7 +36,7 @@ describe('findHeadInCache', () => {
'linking', 'linking',
{ {
lazyData: null, lazyData: null,
subTreeData: null, rsc: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -53,7 +53,7 @@ describe('findHeadInCache', () => { ...@@ -53,7 +53,7 @@ describe('findHeadInCache', () => {
'', '',
{ {
lazyData: null, lazyData: null,
subTreeData: null, rsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
head: ( head: (
<> <>
...@@ -65,7 +65,7 @@ describe('findHeadInCache', () => { ...@@ -65,7 +65,7 @@ describe('findHeadInCache', () => {
]), ]),
], ],
]), ]),
subTreeData: null, rsc: 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
...@@ -73,7 +73,7 @@ describe('findHeadInCache', () => { ...@@ -73,7 +73,7 @@ describe('findHeadInCache', () => {
// '', // '',
// { // {
// lazyData: null, // lazyData: null,
// subTreeData: <>Page</>, // rsc: <>Page</>,
// parallelRoutes: new Map(), // parallelRoutes: new Map(),
// }, // },
// ], // ],
......
...@@ -77,7 +77,7 @@ function addRefetchToLeafSegments( ...@@ -77,7 +77,7 @@ function addRefetchToLeafSegments(
) { ) {
let appliedPatch = false let appliedPatch = false
newCache.subTreeData = currentCache.subTreeData newCache.rsc = currentCache.rsc
newCache.parallelRoutes = new Map(currentCache.parallelRoutes) newCache.parallelRoutes = new Map(currentCache.parallelRoutes)
const segmentPathsToFill = generateSegmentsFromPatch(treePatch).map( const segmentPathsToFill = generateSegmentsFromPatch(treePatch).map(
...@@ -237,8 +237,8 @@ export function navigateReducer( ...@@ -237,8 +237,8 @@ export function navigateReducer(
) )
if (hardNavigate) { if (hardNavigate) {
// Copy subTreeData for the root node of the cache. // Copy rsc for the root node of the cache.
cache.subTreeData = currentCache.subTreeData cache.rsc = currentCache.rsc
invalidateCacheBelowFlightSegmentPath( invalidateCacheBelowFlightSegmentPath(
cache, cache,
......
...@@ -94,7 +94,7 @@ describe('prefetchReducer', () => { ...@@ -94,7 +94,7 @@ describe('prefetchReducer', () => {
'', '',
{ {
lazyData: null, lazyData: null,
subTreeData: <>Linking page</>, rsc: <>Linking page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -102,7 +102,7 @@ describe('prefetchReducer', () => { ...@@ -102,7 +102,7 @@ describe('prefetchReducer', () => {
], ],
]), ]),
lazyData: null, lazyData: null,
subTreeData: <>Linking layout level</>, rsc: <>Linking layout level</>,
}, },
], ],
]), ]),
...@@ -181,7 +181,7 @@ describe('prefetchReducer', () => { ...@@ -181,7 +181,7 @@ describe('prefetchReducer', () => {
canonicalUrl: '/linking', canonicalUrl: '/linking',
cache: { cache: {
lazyData: null, lazyData: null,
subTreeData: ( rsc: (
<html> <html>
<head></head> <head></head>
<body>Root layout</body> <body>Root layout</body>
...@@ -233,7 +233,7 @@ describe('prefetchReducer', () => { ...@@ -233,7 +233,7 @@ describe('prefetchReducer', () => {
'', '',
{ {
lazyData: null, lazyData: null,
subTreeData: <>Linking page</>, rsc: <>Linking page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -241,7 +241,7 @@ describe('prefetchReducer', () => { ...@@ -241,7 +241,7 @@ describe('prefetchReducer', () => {
], ],
]), ]),
lazyData: null, lazyData: null,
subTreeData: <>Linking layout level</>, rsc: <>Linking layout level</>,
}, },
], ],
]), ]),
...@@ -334,7 +334,7 @@ describe('prefetchReducer', () => { ...@@ -334,7 +334,7 @@ describe('prefetchReducer', () => {
canonicalUrl: '/linking', canonicalUrl: '/linking',
cache: { cache: {
lazyData: null, lazyData: null,
subTreeData: ( rsc: (
<html> <html>
<head></head> <head></head>
<body>Root layout</body> <body>Root layout</body>
......
...@@ -105,7 +105,7 @@ describe('refreshReducer', () => { ...@@ -105,7 +105,7 @@ describe('refreshReducer', () => {
'', '',
{ {
lazyData: null, lazyData: null,
subTreeData: <>Linking page</>, rsc: <>Linking page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -113,7 +113,7 @@ describe('refreshReducer', () => { ...@@ -113,7 +113,7 @@ describe('refreshReducer', () => {
], ],
]), ]),
lazyData: null, lazyData: null,
subTreeData: <>Linking layout level</>, rsc: <>Linking layout level</>,
}, },
], ],
]), ]),
...@@ -157,7 +157,7 @@ describe('refreshReducer', () => { ...@@ -157,7 +157,7 @@ describe('refreshReducer', () => {
nextUrl: '/linking', nextUrl: '/linking',
cache: { cache: {
lazyData: null, lazyData: null,
subTreeData: ( rsc: (
<html> <html>
<head></head> <head></head>
<body> <body>
...@@ -180,7 +180,7 @@ describe('refreshReducer', () => { ...@@ -180,7 +180,7 @@ describe('refreshReducer', () => {
'', '',
{ {
lazyData: null, lazyData: null,
subTreeData: null, rsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
head: ( head: (
<> <>
...@@ -193,7 +193,7 @@ describe('refreshReducer', () => { ...@@ -193,7 +193,7 @@ describe('refreshReducer', () => {
], ],
]), ]),
lazyData: null, lazyData: null,
subTreeData: null, rsc: null,
}, },
], ],
]), ]),
...@@ -243,7 +243,7 @@ describe('refreshReducer', () => { ...@@ -243,7 +243,7 @@ describe('refreshReducer', () => {
'', '',
{ {
lazyData: null, lazyData: null,
subTreeData: <>Linking page</>, rsc: <>Linking page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -251,7 +251,7 @@ describe('refreshReducer', () => { ...@@ -251,7 +251,7 @@ describe('refreshReducer', () => {
], ],
]), ]),
lazyData: null, lazyData: null,
subTreeData: <>Linking layout level</>, rsc: <>Linking layout level</>,
}, },
], ],
]), ]),
...@@ -309,7 +309,7 @@ describe('refreshReducer', () => { ...@@ -309,7 +309,7 @@ describe('refreshReducer', () => {
nextUrl: '/linking', nextUrl: '/linking',
cache: { cache: {
lazyData: null, lazyData: null,
subTreeData: ( rsc: (
<html> <html>
<head></head> <head></head>
<body> <body>
...@@ -332,7 +332,7 @@ describe('refreshReducer', () => { ...@@ -332,7 +332,7 @@ describe('refreshReducer', () => {
'', '',
{ {
lazyData: null, lazyData: null,
subTreeData: null, rsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
head: ( head: (
<> <>
...@@ -345,7 +345,7 @@ describe('refreshReducer', () => { ...@@ -345,7 +345,7 @@ describe('refreshReducer', () => {
], ],
]), ]),
lazyData: null, lazyData: null,
subTreeData: null, rsc: null,
}, },
], ],
]), ]),
...@@ -395,7 +395,7 @@ describe('refreshReducer', () => { ...@@ -395,7 +395,7 @@ describe('refreshReducer', () => {
'', '',
{ {
lazyData: null, lazyData: null,
subTreeData: <>Linking page</>, rsc: <>Linking page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -403,7 +403,7 @@ describe('refreshReducer', () => { ...@@ -403,7 +403,7 @@ describe('refreshReducer', () => {
], ],
]), ]),
lazyData: null, lazyData: null,
subTreeData: <>Linking layout level</>, rsc: <>Linking layout level</>,
}, },
], ],
[ [
...@@ -417,7 +417,7 @@ describe('refreshReducer', () => { ...@@ -417,7 +417,7 @@ describe('refreshReducer', () => {
'', '',
{ {
lazyData: null, lazyData: null,
subTreeData: <>About page</>, rsc: <>About page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -425,7 +425,7 @@ describe('refreshReducer', () => { ...@@ -425,7 +425,7 @@ describe('refreshReducer', () => {
], ],
]), ]),
lazyData: null, lazyData: null,
subTreeData: <>About layout level</>, rsc: <>About layout level</>,
}, },
], ],
]), ]),
...@@ -483,7 +483,7 @@ describe('refreshReducer', () => { ...@@ -483,7 +483,7 @@ describe('refreshReducer', () => {
nextUrl: '/linking', nextUrl: '/linking',
cache: { cache: {
lazyData: null, lazyData: null,
subTreeData: ( rsc: (
<html> <html>
<head></head> <head></head>
<body> <body>
...@@ -506,7 +506,7 @@ describe('refreshReducer', () => { ...@@ -506,7 +506,7 @@ describe('refreshReducer', () => {
'', '',
{ {
lazyData: null, lazyData: null,
subTreeData: null, rsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
head: ( head: (
<> <>
...@@ -519,7 +519,7 @@ describe('refreshReducer', () => { ...@@ -519,7 +519,7 @@ describe('refreshReducer', () => {
], ],
]), ]),
lazyData: null, lazyData: null,
subTreeData: null, rsc: null,
}, },
], ],
]), ]),
...@@ -569,7 +569,7 @@ describe('refreshReducer', () => { ...@@ -569,7 +569,7 @@ describe('refreshReducer', () => {
'', '',
{ {
lazyData: null, lazyData: null,
subTreeData: <>Linking page</>, rsc: <>Linking page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -577,7 +577,7 @@ describe('refreshReducer', () => { ...@@ -577,7 +577,7 @@ describe('refreshReducer', () => {
], ],
]), ]),
lazyData: null, lazyData: null,
subTreeData: <>Linking layout level</>, rsc: <>Linking layout level</>,
}, },
], ],
[ [
...@@ -591,7 +591,7 @@ describe('refreshReducer', () => { ...@@ -591,7 +591,7 @@ describe('refreshReducer', () => {
'', '',
{ {
lazyData: null, lazyData: null,
subTreeData: <>About page</>, rsc: <>About page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -599,7 +599,7 @@ describe('refreshReducer', () => { ...@@ -599,7 +599,7 @@ describe('refreshReducer', () => {
], ],
]), ]),
lazyData: null, lazyData: null,
subTreeData: <>About layout level</>, rsc: <>About layout level</>,
}, },
], ],
]), ]),
...@@ -706,7 +706,7 @@ describe('refreshReducer', () => { ...@@ -706,7 +706,7 @@ describe('refreshReducer', () => {
nextUrl: '/linking', nextUrl: '/linking',
cache: { cache: {
lazyData: null, lazyData: null,
subTreeData: ( rsc: (
<html> <html>
<head></head> <head></head>
<body> <body>
...@@ -729,7 +729,7 @@ describe('refreshReducer', () => { ...@@ -729,7 +729,7 @@ describe('refreshReducer', () => {
'', '',
{ {
lazyData: null, lazyData: null,
subTreeData: null, rsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
head: ( head: (
<> <>
...@@ -742,7 +742,7 @@ describe('refreshReducer', () => { ...@@ -742,7 +742,7 @@ describe('refreshReducer', () => {
], ],
]), ]),
lazyData: null, lazyData: null,
subTreeData: null, rsc: null,
}, },
], ],
]), ]),
......
...@@ -59,7 +59,7 @@ export function refreshReducer( ...@@ -59,7 +59,7 @@ export function refreshReducer(
return state return state
} }
// Given the path can only have two items the items are only the router state and subTreeData for the root. // Given the path can only have two items the items are only the router state and rsc for the root.
const [treePatch] = flightDataPath const [treePatch] = flightDataPath
const newTree = applyRouterStatePatchToTree( const newTree = applyRouterStatePatchToTree(
// TODO-APP: remove '' // TODO-APP: remove ''
...@@ -94,8 +94,8 @@ export function refreshReducer( ...@@ -94,8 +94,8 @@ export function refreshReducer(
// Handles case where prefetch only returns the router tree patch without rendered components. // Handles case where prefetch only returns the router tree patch without rendered components.
if (cacheNodeSeedData !== null) { if (cacheNodeSeedData !== null) {
const subTreeData = cacheNodeSeedData[2] const rsc = cacheNodeSeedData[2]
cache.subTreeData = subTreeData cache.rsc = rsc
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.
......
...@@ -61,7 +61,7 @@ describe('serverPatchReducer', () => { ...@@ -61,7 +61,7 @@ describe('serverPatchReducer', () => {
'', '',
{ {
lazyData: null, lazyData: null,
subTreeData: <>Linking page</>, rsc: <>Linking page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -69,7 +69,7 @@ describe('serverPatchReducer', () => { ...@@ -69,7 +69,7 @@ describe('serverPatchReducer', () => {
], ],
]), ]),
lazyData: null, lazyData: null,
subTreeData: <>Linking layout level</>, rsc: <>Linking layout level</>,
}, },
], ],
]), ]),
...@@ -132,7 +132,7 @@ describe('serverPatchReducer', () => { ...@@ -132,7 +132,7 @@ describe('serverPatchReducer', () => {
nextUrl: '/linking/about', nextUrl: '/linking/about',
cache: { cache: {
lazyData: null, lazyData: null,
subTreeData: ( rsc: (
<html> <html>
<head></head> <head></head>
<body>Root layout</body> <body>Root layout</body>
...@@ -153,7 +153,7 @@ describe('serverPatchReducer', () => { ...@@ -153,7 +153,7 @@ describe('serverPatchReducer', () => {
'', '',
{ {
lazyData: null, lazyData: null,
subTreeData: <>Linking page</>, rsc: <>Linking page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -161,7 +161,7 @@ describe('serverPatchReducer', () => { ...@@ -161,7 +161,7 @@ describe('serverPatchReducer', () => {
], ],
]), ]),
lazyData: null, lazyData: null,
subTreeData: <>Linking layout level</>, rsc: <>Linking layout level</>,
}, },
], ],
]), ]),
...@@ -211,7 +211,7 @@ describe('serverPatchReducer', () => { ...@@ -211,7 +211,7 @@ describe('serverPatchReducer', () => {
'', '',
{ {
lazyData: null, lazyData: null,
subTreeData: <>Linking page</>, rsc: <>Linking page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -219,7 +219,7 @@ describe('serverPatchReducer', () => { ...@@ -219,7 +219,7 @@ describe('serverPatchReducer', () => {
], ],
]), ]),
lazyData: null, lazyData: null,
subTreeData: <>Linking layout level</>, rsc: <>Linking layout level</>,
}, },
], ],
]), ]),
...@@ -295,7 +295,7 @@ describe('serverPatchReducer', () => { ...@@ -295,7 +295,7 @@ describe('serverPatchReducer', () => {
nextUrl: '/linking/about', nextUrl: '/linking/about',
cache: { cache: {
lazyData: null, lazyData: null,
subTreeData: ( rsc: (
<html> <html>
<head></head> <head></head>
<body>Root layout</body> <body>Root layout</body>
...@@ -316,7 +316,7 @@ describe('serverPatchReducer', () => { ...@@ -316,7 +316,7 @@ describe('serverPatchReducer', () => {
'', '',
{ {
lazyData: null, lazyData: null,
subTreeData: <>Linking page</>, rsc: <>Linking page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -324,7 +324,7 @@ describe('serverPatchReducer', () => { ...@@ -324,7 +324,7 @@ describe('serverPatchReducer', () => {
], ],
]), ]),
lazyData: null, lazyData: null,
subTreeData: <>Linking layout level</>, rsc: <>Linking layout level</>,
}, },
], ],
]), ]),
......
...@@ -214,7 +214,7 @@ export function serverActionReducer( ...@@ -214,7 +214,7 @@ export function serverActionReducer(
return state return state
} }
// Given the path can only have two items the items are only the router state and subTreeData for the root. // Given the path can only have two items the items are only the router state and rsc for the root.
const [treePatch] = flightDataPath const [treePatch] = flightDataPath
const newTree = applyRouterStatePatchToTree( const newTree = applyRouterStatePatchToTree(
// TODO-APP: remove '' // TODO-APP: remove ''
...@@ -238,13 +238,12 @@ export function serverActionReducer( ...@@ -238,13 +238,12 @@ export function serverActionReducer(
// The one before last item is the router state tree patch // The one before last item is the router state tree patch
const [cacheNodeSeedData, head] = flightDataPath.slice(-2) const [cacheNodeSeedData, head] = flightDataPath.slice(-2)
const subTreeData = const rsc = cacheNodeSeedData !== null ? cacheNodeSeedData[2] : null
cacheNodeSeedData !== null ? cacheNodeSeedData[2] : null
// Handles case where prefetch only returns the router tree patch without rendered components. // Handles case where prefetch only returns the router tree patch without rendered components.
if (subTreeData !== null) { if (rsc !== null) {
const cache: CacheNode = createEmptyCacheNode() const cache: CacheNode = createEmptyCacheNode()
cache.subTreeData = subTreeData cache.rsc = rsc
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.
......
...@@ -112,7 +112,7 @@ describe('serverPatchReducer', () => { ...@@ -112,7 +112,7 @@ describe('serverPatchReducer', () => {
'', '',
{ {
lazyData: null, lazyData: null,
subTreeData: <>Linking page</>, rsc: <>Linking page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -120,7 +120,7 @@ describe('serverPatchReducer', () => { ...@@ -120,7 +120,7 @@ describe('serverPatchReducer', () => {
], ],
]), ]),
lazyData: null, lazyData: null,
subTreeData: <>Linking layout level</>, rsc: <>Linking layout level</>,
}, },
], ],
]), ]),
...@@ -173,7 +173,7 @@ describe('serverPatchReducer', () => { ...@@ -173,7 +173,7 @@ describe('serverPatchReducer', () => {
"" => { "" => {
"lazyData": null, "lazyData": null,
"parallelRoutes": Map {}, "parallelRoutes": Map {},
"subTreeData": <React.Fragment> "rsc": <React.Fragment>
Linking page Linking page
</React.Fragment>, </React.Fragment>,
}, },
...@@ -189,23 +189,23 @@ describe('serverPatchReducer', () => { ...@@ -189,23 +189,23 @@ describe('serverPatchReducer', () => {
</React.Fragment>, </React.Fragment>,
"lazyData": null, "lazyData": null,
"parallelRoutes": Map {}, "parallelRoutes": Map {},
"subTreeData": null, "rsc": null,
}, },
}, },
}, },
"subTreeData": <h1> "rsc": <h1>
Somewhere Page! Somewhere Page!
</h1>, </h1>,
}, },
}, },
}, },
"subTreeData": <React.Fragment> "rsc": <React.Fragment>
Linking layout level Linking layout level
</React.Fragment>, </React.Fragment>,
}, },
}, },
}, },
"subTreeData": <html> "rsc": <html>
<head /> <head />
<body> <body>
Root layout Root layout
...@@ -276,7 +276,7 @@ describe('serverPatchReducer', () => { ...@@ -276,7 +276,7 @@ describe('serverPatchReducer', () => {
'', '',
{ {
lazyData: null, lazyData: null,
subTreeData: <>Linking page</>, rsc: <>Linking page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
], ],
...@@ -284,7 +284,7 @@ describe('serverPatchReducer', () => { ...@@ -284,7 +284,7 @@ describe('serverPatchReducer', () => {
], ],
]), ]),
lazyData: null, lazyData: null,
subTreeData: <>Linking layout level</>, rsc: <>Linking layout level</>,
}, },
], ],
]), ]),
...@@ -349,7 +349,7 @@ describe('serverPatchReducer', () => { ...@@ -349,7 +349,7 @@ describe('serverPatchReducer', () => {
"" => { "" => {
"lazyData": null, "lazyData": null,
"parallelRoutes": Map {}, "parallelRoutes": Map {},
"subTreeData": <React.Fragment> "rsc": <React.Fragment>
Linking page Linking page
</React.Fragment>, </React.Fragment>,
}, },
...@@ -365,11 +365,11 @@ describe('serverPatchReducer', () => { ...@@ -365,11 +365,11 @@ describe('serverPatchReducer', () => {
</React.Fragment>, </React.Fragment>,
"lazyData": null, "lazyData": null,
"parallelRoutes": Map {}, "parallelRoutes": Map {},
"subTreeData": null, "rsc": null,
}, },
}, },
}, },
"subTreeData": <h1> "rsc": <h1>
About Page! About Page!
</h1>, </h1>,
}, },
...@@ -385,23 +385,23 @@ describe('serverPatchReducer', () => { ...@@ -385,23 +385,23 @@ describe('serverPatchReducer', () => {
</React.Fragment>, </React.Fragment>,
"lazyData": null, "lazyData": null,
"parallelRoutes": Map {}, "parallelRoutes": Map {},
"subTreeData": null, "rsc": null,
}, },
}, },
}, },
"subTreeData": <h1> "rsc": <h1>
Somewhere Page! Somewhere Page!
</h1>, </h1>,
}, },
}, },
}, },
"subTreeData": <React.Fragment> "rsc": <React.Fragment>
Linking layout level Linking layout level
</React.Fragment>, </React.Fragment>,
}, },
}, },
}, },
"subTreeData": <html> "rsc": <html>
<head /> <head />
<body> <body>
Root layout Root layout
......
...@@ -46,7 +46,7 @@ export interface ServerActionMutable extends Mutable { ...@@ -46,7 +46,7 @@ export interface ServerActionMutable extends Mutable {
/** /**
* Refresh triggers a refresh of the full page data. * Refresh triggers a refresh of the full page data.
* - fetches the Flight data and fills subTreeData at the root of the cache. * - fetches the Flight data and fills rsc at the root of the cache.
* - The router state is updated at the root. * - The router state is updated at the root.
*/ */
export interface RefreshAction { export interface RefreshAction {
......
...@@ -20,7 +20,7 @@ export type CacheNode = ReadyCacheNode | LazyCacheNode ...@@ -20,7 +20,7 @@ export type CacheNode = ReadyCacheNode | LazyCacheNode
export type LazyCacheNode = { export type LazyCacheNode = {
/** /**
* When subtreeData is null, this is a lazily-initialized cache node. * When rsc is null, this is a lazily-initialized cache node.
* *
* If the app attempts to render it, it triggers a lazy data fetch, * If the app attempts to render it, it triggers a lazy data fetch,
* postpones the render, and schedules an update to a new tree. * postpones the render, and schedules an update to a new tree.
...@@ -29,7 +29,10 @@ export type LazyCacheNode = { ...@@ -29,7 +29,10 @@ export type LazyCacheNode = {
* currently is in some cases until we've implemented partial * currently is in some cases until we've implemented partial
* segment fetching. * segment fetching.
*/ */
subTreeData: null rsc: null
// TODO: Add prefetchRsc field.
// prefetchRsc: null
/** /**
* 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
...@@ -46,7 +49,7 @@ export type LazyCacheNode = { ...@@ -46,7 +49,7 @@ export type LazyCacheNode = {
export type ReadyCacheNode = { export type ReadyCacheNode = {
/** /**
* When subtreeData is not null, it represents the RSC data for the * When rsc is not null, it represents the RSC data for the
* corresponding segment. * corresponding segment.
* *
* `null` is a valid React Node but because segment data is always a * `null` is a valid React Node but because segment data is always a
...@@ -54,9 +57,13 @@ export type ReadyCacheNode = { ...@@ -54,9 +57,13 @@ export type ReadyCacheNode = {
* *
* TODO: For additional type safety, update this type to * TODO: For additional type safety, update this type to
* Exclude<React.ReactNode, null>. Need to update createEmptyCacheNode to * Exclude<React.ReactNode, null>. Need to update createEmptyCacheNode to
* accept subTreeData as an argument, or just inline the callers. * accept rsc as an argument, or just inline the callers.
*/ */
subTreeData: React.ReactNode rsc: React.ReactNode
// TODO: Add prefetchRsc field.
// 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.
*/ */
......
...@@ -224,7 +224,7 @@ ...@@ -224,7 +224,7 @@
}, },
"packages/next/src/client/components/router-reducer/fill-cache-with-new-subtree-data.test.tsx": { "packages/next/src/client/components/router-reducer/fill-cache-with-new-subtree-data.test.tsx": {
"passed": [ "passed": [
"fillCacheWithNewSubtreeData should apply subTreeData and head property" "fillCacheWithNewSubtreeData should apply rsc and head property"
], ],
"failed": [], "failed": [],
"pending": [], "pending": [],
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