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