Skip to content

Commit

Permalink
Make CacheNodeSeedData match FlightRouterState more closely (#59590)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
acdlite committed Dec 13, 2023
1 parent 79e82d4 commit c964e9a
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const getFlightData = (): FlightData => {
children: ['', {}],
},
],
['about', null, <h1>About Page!</h1>],
['about', {}, <h1>About Page!</h1>],
<>
<title>About page!</title>
</>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const getFlightData = (): FlightData => {
children: ['', {}],
},
],
['about', null, <h1>SubTreeData Injected!</h1>],
['about', {}, <h1>SubTreeData Injected!</h1>],
<>
<title>Head Injected!</title>
</>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const getFlightData = (): FlightData => {
null,
true,
],
['', null, <h1>About Page!</h1>],
['', {}, <h1>About Page!</h1>],
<>
<title>About page!</title>
</>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const getFlightData = (): FlightData => {
children: ['', {}],
},
],
['about', null, <h1>About Page!</h1>],
['about', {}, <h1>About Page!</h1>],
<>
<title>About page!</title>
</>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const flightData: FlightData = [
children: ['__PAGE__', {}],
},
],
['about', null, <h1>About Page!</h1>],
['about', {}, <h1>About Page!</h1>],
<>
<title>About page!</title>
</>,
Expand Down Expand Up @@ -58,7 +58,7 @@ const demographicsFlightData: FlightData = [
],
[
'',
null,
{},
<html>
<head></head>
<body>Root layout from response</body>
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
</>,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jest.mock('../fetch-server-response', () => {
],
[
'',
null,
{},
<html>
<head></head>
<body>
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
</>,
Expand Down Expand Up @@ -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>
</>,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('shouldHardNavigate', () => {
children: ['', {}],
},
],
['about', null, <h1>About Page!</h1>],
['about', {}, <h1>About Page!</h1>],
<>
<title>About page!</title>
</>,
Expand Down Expand Up @@ -94,7 +94,7 @@ describe('shouldHardNavigate', () => {
children: ['', {}],
},
],
[['id', '123', 'd'], null, null],
[['id', '123', 'd'], {}, null],
null,
],
]
Expand Down Expand Up @@ -151,7 +151,7 @@ describe('shouldHardNavigate', () => {
children: ['', {}],
},
],
[['id', '123', 'd'], null, null],
[['id', '123', 'd'], {}, null],
null,
],
]
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/server/app-render/app-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/server/app-render/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export type CacheNodeSeedData = [
segment: Segment,
parallelRoutes: {
[parallelRouterKey: string]: CacheNodeSeedData | null
} | null,
},
node: React.ReactNode | null
]

Expand Down

0 comments on commit c964e9a

Please sign in to comment.