Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[metadata] Separate viewport and metadata in rsc and cache #73867

Merged
merged 5 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/next/src/client/components/app-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export function createEmptyCacheNode(): CacheNode {
lazyData: null,
rsc: null,
prefetchRsc: null,
head: null,
head: [null, null],
prefetchHead: null,
parallelRoutes: new Map(),
loading: null,
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/client/components/layout-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ export default function OuterLayoutRouter({
lazyData: null,
rsc: null,
prefetchRsc: null,
head: null,
head: [null, null],
prefetchHead: null,
parallelRoutes: new Map(),
loading: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function fillNewTreeWithOnlyLoadingSegments(
// copy the layout but null the page segment as that's not meant to be used
rsc: segmentForParallelRoute.includes(PAGE_SEGMENT_KEY) ? null : rsc,
prefetchRsc: null,
head: null,
head: [null, null],
prefetchHead: null,
parallelRoutes: new Map(),
loading,
Expand All @@ -184,7 +184,7 @@ function fillNewTreeWithOnlyLoadingSegments(
lazyData: null,
rsc: null,
prefetchRsc: null,
head: null,
head: [null, null],
prefetchHead: null,
parallelRoutes: new Map(),
loading: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('clearCacheNodeDataForSegmentPath', () => {
lazyData: null,
rsc: null,
prefetchRsc: null,
head: null,
head: [null, null],
prefetchHead: null,
parallelRoutes: new Map(),
loading: null,
Expand All @@ -25,7 +25,7 @@ describe('clearCacheNodeDataForSegmentPath', () => {
lazyData: null,
rsc: <>Root layout</>,
prefetchRsc: null,
head: null,
head: [null, null],
prefetchHead: null,
loading: null,
parallelRoutes: new Map([
Expand All @@ -38,7 +38,7 @@ describe('clearCacheNodeDataForSegmentPath', () => {
lazyData: null,
rsc: <>Linking</>,
prefetchRsc: null,
head: null,
head: [null, null],
prefetchHead: null,
loading: null,
parallelRoutes: new Map([
Expand All @@ -51,7 +51,7 @@ describe('clearCacheNodeDataForSegmentPath', () => {
lazyData: null,
rsc: <>Page</>,
prefetchRsc: null,
head: null,
head: [null, null],
prefetchHead: null,
parallelRoutes: new Map(),
loading: null,
Expand All @@ -70,52 +70,64 @@ describe('clearCacheNodeDataForSegmentPath', () => {
clearCacheNodeDataForSegmentPath(cache, existingCache, flightSegmentPath)

expect(cache).toMatchInlineSnapshot(`
{
"head": null,
"lazyData": null,
"loading": null,
"parallelRoutes": Map {
"children" => Map {
"linking" => {
"head": null,
"lazyData": null,
"loading": null,
"parallelRoutes": Map {
"children" => Map {
"" => {
"head": null,
"lazyData": null,
"loading": null,
"parallelRoutes": Map {},
"prefetchHead": null,
"prefetchRsc": null,
"rsc": <React.Fragment>
Page
</React.Fragment>,
},
},
},
"prefetchHead": null,
"prefetchRsc": null,
"rsc": <React.Fragment>
Linking
</React.Fragment>,
},
"dashboard" => {
"head": null,
"lazyData": null,
"loading": null,
"parallelRoutes": Map {},
"prefetchHead": null,
"prefetchRsc": null,
"rsc": null,
},
},
},
"prefetchHead": null,
"prefetchRsc": null,
"rsc": null,
}
{
"head": [
null,
null,
],
"lazyData": null,
"loading": null,
"parallelRoutes": Map {
"children" => Map {
"linking" => {
"head": [
null,
null,
],
"lazyData": null,
"loading": null,
"parallelRoutes": Map {
"children" => Map {
"" => {
"head": [
null,
null,
],
"lazyData": null,
"loading": null,
"parallelRoutes": Map {},
"prefetchHead": null,
"prefetchRsc": null,
"rsc": <React.Fragment>
Page
</React.Fragment>,
},
},
},
"prefetchHead": null,
"prefetchRsc": null,
"rsc": <React.Fragment>
Linking
</React.Fragment>,
},
"dashboard" => {
"head": [
null,
null,
],
"lazyData": null,
"loading": null,
"parallelRoutes": Map {},
"prefetchHead": null,
"prefetchRsc": null,
"rsc": null,
},
},
},
"prefetchHead": null,
"prefetchRsc": null,
"rsc": null,
}
`)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function clearCacheNodeDataForSegmentPath(
lazyData: null,
rsc: null,
prefetchRsc: null,
head: null,
head: [null, null],
prefetchHead: null,
parallelRoutes: new Map(),
loading: null,
Expand All @@ -56,7 +56,7 @@ export function clearCacheNodeDataForSegmentPath(
lazyData: null,
rsc: null,
prefetchRsc: null,
head: null,
head: [null, null],
prefetchHead: null,
parallelRoutes: new Map(),
loading: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('createInitialRouterState', () => {
lazyData: null,
rsc: children,
prefetchRsc: null,
head: null,
head: [null, null],
prefetchHead: null,
loading: null,
parallelRoutes: new Map([
Expand All @@ -81,7 +81,7 @@ describe('createInitialRouterState', () => {
prefetchRsc: null,
parallelRoutes: new Map(),
loading: null,
head: <title>Test</title>,
head: [null, <title>Test</title>],
prefetchHead: null,
},
],
Expand All @@ -91,7 +91,7 @@ describe('createInitialRouterState', () => {
lazyData: null,
rsc: null,
prefetchRsc: null,
head: null,
head: [null, null],
prefetchHead: null,
loading: null,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function createInitialRouterState({
lazyData: null,
rsc,
prefetchRsc: null,
head: null,
head: [null, 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.
parallelRoutes: isServer ? new Map() : initialParallelRoutes,
Expand All @@ -74,7 +74,8 @@ export function createInitialRouterState({
undefined,
initialTree,
initialSeedData,
initialHead
initialHead,
undefined
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import React from 'react'
import { fillCacheWithNewSubTreeData } from './fill-cache-with-new-subtree-data'
import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime'
import type { NormalizedFlightData } from '../../flight-data-helpers'
Expand All @@ -11,7 +10,7 @@ const getFlightData = (): NormalizedFlightData[] => {
segment: 'about',
tree: ['about', { children: ['', {}] }],
seedData: ['about', <h1>SubTreeData Injected!</h1>, {}, null, false],
head: '<title>Head Injected!</title>',
head: [null, '<title>Head Injected!</title>'],
isHeadPartial: false,
isRootRender: false,
},
Expand All @@ -24,7 +23,7 @@ describe('fillCacheWithNewSubtreeData', () => {
lazyData: null,
rsc: null,
prefetchRsc: null,
head: null,
head: [null, null],
prefetchHead: null,
loading: null,
parallelRoutes: new Map(),
Expand All @@ -33,7 +32,7 @@ describe('fillCacheWithNewSubtreeData', () => {
lazyData: null,
rsc: <>Root layout</>,
prefetchRsc: null,
head: null,
head: [null, null],
prefetchHead: null,
loading: null,
parallelRoutes: new Map([
Expand All @@ -46,7 +45,7 @@ describe('fillCacheWithNewSubtreeData', () => {
lazyData: null,
rsc: <>Linking</>,
prefetchRsc: null,
head: null,
head: [null, null],
prefetchHead: null,
loading: null,
parallelRoutes: new Map([
Expand All @@ -59,7 +58,7 @@ describe('fillCacheWithNewSubtreeData', () => {
lazyData: null,
rsc: <>Page</>,
prefetchRsc: null,
head: null,
head: [null, null],
prefetchHead: null,
loading: null,
parallelRoutes: new Map(),
Expand Down Expand Up @@ -90,7 +89,7 @@ describe('fillCacheWithNewSubtreeData', () => {
lazyData: null,
rsc: null,
prefetchRsc: null,
head: null,
head: [null, null],
prefetchHead: null,
loading: null,
parallelRoutes: new Map([
Expand All @@ -103,7 +102,7 @@ describe('fillCacheWithNewSubtreeData', () => {
lazyData: null,
rsc: <>Linking</>,
prefetchRsc: null,
head: null,
head: [null, null],
prefetchHead: null,
loading: null,
parallelRoutes: new Map([
Expand All @@ -117,7 +116,7 @@ describe('fillCacheWithNewSubtreeData', () => {
lazyData: null,
rsc: <>Page</>,
prefetchRsc: null,
head: null,
head: [null, null],
prefetchHead: null,
loading: null,
parallelRoutes: new Map(),
Expand All @@ -127,7 +126,7 @@ describe('fillCacheWithNewSubtreeData', () => {
'about',
{
lazyData: null,
head: null,
head: [null, null],
prefetchHead: null,
loading: null,
parallelRoutes: new Map([
Expand All @@ -143,11 +142,12 @@ describe('fillCacheWithNewSubtreeData', () => {
parallelRoutes: new Map(),
prefetchHead: null,
loading: null,
head: (
head: [
null,
<>
<title>Head Injected!</title>
</>
),
</>,
],
},
],
]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function fillCacheHelper(
rsc:
fillLazyItems || incomingSegment !== PAGE_SEGMENT_KEY ? rsc : null,
prefetchRsc: null,
head: null,
head: [null, null],
prefetchHead: null,
loading,
parallelRoutes:
Expand Down
Loading
Loading