Unverified Commit c964e9a4 authored by Andrew Clark's avatar Andrew Clark Committed by GitHub

Make CacheNodeSeedData match FlightRouterState more closely (#59590)

When PPR is enabled, the CacheNodeSeedData and FlightRouterState
contained in an RSC payload (whether it's static or dynamic) should
always have the same tree structure.

The only reason the two trees would ever be different is if the server
partially renders with `loading.tsx`, but that behavior doesn't exist
when PPR is enabled. (In that case, the CacheNodeSeedData would describe
only a subset of FlightRouterState.)

The behavior is already correct but to make the types a bit closer, this
changes the `parallelRoutes` slot of CacheNodeSeedData to be
non-nullable; if there are no children, it should be an empty object.

It's not semantically important, I'm only changing it to make the types
more consistent, since we typically traverse both trees in parallel.

Eventually we will probably merge these into a single transport type.

Closes NEXT-1868
parent 79e82d42
......@@ -33,7 +33,7 @@ const getFlightData = (): FlightData => {
children: ['', {}],
},
],
['about', null, <h1>About Page!</h1>],
['about', {}, <h1>About Page!</h1>],
<>
<title>About page!</title>
</>,
......
......@@ -36,7 +36,7 @@ describe('createInitialRouterState', () => {
buildId,
initialTree,
initialCanonicalUrl,
initialSeedData: ['', null, children],
initialSeedData: ['', {}, children],
initialParallelRoutes,
isServer: false,
location: new URL('/linking', 'https://localhost') as any,
......@@ -47,7 +47,7 @@ describe('createInitialRouterState', () => {
buildId,
initialTree,
initialCanonicalUrl,
initialSeedData: ['', null, children],
initialSeedData: ['', {}, children],
initialParallelRoutes,
isServer: false,
location: new URL('/linking', 'https://localhost') as any,
......
......@@ -16,7 +16,7 @@ const getFlightData = (): FlightData => {
children: ['', {}],
},
],
['about', null, <h1>SubTreeData Injected!</h1>],
['about', {}, <h1>SubTreeData Injected!</h1>],
<>
<title>Head Injected!</title>
</>,
......
......@@ -25,7 +25,7 @@ const getFlightData = (): FlightData => {
null,
true,
],
['', null, <h1>About Page!</h1>],
['', {}, <h1>About Page!</h1>],
<>
<title>About page!</title>
</>,
......
......@@ -35,9 +35,7 @@ export function fillLazyItemsTillLeafWithHead(
// in the response format, so that we don't have to send the keys twice.
// Then the client can convert them into separate representations.
const parallelSeedData =
cacheNodeSeedData !== null &&
cacheNodeSeedData[1] !== null &&
cacheNodeSeedData[1][key] !== undefined
cacheNodeSeedData !== null && cacheNodeSeedData[1][key] !== undefined
? cacheNodeSeedData[1][key]
: null
if (existingCache) {
......
......@@ -17,7 +17,7 @@ const getFlightData = (): FlightData => {
children: ['', {}],
},
],
['about', null, <h1>About Page!</h1>],
['about', {}, <h1>About Page!</h1>],
<>
<title>About page!</title>
</>,
......
......@@ -28,7 +28,7 @@ const flightData: FlightData = [
children: ['__PAGE__', {}],
},
],
['about', null, <h1>About Page!</h1>],
['about', {}, <h1>About Page!</h1>],
<>
<title>About page!</title>
</>,
......@@ -58,7 +58,7 @@ const demographicsFlightData: FlightData = [
],
[
'',
null,
{},
<html>
<head></head>
<body>Root layout from response</body>
......@@ -162,7 +162,7 @@ describe('navigateReducer', () => {
initialTree,
initialHead: null,
initialCanonicalUrl,
initialSeedData: ['', null, children],
initialSeedData: ['', {}, children],
initialParallelRoutes,
isServer: false,
location: new URL('/linking', 'https://localhost') as any,
......@@ -355,7 +355,7 @@ describe('navigateReducer', () => {
initialTree,
initialHead: null,
initialCanonicalUrl,
initialSeedData: ['', null, children],
initialSeedData: ['', {}, children],
initialParallelRoutes,
isServer: false,
location: new URL('/linking', 'https://localhost') as any,
......@@ -549,7 +549,7 @@ describe('navigateReducer', () => {
initialTree,
initialHead: null,
initialCanonicalUrl,
initialSeedData: ['', null, children],
initialSeedData: ['', {}, children],
initialParallelRoutes,
isServer: false,
location: new URL('/linking', 'https://localhost') as any,
......@@ -686,7 +686,7 @@ describe('navigateReducer', () => {
initialTree,
initialHead: null,
initialCanonicalUrl,
initialSeedData: ['', null, children],
initialSeedData: ['', {}, children],
initialParallelRoutes,
isServer: false,
location: new URL('/linking', 'https://localhost') as any,
......@@ -823,7 +823,7 @@ describe('navigateReducer', () => {
initialTree,
initialHead: null,
initialCanonicalUrl,
initialSeedData: ['', null, children],
initialSeedData: ['', {}, children],
initialParallelRoutes,
isServer: false,
location: new URL('/linking#hash', 'https://localhost') as any,
......@@ -988,7 +988,7 @@ describe('navigateReducer', () => {
initialTree,
initialHead: null,
initialCanonicalUrl,
initialSeedData: ['', null, children],
initialSeedData: ['', {}, children],
initialParallelRoutes,
isServer: false,
location: new URL('/linking', 'https://localhost') as any,
......@@ -1256,7 +1256,7 @@ describe('navigateReducer', () => {
initialTree,
initialHead: null,
initialCanonicalUrl,
initialSeedData: ['', null, children],
initialSeedData: ['', {}, children],
initialParallelRoutes,
isServer: false,
location: new URL('/parallel-tab-bar', 'https://localhost') as any,
......@@ -1482,7 +1482,7 @@ describe('navigateReducer', () => {
initialTree,
initialHead: null,
initialCanonicalUrl,
initialSeedData: ['', null, children],
initialSeedData: ['', {}, children],
initialParallelRoutes,
isServer: false,
location: new URL('/linking#hash', 'https://localhost') as any,
......@@ -1616,7 +1616,7 @@ describe('navigateReducer', () => {
initialTree,
initialHead: null,
initialCanonicalUrl,
initialSeedData: ['', null, children],
initialSeedData: ['', {}, children],
initialParallelRoutes,
isServer: false,
location: new URL('/linking', 'https://localhost') as any,
......
......@@ -22,7 +22,7 @@ jest.mock('../fetch-server-response', () => {
children: ['', {}],
},
],
['about', null, <h1>About Page!</h1>],
['about', {}, <h1>About Page!</h1>],
<>
<title>About page!</title>
</>,
......@@ -116,7 +116,7 @@ describe('prefetchReducer', () => {
initialTree,
initialHead: null,
initialCanonicalUrl,
initialSeedData: ['', null, children],
initialSeedData: ['', {}, children],
initialParallelRoutes,
isServer: false,
location: new URL('/linking', 'https://localhost') as any,
......@@ -258,7 +258,7 @@ describe('prefetchReducer', () => {
initialTree,
initialHead: null,
initialCanonicalUrl,
initialSeedData: ['', null, children],
initialSeedData: ['', {}, children],
initialParallelRoutes,
isServer: false,
location: new URL('/linking', 'https://localhost') as any,
......@@ -269,7 +269,7 @@ describe('prefetchReducer', () => {
initialTree,
initialHead: null,
initialCanonicalUrl,
initialSeedData: ['', null, children],
initialSeedData: ['', {}, children],
initialParallelRoutes,
isServer: false,
location: new URL('/linking', 'https://localhost') as any,
......
......@@ -28,7 +28,7 @@ jest.mock('../fetch-server-response', () => {
],
[
'',
null,
{},
<html>
<head></head>
<body>
......@@ -127,7 +127,7 @@ describe('refreshReducer', () => {
initialTree,
initialHead: null,
initialCanonicalUrl,
initialSeedData: ['', null, children],
initialSeedData: ['', {}, children],
initialParallelRoutes,
isServer: false,
location: new URL('/linking', 'https://localhost') as any,
......@@ -270,7 +270,7 @@ describe('refreshReducer', () => {
initialTree,
initialHead: null,
initialCanonicalUrl,
initialSeedData: ['', null, children],
initialSeedData: ['', {}, children],
initialParallelRoutes,
isServer: false,
location: new URL('/linking', 'https://localhost') as any,
......@@ -281,7 +281,7 @@ describe('refreshReducer', () => {
initialTree,
initialHead: null,
initialCanonicalUrl,
initialSeedData: ['', null, children],
initialSeedData: ['', {}, children],
initialParallelRoutes,
isServer: false,
location: new URL('/linking', 'https://localhost') as any,
......@@ -451,7 +451,7 @@ describe('refreshReducer', () => {
initialTree,
initialHead: null,
initialCanonicalUrl,
initialSeedData: ['', null, children],
initialSeedData: ['', {}, children],
initialParallelRoutes,
isServer: false,
location: new URL('/linking', 'https://localhost') as any,
......@@ -462,7 +462,7 @@ describe('refreshReducer', () => {
initialTree,
initialHead: null,
initialCanonicalUrl,
initialSeedData: ['', null, children],
initialSeedData: ['', {}, children],
initialParallelRoutes,
isServer: false,
location: new URL('/linking', 'https://localhost') as any,
......@@ -678,7 +678,7 @@ describe('refreshReducer', () => {
initialTree,
initialHead: null,
initialCanonicalUrl,
initialSeedData: ['', null, children],
initialSeedData: ['', {}, children],
initialParallelRoutes,
isServer: false,
location: new URL('/linking', 'https://localhost') as any,
......@@ -691,7 +691,7 @@ describe('refreshReducer', () => {
initialTree,
initialHead: null,
initialCanonicalUrl,
initialSeedData: ['', null, children],
initialSeedData: ['', {}, children],
initialParallelRoutes,
isServer: false,
location: new URL('/linking', 'https://localhost') as any,
......
......@@ -83,7 +83,7 @@ describe('serverPatchReducer', () => {
initialTree,
initialHead: null,
initialCanonicalUrl,
initialSeedData: ['', null, children],
initialSeedData: ['', {}, children],
initialParallelRoutes,
isServer: false,
location: new URL('/linking', 'https://localhost') as any,
......@@ -238,7 +238,7 @@ describe('serverPatchReducer', () => {
initialTree,
initialHead: null,
initialCanonicalUrl,
initialSeedData: ['', null, children],
initialSeedData: ['', {}, children],
initialParallelRoutes,
isServer: false,
location: new URL('/linking', 'https://localhost') as any,
......@@ -248,7 +248,7 @@ describe('serverPatchReducer', () => {
initialTree,
initialHead: null,
initialCanonicalUrl,
initialSeedData: ['', null, children],
initialSeedData: ['', {}, children],
initialParallelRoutes,
isServer: false,
location: new URL('/linking', 'https://localhost') as any,
......
......@@ -25,7 +25,7 @@ jest.mock('../fetch-server-response', () => {
children: ['', {}],
},
],
['about', null, <h1>About Page!</h1>],
['about', {}, <h1>About Page!</h1>],
<>
<title>About page!</title>
</>,
......@@ -56,7 +56,7 @@ const flightDataForPatch: FlightData = [
children: ['', {}],
},
],
['somewhere-else', null, <h1>Somewhere Page!</h1>],
['somewhere-else', {}, <h1>Somewhere Page!</h1>],
<>
<title>Somewhere page!</title>
</>,
......@@ -134,7 +134,7 @@ describe('serverPatchReducer', () => {
initialTree,
initialHead: null,
initialCanonicalUrl,
initialSeedData: ['', null, children],
initialSeedData: ['', {}, children],
initialParallelRoutes,
isServer: false,
location: new URL('/linking/about', 'https://localhost') as any,
......@@ -314,7 +314,7 @@ describe('serverPatchReducer', () => {
initialTree,
initialHead: null,
initialCanonicalUrl,
initialSeedData: ['', null, children],
initialSeedData: ['', {}, children],
initialParallelRoutes,
isServer: false,
location: new URL(initialCanonicalUrl, 'https://localhost') as any,
......
......@@ -35,7 +35,7 @@ describe('shouldHardNavigate', () => {
children: ['', {}],
},
],
['about', null, <h1>About Page!</h1>],
['about', {}, <h1>About Page!</h1>],
<>
<title>About page!</title>
</>,
......@@ -94,7 +94,7 @@ describe('shouldHardNavigate', () => {
children: ['', {}],
},
],
[['id', '123', 'd'], null, null],
[['id', '123', 'd'], {}, null],
null,
],
]
......@@ -151,7 +151,7 @@ describe('shouldHardNavigate', () => {
children: ['', {}],
},
],
[['id', '123', 'd'], null, null],
[['id', '123', 'd'], {}, null],
null,
],
]
......
......@@ -964,7 +964,7 @@ async function renderToHTMLOrFlightImpl(
// so we create a not found page with AppRouter
const initialSeedData: CacheNodeSeedData = [
initialTree[0],
null,
{},
<html id="__next_error__">
<head></head>
<body></body>
......
......@@ -73,7 +73,7 @@ export type CacheNodeSeedData = [
segment: Segment,
parallelRoutes: {
[parallelRouterKey: string]: CacheNodeSeedData | null
} | null,
},
node: React.ReactNode | null
]
......
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