Unverified Commit eb6ea067 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

[metadata] Change the array head to single node in flight data (#74299)

parent 15bb8ce5
...@@ -145,7 +145,7 @@ export function createEmptyCacheNode(): CacheNode { ...@@ -145,7 +145,7 @@ export function createEmptyCacheNode(): CacheNode {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
loading: null, loading: null,
......
...@@ -549,7 +549,7 @@ export default function OuterLayoutRouter({ ...@@ -549,7 +549,7 @@ export default function OuterLayoutRouter({
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
loading: null, loading: null,
......
...@@ -172,7 +172,7 @@ function fillNewTreeWithOnlyLoadingSegments( ...@@ -172,7 +172,7 @@ function fillNewTreeWithOnlyLoadingSegments(
// copy the layout but null the page segment as that's not meant to be used // copy the layout but null the page segment as that's not meant to be used
rsc: segmentForParallelRoute.includes(PAGE_SEGMENT_KEY) ? null : rsc, rsc: segmentForParallelRoute.includes(PAGE_SEGMENT_KEY) ? null : rsc,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
loading, loading,
...@@ -184,7 +184,7 @@ function fillNewTreeWithOnlyLoadingSegments( ...@@ -184,7 +184,7 @@ function fillNewTreeWithOnlyLoadingSegments(
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
loading: null, loading: null,
......
...@@ -16,7 +16,7 @@ describe('clearCacheNodeDataForSegmentPath', () => { ...@@ -16,7 +16,7 @@ describe('clearCacheNodeDataForSegmentPath', () => {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
loading: null, loading: null,
...@@ -25,7 +25,7 @@ describe('clearCacheNodeDataForSegmentPath', () => { ...@@ -25,7 +25,7 @@ describe('clearCacheNodeDataForSegmentPath', () => {
lazyData: null, lazyData: null,
rsc: <>Root layout</>, rsc: <>Root layout</>,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
...@@ -38,7 +38,7 @@ describe('clearCacheNodeDataForSegmentPath', () => { ...@@ -38,7 +38,7 @@ describe('clearCacheNodeDataForSegmentPath', () => {
lazyData: null, lazyData: null,
rsc: <>Linking</>, rsc: <>Linking</>,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
...@@ -51,7 +51,7 @@ describe('clearCacheNodeDataForSegmentPath', () => { ...@@ -51,7 +51,7 @@ describe('clearCacheNodeDataForSegmentPath', () => {
lazyData: null, lazyData: null,
rsc: <>Page</>, rsc: <>Page</>,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
loading: null, loading: null,
...@@ -71,28 +71,19 @@ describe('clearCacheNodeDataForSegmentPath', () => { ...@@ -71,28 +71,19 @@ describe('clearCacheNodeDataForSegmentPath', () => {
expect(cache).toMatchInlineSnapshot(` expect(cache).toMatchInlineSnapshot(`
{ {
"head": [ "head": null,
null,
null,
],
"lazyData": null, "lazyData": null,
"loading": null, "loading": null,
"parallelRoutes": Map { "parallelRoutes": Map {
"children" => Map { "children" => Map {
"linking" => { "linking" => {
"head": [ "head": null,
null,
null,
],
"lazyData": null, "lazyData": null,
"loading": null, "loading": null,
"parallelRoutes": Map { "parallelRoutes": Map {
"children" => Map { "children" => Map {
"" => { "" => {
"head": [ "head": null,
null,
null,
],
"lazyData": null, "lazyData": null,
"loading": null, "loading": null,
"parallelRoutes": Map {}, "parallelRoutes": Map {},
...@@ -111,10 +102,7 @@ describe('clearCacheNodeDataForSegmentPath', () => { ...@@ -111,10 +102,7 @@ describe('clearCacheNodeDataForSegmentPath', () => {
</React.Fragment>, </React.Fragment>,
}, },
"dashboard" => { "dashboard" => {
"head": [ "head": null,
null,
null,
],
"lazyData": null, "lazyData": null,
"loading": null, "loading": null,
"parallelRoutes": Map {}, "parallelRoutes": Map {},
......
...@@ -40,7 +40,7 @@ export function clearCacheNodeDataForSegmentPath( ...@@ -40,7 +40,7 @@ export function clearCacheNodeDataForSegmentPath(
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
loading: null, loading: null,
...@@ -56,7 +56,7 @@ export function clearCacheNodeDataForSegmentPath( ...@@ -56,7 +56,7 @@ export function clearCacheNodeDataForSegmentPath(
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
loading: null, loading: null,
......
...@@ -32,9 +32,7 @@ describe('createInitialRouterState', () => { ...@@ -32,9 +32,7 @@ describe('createInitialRouterState', () => {
const initialParallelRoutes: CacheNode['parallelRoutes'] = new Map() const initialParallelRoutes: CacheNode['parallelRoutes'] = new Map()
const state = createInitialRouterState({ const state = createInitialRouterState({
initialFlightData: [ initialFlightData: [[initialTree, ['', children, {}, null]]],
[initialTree, ['', children, {}, null], <title>Test</title>],
],
initialCanonicalUrlParts: initialCanonicalUrl.split('/'), initialCanonicalUrlParts: initialCanonicalUrl.split('/'),
initialParallelRoutes, initialParallelRoutes,
location: new URL('/linking', 'https://localhost') as any, location: new URL('/linking', 'https://localhost') as any,
...@@ -44,9 +42,7 @@ describe('createInitialRouterState', () => { ...@@ -44,9 +42,7 @@ describe('createInitialRouterState', () => {
}) })
const state2 = createInitialRouterState({ const state2 = createInitialRouterState({
initialFlightData: [ initialFlightData: [[initialTree, ['', children, {}, null]]],
[initialTree, ['', children, {}, null], <title>Test</title>],
],
initialCanonicalUrlParts: initialCanonicalUrl.split('/'), initialCanonicalUrlParts: initialCanonicalUrl.split('/'),
initialParallelRoutes, initialParallelRoutes,
location: new URL('/linking', 'https://localhost') as any, location: new URL('/linking', 'https://localhost') as any,
...@@ -59,7 +55,7 @@ describe('createInitialRouterState', () => { ...@@ -59,7 +55,7 @@ describe('createInitialRouterState', () => {
lazyData: null, lazyData: null,
rsc: children, rsc: children,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
...@@ -81,7 +77,7 @@ describe('createInitialRouterState', () => { ...@@ -81,7 +77,7 @@ describe('createInitialRouterState', () => {
prefetchRsc: null, prefetchRsc: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
loading: null, loading: null,
head: [null, <title>Test</title>], head: null,
prefetchHead: null, prefetchHead: null,
}, },
], ],
...@@ -91,7 +87,7 @@ describe('createInitialRouterState', () => { ...@@ -91,7 +87,7 @@ describe('createInitialRouterState', () => {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
}, },
......
...@@ -48,7 +48,7 @@ export function createInitialRouterState({ ...@@ -48,7 +48,7 @@ export function createInitialRouterState({
lazyData: null, lazyData: null,
rsc, rsc,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
// The cache gets seeded during the first render. `initialParallelRoutes` ensures the cache from the first render is there during the second render. // The cache gets seeded during the first render. `initialParallelRoutes` ensures the cache from the first render is there during the second render.
parallelRoutes: isServer ? new Map() : initialParallelRoutes, parallelRoutes: isServer ? new Map() : initialParallelRoutes,
......
...@@ -10,7 +10,7 @@ const getFlightData = (): NormalizedFlightData[] => { ...@@ -10,7 +10,7 @@ const getFlightData = (): NormalizedFlightData[] => {
segment: 'about', segment: 'about',
tree: ['about', { children: ['', {}] }], tree: ['about', { children: ['', {}] }],
seedData: ['about', <h1>SubTreeData Injected!</h1>, {}, null, false], seedData: ['about', <h1>SubTreeData Injected!</h1>, {}, null, false],
head: [null, '<title>Head Injected!</title>'], head: null,
isHeadPartial: false, isHeadPartial: false,
isRootRender: false, isRootRender: false,
}, },
...@@ -23,7 +23,7 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -23,7 +23,7 @@ describe('fillCacheWithNewSubtreeData', () => {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
...@@ -32,7 +32,7 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -32,7 +32,7 @@ describe('fillCacheWithNewSubtreeData', () => {
lazyData: null, lazyData: null,
rsc: <>Root layout</>, rsc: <>Root layout</>,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
...@@ -45,7 +45,7 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -45,7 +45,7 @@ describe('fillCacheWithNewSubtreeData', () => {
lazyData: null, lazyData: null,
rsc: <>Linking</>, rsc: <>Linking</>,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
...@@ -58,7 +58,7 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -58,7 +58,7 @@ describe('fillCacheWithNewSubtreeData', () => {
lazyData: null, lazyData: null,
rsc: <>Page</>, rsc: <>Page</>,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
...@@ -89,7 +89,7 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -89,7 +89,7 @@ describe('fillCacheWithNewSubtreeData', () => {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
...@@ -102,7 +102,7 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -102,7 +102,7 @@ describe('fillCacheWithNewSubtreeData', () => {
lazyData: null, lazyData: null,
rsc: <>Linking</>, rsc: <>Linking</>,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
...@@ -116,7 +116,7 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -116,7 +116,7 @@ describe('fillCacheWithNewSubtreeData', () => {
lazyData: null, lazyData: null,
rsc: <>Page</>, rsc: <>Page</>,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
...@@ -126,7 +126,7 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -126,7 +126,7 @@ describe('fillCacheWithNewSubtreeData', () => {
'about', 'about',
{ {
lazyData: null, lazyData: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
...@@ -142,12 +142,7 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -142,12 +142,7 @@ describe('fillCacheWithNewSubtreeData', () => {
parallelRoutes: new Map(), parallelRoutes: new Map(),
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
head: [ head: null,
null,
<>
<title>Head Injected!</title>
</>,
],
}, },
], ],
]), ]),
......
...@@ -71,7 +71,7 @@ function fillCacheHelper( ...@@ -71,7 +71,7 @@ function fillCacheHelper(
rsc: rsc:
fillLazyItems || incomingSegment !== PAGE_SEGMENT_KEY ? rsc : null, fillLazyItems || incomingSegment !== PAGE_SEGMENT_KEY ? rsc : null,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading, loading,
parallelRoutes: parallelRoutes:
......
...@@ -39,7 +39,7 @@ describe('fillLazyItemsTillLeafWithHead', () => { ...@@ -39,7 +39,7 @@ describe('fillLazyItemsTillLeafWithHead', () => {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
loading: null, loading: null,
...@@ -48,7 +48,7 @@ describe('fillLazyItemsTillLeafWithHead', () => { ...@@ -48,7 +48,7 @@ describe('fillLazyItemsTillLeafWithHead', () => {
lazyData: null, lazyData: null,
rsc: <>Root layout</>, rsc: <>Root layout</>,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
...@@ -61,7 +61,7 @@ describe('fillLazyItemsTillLeafWithHead', () => { ...@@ -61,7 +61,7 @@ describe('fillLazyItemsTillLeafWithHead', () => {
lazyData: null, lazyData: null,
rsc: <>Linking</>, rsc: <>Linking</>,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
...@@ -74,7 +74,7 @@ describe('fillLazyItemsTillLeafWithHead', () => { ...@@ -74,7 +74,7 @@ describe('fillLazyItemsTillLeafWithHead', () => {
lazyData: null, lazyData: null,
rsc: <>Page</>, rsc: <>Page</>,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
...@@ -114,7 +114,7 @@ describe('fillLazyItemsTillLeafWithHead', () => { ...@@ -114,7 +114,7 @@ describe('fillLazyItemsTillLeafWithHead', () => {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
...@@ -127,7 +127,7 @@ describe('fillLazyItemsTillLeafWithHead', () => { ...@@ -127,7 +127,7 @@ describe('fillLazyItemsTillLeafWithHead', () => {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
...@@ -152,12 +152,7 @@ describe('fillLazyItemsTillLeafWithHead', () => { ...@@ -152,12 +152,7 @@ describe('fillLazyItemsTillLeafWithHead', () => {
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
head: [ head: null,
null,
<>
<title>About page!</title>
</>,
],
}, },
], ],
]), ]),
...@@ -165,7 +160,7 @@ describe('fillLazyItemsTillLeafWithHead', () => { ...@@ -165,7 +160,7 @@ describe('fillLazyItemsTillLeafWithHead', () => {
]), ]),
rsc: null, rsc: null,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
}, },
], ],
...@@ -175,7 +170,7 @@ describe('fillLazyItemsTillLeafWithHead', () => { ...@@ -175,7 +170,7 @@ describe('fillLazyItemsTillLeafWithHead', () => {
lazyData: null, lazyData: null,
rsc: <>Page</>, rsc: <>Page</>,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
......
import type { import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime'
CacheNode,
HeadData,
} from '../../../shared/lib/app-router-context.shared-runtime'
import type { import type {
FlightRouterState, FlightRouterState,
CacheNodeSeedData, CacheNodeSeedData,
...@@ -17,7 +14,7 @@ export function fillLazyItemsTillLeafWithHead( ...@@ -17,7 +14,7 @@ export function fillLazyItemsTillLeafWithHead(
existingCache: CacheNode | undefined, existingCache: CacheNode | undefined,
routerState: FlightRouterState, routerState: FlightRouterState,
cacheNodeSeedData: CacheNodeSeedData | null, cacheNodeSeedData: CacheNodeSeedData | null,
head: HeadData, head: React.ReactNode,
prefetchEntry: PrefetchCacheEntry | undefined prefetchEntry: PrefetchCacheEntry | undefined
): void { ): void {
const isLastSegment = Object.keys(routerState[1]).length === 0 const isLastSegment = Object.keys(routerState[1]).length === 0
...@@ -69,7 +66,7 @@ export function fillLazyItemsTillLeafWithHead( ...@@ -69,7 +66,7 @@ export function fillLazyItemsTillLeafWithHead(
// `prefetchRsc`. As an incremental step, we'll just de-opt to the // `prefetchRsc`. As an incremental step, we'll just de-opt to the
// old behavior — no PPR value. // old behavior — no PPR value.
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading, loading,
parallelRoutes: new Map(existingCacheNode?.parallelRoutes), parallelRoutes: new Map(existingCacheNode?.parallelRoutes),
...@@ -96,7 +93,7 @@ export function fillLazyItemsTillLeafWithHead( ...@@ -96,7 +93,7 @@ export function fillLazyItemsTillLeafWithHead(
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
parallelRoutes: new Map(existingCacheNode?.parallelRoutes), parallelRoutes: new Map(existingCacheNode?.parallelRoutes),
loading: null, loading: null,
...@@ -129,7 +126,7 @@ export function fillLazyItemsTillLeafWithHead( ...@@ -129,7 +126,7 @@ export function fillLazyItemsTillLeafWithHead(
lazyData: null, lazyData: null,
rsc: seedNode, rsc: seedNode,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
loading, loading,
...@@ -141,7 +138,7 @@ export function fillLazyItemsTillLeafWithHead( ...@@ -141,7 +138,7 @@ export function fillLazyItemsTillLeafWithHead(
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
loading: null, loading: null,
......
...@@ -12,7 +12,7 @@ const getFlightData = (): NormalizedFlightData[] => { ...@@ -12,7 +12,7 @@ const getFlightData = (): NormalizedFlightData[] => {
segment: 'about', segment: 'about',
tree: ['about', { children: ['', {}] }], tree: ['about', { children: ['', {}] }],
seedData: ['about', <h1>About Page!</h1>, {}, null, false], seedData: ['about', <h1>About Page!</h1>, {}, null, false],
head: [null, '<title>About page!</title>'], head: null,
isHeadPartial: false, isHeadPartial: false,
isRootRender: false, isRootRender: false,
}, },
...@@ -25,7 +25,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => { ...@@ -25,7 +25,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
...@@ -34,7 +34,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => { ...@@ -34,7 +34,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => {
lazyData: null, lazyData: null,
rsc: <>Root layout</>, rsc: <>Root layout</>,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
...@@ -47,7 +47,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => { ...@@ -47,7 +47,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => {
lazyData: null, lazyData: null,
rsc: <>Linking</>, rsc: <>Linking</>,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
...@@ -60,7 +60,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => { ...@@ -60,7 +60,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => {
lazyData: null, lazyData: null,
rsc: <>Page</>, rsc: <>Page</>,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
...@@ -100,7 +100,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => { ...@@ -100,7 +100,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => {
const expectedCache: CacheNode = { const expectedCache: CacheNode = {
lazyData: null, lazyData: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
...@@ -111,7 +111,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => { ...@@ -111,7 +111,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => {
'linking', 'linking',
{ {
lazyData: null, lazyData: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
...@@ -126,7 +126,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => { ...@@ -126,7 +126,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => {
parallelRoutes: new Map(), parallelRoutes: new Map(),
rsc: <React.Fragment>Page</React.Fragment>, rsc: <React.Fragment>Page</React.Fragment>,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
}, },
], ],
......
...@@ -8,7 +8,7 @@ describe('invalidateCacheByRouterState', () => { ...@@ -8,7 +8,7 @@ describe('invalidateCacheByRouterState', () => {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
...@@ -17,7 +17,7 @@ describe('invalidateCacheByRouterState', () => { ...@@ -17,7 +17,7 @@ describe('invalidateCacheByRouterState', () => {
lazyData: null, lazyData: null,
rsc: <>Root layout</>, rsc: <>Root layout</>,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
...@@ -30,7 +30,7 @@ describe('invalidateCacheByRouterState', () => { ...@@ -30,7 +30,7 @@ describe('invalidateCacheByRouterState', () => {
lazyData: null, lazyData: null,
rsc: <>Linking</>, rsc: <>Linking</>,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
...@@ -43,7 +43,7 @@ describe('invalidateCacheByRouterState', () => { ...@@ -43,7 +43,7 @@ describe('invalidateCacheByRouterState', () => {
lazyData: null, lazyData: null,
rsc: <>Page</>, rsc: <>Page</>,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
...@@ -85,7 +85,7 @@ describe('invalidateCacheByRouterState', () => { ...@@ -85,7 +85,7 @@ describe('invalidateCacheByRouterState', () => {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map([['children', new Map()]]), parallelRoutes: new Map([['children', new Map()]]),
......
...@@ -387,10 +387,7 @@ function createCacheNodeOnNavigation( ...@@ -387,10 +387,7 @@ function createCacheNodeOnNavigation(
// `prefetchRsc` field. // `prefetchRsc` field.
rsc, rsc,
prefetchRsc: null, prefetchRsc: null,
head: (isLeafSegment ? possiblyPartialPrefetchHead : null) ?? [ head: isLeafSegment ? possiblyPartialPrefetchHead : null,
null,
null,
],
prefetchHead: null, prefetchHead: null,
loading, loading,
parallelRoutes: cacheNodeChildren, parallelRoutes: cacheNodeChildren,
...@@ -698,14 +695,7 @@ function createPendingCacheNode( ...@@ -698,14 +695,7 @@ function createPendingCacheNode(
// Create a deferred promise. This will be fulfilled once the dynamic // Create a deferred promise. This will be fulfilled once the dynamic
// response is received from the server. // response is received from the server.
rsc: createDeferredRsc() as React.ReactNode, rsc: createDeferredRsc() as React.ReactNode,
head: isLeafSegment head: isLeafSegment ? (createDeferredRsc() as React.ReactNode) : null,
? [
// TODO: change head back to ReactNode when metadata
// is stably rendered in body
createDeferredRsc() as React.ReactNode,
null,
]
: [null, null],
} }
} }
...@@ -810,8 +800,8 @@ function finishPendingCacheNode( ...@@ -810,8 +800,8 @@ function finishPendingCacheNode(
// TODO: change head back to ReactNode when metadata // TODO: change head back to ReactNode when metadata
// is stably rendered in body // is stably rendered in body
// Handle head[0] - viewport // Handle head[0] - viewport
if (isDeferredRsc(head[0])) { if (isDeferredRsc(head)) {
head[0].resolve(dynamicHead[0]) head.resolve(dynamicHead)
} }
} }
......
import React from 'react'
import type { FlightRouterState } from '../../../../server/app-render/types' import type { FlightRouterState } from '../../../../server/app-render/types'
import type { CacheNode } from '../../../../shared/lib/app-router-context.shared-runtime' import type { CacheNode } from '../../../../shared/lib/app-router-context.shared-runtime'
import { findHeadInCache } from './find-head-in-cache' import { findHeadInCache } from './find-head-in-cache'
...@@ -29,7 +28,7 @@ describe('findHeadInCache', () => { ...@@ -29,7 +28,7 @@ describe('findHeadInCache', () => {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
...@@ -42,7 +41,7 @@ describe('findHeadInCache', () => { ...@@ -42,7 +41,7 @@ describe('findHeadInCache', () => {
lazyData: null, lazyData: null,
rsc: null, rsc: null,
prefetchRsc: null, prefetchRsc: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
...@@ -53,7 +52,7 @@ describe('findHeadInCache', () => { ...@@ -53,7 +52,7 @@ describe('findHeadInCache', () => {
'about', 'about',
{ {
lazyData: null, lazyData: null,
head: [null, null], head: null,
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
...@@ -69,12 +68,7 @@ describe('findHeadInCache', () => { ...@@ -69,12 +68,7 @@ describe('findHeadInCache', () => {
prefetchHead: null, prefetchHead: null,
loading: null, loading: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
head: [ head: null,
null,
<>
<title>About page!</title>
</>,
],
}, },
], ],
]), ]),
...@@ -108,12 +102,7 @@ describe('findHeadInCache', () => { ...@@ -108,12 +102,7 @@ describe('findHeadInCache', () => {
expect(result).not.toBeNull() expect(result).not.toBeNull()
const [cacheNode, key] = result! const [cacheNode, key] = result!
expect(cacheNode.head[0]).toBe(null) expect(cacheNode.head).toBe(null)
expect(cacheNode.head[1]).toMatchObject(
<>
<title>About page!</title>
</>
)
expect(key).toBe('/linking/about/') expect(key).toBe('/linking/about/')
}) })
}) })
...@@ -313,7 +313,7 @@ export function readOrCreateRouteCacheEntry( ...@@ -313,7 +313,7 @@ export function readOrCreateRouteCacheEntry(
status: EntryStatus.Empty, status: EntryStatus.Empty,
blockedTasks: null, blockedTasks: null,
tree: null, tree: null,
head: [null, null], head: null,
isHeadPartial: true, isHeadPartial: true,
// Since this is an empty entry, there's no reason to ever evict it. It will // Since this is an empty entry, there's no reason to ever evict it. It will
// be updated when the data is populated. // be updated when the data is populated.
......
...@@ -32,7 +32,7 @@ export type NormalizedFlightData = { ...@@ -32,7 +32,7 @@ export type NormalizedFlightData = {
export function getFlightDataPartsFromPath( export function getFlightDataPartsFromPath(
flightDataPath: FlightDataPath flightDataPath: FlightDataPath
): NormalizedFlightData { ): NormalizedFlightData {
// Pick the last 4 items from the `FlightDataPath` to get the [tree, seedData, [viewport, metadata], isHeadPartial]. // Pick the last 4 items from the `FlightDataPath` to get the [tree, seedData, viewport, isHeadPartial].
const flightDataPathLength = 4 const flightDataPathLength = 4
// tree, seedData, and head are *always* the last three items in the `FlightDataPath`. // tree, seedData, and head are *always* the last three items in the `FlightDataPath`.
const [tree, seedData, head, isHeadPartial] = const [tree, seedData, head, isHeadPartial] =
......
...@@ -6,7 +6,10 @@ import type { NextFontManifest } from '../../build/webpack/plugins/next-font-man ...@@ -6,7 +6,10 @@ import type { NextFontManifest } from '../../build/webpack/plugins/next-font-man
import type { ParsedUrlQuery } from 'querystring' import type { ParsedUrlQuery } from 'querystring'
import type { AppPageModule } from '../route-modules/app-page/module' import type { AppPageModule } from '../route-modules/app-page/module'
import type { ExpireTime } from '../lib/revalidate' import type { ExpireTime } from '../lib/revalidate'
import type { LoadingModuleData } from '../../shared/lib/app-router-context.shared-runtime' import type {
HeadData,
LoadingModuleData,
} from '../../shared/lib/app-router-context.shared-runtime'
import type { DeepReadonly } from '../../shared/lib/deep-readonly' import type { DeepReadonly } from '../../shared/lib/deep-readonly'
import type { __ApiPreviewProps } from '../api-utils' import type { __ApiPreviewProps } from '../api-utils'
...@@ -131,7 +134,7 @@ export type FlightDataSegment = [ ...@@ -131,7 +134,7 @@ export type FlightDataSegment = [
/* segment of the rendered slice: */ Segment, /* segment of the rendered slice: */ Segment,
/* treePatch */ FlightRouterState, /* treePatch */ FlightRouterState,
/* cacheNodeSeedData */ CacheNodeSeedData | null, // Can be null during prefetch if there's no loading component /* cacheNodeSeedData */ CacheNodeSeedData | null, // Can be null during prefetch if there's no loading component
/* head: [viewport, metadata] */ [React.ReactNode, React.ReactNode], /* head: viewport */ HeadData,
/* isHeadPartial */ boolean, /* isHeadPartial */ boolean,
] ]
......
...@@ -23,8 +23,8 @@ export type LoadingModuleData = ...@@ -23,8 +23,8 @@ export type LoadingModuleData =
| [React.JSX.Element, React.ReactNode, React.ReactNode] | [React.JSX.Element, React.ReactNode, React.ReactNode]
| null | null
/** metadata cache nodes: [viewport, metadata] */ /** viewport metadata node */
export type HeadData = [React.ReactNode, React.ReactNode] export type HeadData = React.ReactNode
export type LazyCacheNode = { export type LazyCacheNode = {
/** /**
......
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