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

Remove CacheNode.status field (#59472)

I'm about to make some changes to the CacheNode data structure, and
before I add more complexity, I noticed an opportunity to remove some —
the `status` field isn't logically necessary:

- The `DATA_FETCH` and `LAZY_INITIALIZED` states are already treated as
equivalent; in either case, they will cause the render to suspend during
render, trigger a lazy data fetch (if one hasn't been triggered
already), and then update the router with the result of the response.
- `subTreeData` is null if and only if the node is in the `DATA_FETCH`
or `LAZY_INITIALIZED` states, and it always causes the render to
suspend. So rather than check if the status is one of those, we can
check if `subTreeData` is null.

The most important changes are to CacheNode type in
app-router-context.shared-runtime and the lazy fetching logic in
LayoutRouter. Everything else in the diff is related to deleting the
`status` field wherever a CacheNode is referenced, like in the reducer
unit tests.

Closes NEXT-1842
parent c542a761
...@@ -13,7 +13,6 @@ import { ...@@ -13,7 +13,6 @@ import {
AppRouterContext, AppRouterContext,
LayoutRouterContext, LayoutRouterContext,
GlobalLayoutRouterContext, GlobalLayoutRouterContext,
CacheStates,
} from '../../shared/lib/app-router-context.shared-runtime' } from '../../shared/lib/app-router-context.shared-runtime'
import type { import type {
CacheNode, CacheNode,
...@@ -149,7 +148,6 @@ function HistoryUpdater({ ...@@ -149,7 +148,6 @@ function HistoryUpdater({
} }
export const createEmptyCacheNode = () => ({ export const createEmptyCacheNode = () => ({
status: CacheStates.LAZY_INITIALIZED,
data: null, data: null,
subTreeData: null, subTreeData: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
......
...@@ -12,7 +12,6 @@ import type { FocusAndScrollRef } from './router-reducer/router-reducer-types' ...@@ -12,7 +12,6 @@ import type { FocusAndScrollRef } from './router-reducer/router-reducer-types'
import React, { useContext, use, startTransition, Suspense } from 'react' import React, { useContext, use, startTransition, Suspense } from 'react'
import ReactDOM from 'react-dom' import ReactDOM from 'react-dom'
import { import {
CacheStates,
LayoutRouterContext, LayoutRouterContext,
GlobalLayoutRouterContext, GlobalLayoutRouterContext,
TemplateContext, TemplateContext,
...@@ -338,8 +337,16 @@ function InnerLayoutRouter({ ...@@ -338,8 +337,16 @@ function InnerLayoutRouter({
// Read segment path from the parallel router cache node. // Read segment path from the parallel router cache node.
let childNode = childNodes.get(cacheKey) let childNode = childNodes.get(cacheKey)
// When childNode is not available during rendering client-side we need to fetch it from the server. // When data is not available during rendering client-side we need to fetch
if (!childNode || childNode.status === CacheStates.LAZY_INITIALIZED) { // it from the server.
if (
!childNode ||
// Check if this is a lazy cache entry that has not yet initiated a
// data request.
//
// TODO: An eventual goal of PPR is to remove this case entirely.
(childNode.subTreeData === null && childNode.data === null)
) {
/** /**
* Router state with refetch marker added * Router state with refetch marker added
*/ */
...@@ -347,7 +354,6 @@ function InnerLayoutRouter({ ...@@ -347,7 +354,6 @@ function InnerLayoutRouter({
const refetchTree = walkAddRefetch(['', ...segmentPath], fullTree) const refetchTree = walkAddRefetch(['', ...segmentPath], fullTree)
childNode = { childNode = {
status: CacheStates.DATA_FETCH,
data: fetchServerResponse( data: fetchServerResponse(
new URL(url, location.origin), new URL(url, location.origin),
refetchTree, refetchTree,
...@@ -355,14 +361,8 @@ function InnerLayoutRouter({ ...@@ -355,14 +361,8 @@ function InnerLayoutRouter({
buildId buildId
), ),
subTreeData: null, subTreeData: null,
head: head: childNode ? childNode.head : undefined,
childNode && childNode.status === CacheStates.LAZY_INITIALIZED parallelRoutes: childNode ? childNode.parallelRoutes : new Map(),
? childNode.head
: undefined,
parallelRoutes:
childNode && childNode.status === CacheStates.LAZY_INITIALIZED
? childNode.parallelRoutes
: new Map(),
} }
/** /**
......
import { CacheStates } from '../../../shared/lib/app-router-context.shared-runtime'
import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime' import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime'
import type { FlightDataPath } from '../../../server/app-render/types' import type { FlightDataPath } from '../../../server/app-render/types'
import { fillLazyItemsTillLeafWithHead } from './fill-lazy-items-till-leaf-with-head' import { fillLazyItemsTillLeafWithHead } from './fill-lazy-items-till-leaf-with-head'
...@@ -20,7 +19,6 @@ export function applyFlightData( ...@@ -20,7 +19,6 @@ export function applyFlightData(
if (flightDataPath.length === 3) { if (flightDataPath.length === 3) {
const subTreeData = cacheNodeSeedData[2] const subTreeData = cacheNodeSeedData[2]
cache.status = CacheStates.READY
cache.subTreeData = subTreeData cache.subTreeData = subTreeData
fillLazyItemsTillLeafWithHead( fillLazyItemsTillLeafWithHead(
cache, cache,
...@@ -32,7 +30,6 @@ export function applyFlightData( ...@@ -32,7 +30,6 @@ export function applyFlightData(
) )
} else { } else {
// Copy subTreeData for the root node of the cache. // Copy subTreeData for the root node of the cache.
cache.status = CacheStates.READY
cache.subTreeData = existingCache.subTreeData cache.subTreeData = existingCache.subTreeData
cache.parallelRoutes = new Map(existingCache.parallelRoutes) cache.parallelRoutes = new Map(existingCache.parallelRoutes)
// Create a copy of the existing cache with the subTreeData applied. // Create a copy of the existing cache with the subTreeData applied.
......
import React from 'react' import React from 'react'
import type { FlightRouterState } from '../../../server/app-render/types' import type { FlightRouterState } from '../../../server/app-render/types'
import { CacheStates } from '../../../shared/lib/app-router-context.shared-runtime'
import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime' import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime'
import { createInitialRouterState } from './create-initial-router-state' import { createInitialRouterState } from './create-initial-router-state'
...@@ -56,7 +55,6 @@ describe('createInitialRouterState', () => { ...@@ -56,7 +55,6 @@ describe('createInitialRouterState', () => {
}) })
const expectedCache: CacheNode = { const expectedCache: CacheNode = {
status: CacheStates.READY,
data: null, data: null,
subTreeData: children, subTreeData: children,
parallelRoutes: new Map([ parallelRoutes: new Map([
...@@ -66,7 +64,6 @@ describe('createInitialRouterState', () => { ...@@ -66,7 +64,6 @@ describe('createInitialRouterState', () => {
[ [
'linking', 'linking',
{ {
status: CacheStates.LAZY_INITIALIZED,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -74,7 +71,6 @@ describe('createInitialRouterState', () => { ...@@ -74,7 +71,6 @@ describe('createInitialRouterState', () => {
[ [
'', '',
{ {
status: CacheStates.LAZY_INITIALIZED,
data: null, data: null,
subTreeData: null, subTreeData: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
......
...@@ -5,7 +5,6 @@ import type { ...@@ -5,7 +5,6 @@ import type {
CacheNodeSeedData, CacheNodeSeedData,
} from '../../../server/app-render/types' } from '../../../server/app-render/types'
import { CacheStates } from '../../../shared/lib/app-router-context.shared-runtime'
import { createHrefFromUrl } from './create-href-from-url' import { createHrefFromUrl } from './create-href-from-url'
import { fillLazyItemsTillLeafWithHead } from './fill-lazy-items-till-leaf-with-head' import { fillLazyItemsTillLeafWithHead } from './fill-lazy-items-till-leaf-with-head'
import { extractPathFromFlightRouterState } from './compute-changed-path' import { extractPathFromFlightRouterState } from './compute-changed-path'
...@@ -34,7 +33,6 @@ export function createInitialRouterState({ ...@@ -34,7 +33,6 @@ export function createInitialRouterState({
const subTreeData = initialSeedData[2] const subTreeData = initialSeedData[2]
const cache: CacheNode = { const cache: CacheNode = {
status: CacheStates.READY,
data: null, data: null,
subTreeData: subTreeData, subTreeData: subTreeData,
// 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.
......
import React from 'react' import React from 'react'
import type { FetchServerResponseResult } from './fetch-server-response' import type { FetchServerResponseResult } from './fetch-server-response'
import { fillCacheWithDataProperty } from './fill-cache-with-data-property' import { fillCacheWithDataProperty } from './fill-cache-with-data-property'
import { CacheStates } from '../../../shared/lib/app-router-context.shared-runtime'
import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime' import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime'
describe('fillCacheWithDataProperty', () => { describe('fillCacheWithDataProperty', () => {
...@@ -23,14 +22,12 @@ describe('fillCacheWithDataProperty', () => { ...@@ -23,14 +22,12 @@ describe('fillCacheWithDataProperty', () => {
.flat() .flat()
const cache: CacheNode = { const cache: CacheNode = {
status: CacheStates.LAZY_INITIALIZED,
data: null, data: null,
subTreeData: null, subTreeData: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
} }
const existingCache: CacheNode = { const existingCache: CacheNode = {
data: null, data: null,
status: CacheStates.READY,
subTreeData: <>Root layout</>, subTreeData: <>Root layout</>,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
...@@ -40,7 +37,6 @@ describe('fillCacheWithDataProperty', () => { ...@@ -40,7 +37,6 @@ describe('fillCacheWithDataProperty', () => {
'linking', 'linking',
{ {
data: null, data: null,
status: CacheStates.READY,
subTreeData: <>Linking</>, subTreeData: <>Linking</>,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
...@@ -50,7 +46,6 @@ describe('fillCacheWithDataProperty', () => { ...@@ -50,7 +46,6 @@ describe('fillCacheWithDataProperty', () => {
'', '',
{ {
data: null, data: null,
status: CacheStates.READY,
subTreeData: <>Page</>, subTreeData: <>Page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
...@@ -81,14 +76,12 @@ describe('fillCacheWithDataProperty', () => { ...@@ -81,14 +76,12 @@ describe('fillCacheWithDataProperty', () => {
"" => { "" => {
"data": null, "data": null,
"parallelRoutes": Map {}, "parallelRoutes": Map {},
"status": "READY",
"subTreeData": <React.Fragment> "subTreeData": <React.Fragment>
Page Page
</React.Fragment>, </React.Fragment>,
}, },
}, },
}, },
"status": "READY",
"subTreeData": <React.Fragment> "subTreeData": <React.Fragment>
Linking Linking
</React.Fragment>, </React.Fragment>,
...@@ -96,12 +89,10 @@ describe('fillCacheWithDataProperty', () => { ...@@ -96,12 +89,10 @@ describe('fillCacheWithDataProperty', () => {
"dashboard" => { "dashboard" => {
"data": Promise {}, "data": Promise {},
"parallelRoutes": Map {}, "parallelRoutes": Map {},
"status": "DATAFETCH",
"subTreeData": null, "subTreeData": null,
}, },
}, },
}, },
"status": "LAZYINITIALIZED",
"subTreeData": null, "subTreeData": null,
} }
`) `)
......
import type { FetchServerResponseResult } from './fetch-server-response' import type { FetchServerResponseResult } from './fetch-server-response'
import type { FlightSegmentPath } from '../../../server/app-render/types' import type { FlightSegmentPath } from '../../../server/app-render/types'
import { CacheStates } from '../../../shared/lib/app-router-context.shared-runtime'
import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime' import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime'
import { createRouterCacheKey } from './create-router-cache-key' import { createRouterCacheKey } from './create-router-cache-key'
...@@ -39,7 +38,6 @@ export function fillCacheWithDataProperty( ...@@ -39,7 +38,6 @@ export function fillCacheWithDataProperty(
childCacheNode === existingChildCacheNode childCacheNode === existingChildCacheNode
) { ) {
childSegmentMap.set(cacheKey, { childSegmentMap.set(cacheKey, {
status: CacheStates.DATA_FETCH,
data: fetchResponse(), data: fetchResponse(),
subTreeData: null, subTreeData: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
...@@ -52,7 +50,6 @@ export function fillCacheWithDataProperty( ...@@ -52,7 +50,6 @@ export function fillCacheWithDataProperty(
// Start fetch in the place where the existing cache doesn't have the data yet. // Start fetch in the place where the existing cache doesn't have the data yet.
if (!childCacheNode) { if (!childCacheNode) {
childSegmentMap.set(cacheKey, { childSegmentMap.set(cacheKey, {
status: CacheStates.DATA_FETCH,
data: fetchResponse(), data: fetchResponse(),
subTreeData: null, subTreeData: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
...@@ -63,7 +60,6 @@ export function fillCacheWithDataProperty( ...@@ -63,7 +60,6 @@ export function fillCacheWithDataProperty(
if (childCacheNode === existingChildCacheNode) { if (childCacheNode === existingChildCacheNode) {
childCacheNode = { childCacheNode = {
status: childCacheNode.status,
data: childCacheNode.data, data: childCacheNode.data,
subTreeData: childCacheNode.subTreeData, subTreeData: childCacheNode.subTreeData,
parallelRoutes: new Map(childCacheNode.parallelRoutes), parallelRoutes: new Map(childCacheNode.parallelRoutes),
......
import React from 'react' import React from 'react'
import { fillCacheWithNewSubTreeData } from './fill-cache-with-new-subtree-data' import { fillCacheWithNewSubTreeData } from './fill-cache-with-new-subtree-data'
import { CacheStates } from '../../../shared/lib/app-router-context.shared-runtime'
import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime' import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime'
import type { FlightData } from '../../../server/app-render/types' import type { FlightData } from '../../../server/app-render/types'
...@@ -28,14 +27,12 @@ const getFlightData = (): FlightData => { ...@@ -28,14 +27,12 @@ const getFlightData = (): FlightData => {
describe('fillCacheWithNewSubtreeData', () => { describe('fillCacheWithNewSubtreeData', () => {
it('should apply subTreeData and head property', () => { it('should apply subTreeData and head property', () => {
const cache: CacheNode = { const cache: CacheNode = {
status: CacheStates.LAZY_INITIALIZED,
data: null, data: null,
subTreeData: null, subTreeData: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
} }
const existingCache: CacheNode = { const existingCache: CacheNode = {
data: null, data: null,
status: CacheStates.READY,
subTreeData: <>Root layout</>, subTreeData: <>Root layout</>,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
...@@ -45,7 +42,6 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -45,7 +42,6 @@ describe('fillCacheWithNewSubtreeData', () => {
'linking', 'linking',
{ {
data: null, data: null,
status: CacheStates.READY,
subTreeData: <>Linking</>, subTreeData: <>Linking</>,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
...@@ -55,7 +51,6 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -55,7 +51,6 @@ describe('fillCacheWithNewSubtreeData', () => {
'', '',
{ {
data: null, data: null,
status: CacheStates.READY,
subTreeData: <>Page</>, subTreeData: <>Page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
...@@ -83,7 +78,6 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -83,7 +78,6 @@ describe('fillCacheWithNewSubtreeData', () => {
const expectedCache: CacheNode = { const expectedCache: CacheNode = {
data: null, data: null,
status: CacheStates.LAZY_INITIALIZED,
subTreeData: null, subTreeData: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
...@@ -93,7 +87,6 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -93,7 +87,6 @@ describe('fillCacheWithNewSubtreeData', () => {
'linking', 'linking',
{ {
data: null, data: null,
status: CacheStates.READY,
subTreeData: <>Linking</>, subTreeData: <>Linking</>,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
...@@ -104,7 +97,6 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -104,7 +97,6 @@ describe('fillCacheWithNewSubtreeData', () => {
'', '',
{ {
data: null, data: null,
status: CacheStates.READY,
subTreeData: <>Page</>, subTreeData: <>Page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
...@@ -121,7 +113,6 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -121,7 +113,6 @@ describe('fillCacheWithNewSubtreeData', () => {
'', '',
{ {
data: null, data: null,
status: CacheStates.LAZY_INITIALIZED,
subTreeData: null, subTreeData: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
head: ( head: (
...@@ -135,7 +126,6 @@ describe('fillCacheWithNewSubtreeData', () => { ...@@ -135,7 +126,6 @@ describe('fillCacheWithNewSubtreeData', () => {
], ],
]), ]),
subTreeData: <h1>SubTreeData Injected!</h1>, subTreeData: <h1>SubTreeData Injected!</h1>,
status: CacheStates.READY,
}, },
], ],
]), ]),
......
import { CacheStates } from '../../../shared/lib/app-router-context.shared-runtime'
import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime' import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime'
import type { import type {
FlightDataPath, FlightDataPath,
...@@ -49,7 +48,6 @@ export function fillCacheWithNewSubTreeData( ...@@ -49,7 +48,6 @@ export function fillCacheWithNewSubTreeData(
const seedData: CacheNodeSeedData = flightDataPath[3] const seedData: CacheNodeSeedData = flightDataPath[3]
const subTreeData = seedData[2] const subTreeData = seedData[2]
childCacheNode = { childCacheNode = {
status: CacheStates.READY,
data: null, data: null,
subTreeData, subTreeData,
// Ensure segments other than the one we got data for are preserved. // Ensure segments other than the one we got data for are preserved.
...@@ -88,7 +86,6 @@ export function fillCacheWithNewSubTreeData( ...@@ -88,7 +86,6 @@ export function fillCacheWithNewSubTreeData(
if (childCacheNode === existingChildCacheNode) { if (childCacheNode === existingChildCacheNode) {
childCacheNode = { childCacheNode = {
status: childCacheNode.status,
data: childCacheNode.data, data: childCacheNode.data,
subTreeData: childCacheNode.subTreeData, subTreeData: childCacheNode.subTreeData,
parallelRoutes: new Map(childCacheNode.parallelRoutes), parallelRoutes: new Map(childCacheNode.parallelRoutes),
......
import React from 'react' import React from 'react'
import { fillLazyItemsTillLeafWithHead } from './fill-lazy-items-till-leaf-with-head' import { fillLazyItemsTillLeafWithHead } from './fill-lazy-items-till-leaf-with-head'
import { CacheStates } from '../../../shared/lib/app-router-context.shared-runtime'
import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime' import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime'
import type { FlightData } from '../../../server/app-render/types' import type { FlightData } from '../../../server/app-render/types'
...@@ -37,14 +36,12 @@ const getFlightData = (): FlightData => { ...@@ -37,14 +36,12 @@ const getFlightData = (): FlightData => {
describe('fillLazyItemsTillLeafWithHead', () => { describe('fillLazyItemsTillLeafWithHead', () => {
it('should fill lazy items till leaf with head', () => { it('should fill lazy items till leaf with head', () => {
const cache: CacheNode = { const cache: CacheNode = {
status: CacheStates.LAZY_INITIALIZED,
data: null, data: null,
subTreeData: null, subTreeData: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
} }
const existingCache: CacheNode = { const existingCache: CacheNode = {
data: null, data: null,
status: CacheStates.READY,
subTreeData: <>Root layout</>, subTreeData: <>Root layout</>,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
...@@ -54,7 +51,6 @@ describe('fillLazyItemsTillLeafWithHead', () => { ...@@ -54,7 +51,6 @@ describe('fillLazyItemsTillLeafWithHead', () => {
'linking', 'linking',
{ {
data: null, data: null,
status: CacheStates.READY,
subTreeData: <>Linking</>, subTreeData: <>Linking</>,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
...@@ -64,7 +60,6 @@ describe('fillLazyItemsTillLeafWithHead', () => { ...@@ -64,7 +60,6 @@ describe('fillLazyItemsTillLeafWithHead', () => {
'', '',
{ {
data: null, data: null,
status: CacheStates.READY,
subTreeData: <>Page</>, subTreeData: <>Page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
...@@ -98,7 +93,6 @@ describe('fillLazyItemsTillLeafWithHead', () => { ...@@ -98,7 +93,6 @@ describe('fillLazyItemsTillLeafWithHead', () => {
const expectedCache: CacheNode = { const expectedCache: CacheNode = {
data: null, data: null,
status: CacheStates.LAZY_INITIALIZED,
subTreeData: null, subTreeData: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
...@@ -108,7 +102,6 @@ describe('fillLazyItemsTillLeafWithHead', () => { ...@@ -108,7 +102,6 @@ describe('fillLazyItemsTillLeafWithHead', () => {
'linking', 'linking',
{ {
data: null, data: null,
status: CacheStates.LAZY_INITIALIZED,
subTreeData: null, subTreeData: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
...@@ -126,7 +119,6 @@ describe('fillLazyItemsTillLeafWithHead', () => { ...@@ -126,7 +119,6 @@ describe('fillLazyItemsTillLeafWithHead', () => {
'', '',
{ {
data: null, data: null,
status: CacheStates.LAZY_INITIALIZED,
subTreeData: null, subTreeData: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
head: ( head: (
...@@ -140,14 +132,12 @@ describe('fillLazyItemsTillLeafWithHead', () => { ...@@ -140,14 +132,12 @@ describe('fillLazyItemsTillLeafWithHead', () => {
], ],
]), ]),
subTreeData: null, subTreeData: null,
status: CacheStates.LAZY_INITIALIZED,
}, },
], ],
[ [
'', '',
{ {
data: null, data: null,
status: CacheStates.READY,
subTreeData: <>Page</>, subTreeData: <>Page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
......
import { CacheStates } from '../../../shared/lib/app-router-context.shared-runtime'
import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime' import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime'
import type { import type {
FlightRouterState, FlightRouterState,
...@@ -52,7 +51,6 @@ export function fillLazyItemsTillLeafWithHead( ...@@ -52,7 +51,6 @@ export function fillLazyItemsTillLeafWithHead(
// New data was sent from the server. // New data was sent from the server.
const seedNode = parallelSeedData[2] const seedNode = parallelSeedData[2]
newCacheNode = { newCacheNode = {
status: CacheStates.READY,
data: null, data: null,
subTreeData: seedNode, subTreeData: seedNode,
parallelRoutes: new Map(existingCacheNode?.parallelRoutes), parallelRoutes: new Map(existingCacheNode?.parallelRoutes),
...@@ -61,7 +59,6 @@ export function fillLazyItemsTillLeafWithHead( ...@@ -61,7 +59,6 @@ export function fillLazyItemsTillLeafWithHead(
// No new data was sent from the server, but the existing cache node // No new data was sent from the server, but the existing cache node
// was prefetched, so we should reuse that. // was prefetched, so we should reuse that.
newCacheNode = { newCacheNode = {
status: existingCacheNode.status,
data: existingCacheNode.data, data: existingCacheNode.data,
subTreeData: existingCacheNode.subTreeData, subTreeData: existingCacheNode.subTreeData,
parallelRoutes: new Map(existingCacheNode.parallelRoutes), parallelRoutes: new Map(existingCacheNode.parallelRoutes),
...@@ -70,7 +67,6 @@ export function fillLazyItemsTillLeafWithHead( ...@@ -70,7 +67,6 @@ export function fillLazyItemsTillLeafWithHead(
// No data available for this node. This will trigger a lazy fetch // No data available for this node. This will trigger a lazy fetch
// during render. // during render.
newCacheNode = { newCacheNode = {
status: CacheStates.LAZY_INITIALIZED,
data: null, data: null,
subTreeData: null, subTreeData: null,
parallelRoutes: new Map(existingCacheNode?.parallelRoutes), parallelRoutes: new Map(existingCacheNode?.parallelRoutes),
...@@ -99,7 +95,6 @@ export function fillLazyItemsTillLeafWithHead( ...@@ -99,7 +95,6 @@ export function fillLazyItemsTillLeafWithHead(
// New data was sent from the server. // New data was sent from the server.
const seedNode = parallelSeedData[2] const seedNode = parallelSeedData[2]
newCacheNode = { newCacheNode = {
status: CacheStates.READY,
data: null, data: null,
subTreeData: seedNode, subTreeData: seedNode,
parallelRoutes: new Map(), parallelRoutes: new Map(),
...@@ -108,7 +103,6 @@ export function fillLazyItemsTillLeafWithHead( ...@@ -108,7 +103,6 @@ export function fillLazyItemsTillLeafWithHead(
// No data available for this node. This will trigger a lazy fetch // No data available for this node. This will trigger a lazy fetch
// during render. // during render.
newCacheNode = { newCacheNode = {
status: CacheStates.LAZY_INITIALIZED,
data: null, data: null,
subTreeData: null, subTreeData: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
......
import React from 'react' import React from 'react'
import type { FlightData } from '../../../server/app-render/types' import type { FlightData } from '../../../server/app-render/types'
import { invalidateCacheBelowFlightSegmentPath } from './invalidate-cache-below-flight-segmentpath' import { invalidateCacheBelowFlightSegmentPath } from './invalidate-cache-below-flight-segmentpath'
import { CacheStates } from '../../../shared/lib/app-router-context.shared-runtime'
import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime' import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime'
import { fillCacheWithNewSubTreeData } from './fill-cache-with-new-subtree-data' import { fillCacheWithNewSubTreeData } from './fill-cache-with-new-subtree-data'
...@@ -29,14 +28,12 @@ const getFlightData = (): FlightData => { ...@@ -29,14 +28,12 @@ const getFlightData = (): FlightData => {
describe('invalidateCacheBelowFlightSegmentPath', () => { describe('invalidateCacheBelowFlightSegmentPath', () => {
it('should invalidate cache below flight segment path', () => { it('should invalidate cache below flight segment path', () => {
const cache: CacheNode = { const cache: CacheNode = {
status: CacheStates.LAZY_INITIALIZED,
data: null, data: null,
subTreeData: null, subTreeData: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
} }
const existingCache: CacheNode = { const existingCache: CacheNode = {
data: null, data: null,
status: CacheStates.READY,
subTreeData: <>Root layout</>, subTreeData: <>Root layout</>,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
...@@ -46,7 +43,6 @@ describe('invalidateCacheBelowFlightSegmentPath', () => { ...@@ -46,7 +43,6 @@ describe('invalidateCacheBelowFlightSegmentPath', () => {
'linking', 'linking',
{ {
data: null, data: null,
status: CacheStates.READY,
subTreeData: <>Linking</>, subTreeData: <>Linking</>,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
...@@ -56,7 +52,6 @@ describe('invalidateCacheBelowFlightSegmentPath', () => { ...@@ -56,7 +52,6 @@ describe('invalidateCacheBelowFlightSegmentPath', () => {
'', '',
{ {
data: null, data: null,
status: CacheStates.READY,
subTreeData: <>Page</>, subTreeData: <>Page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
...@@ -81,10 +76,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => { ...@@ -81,10 +76,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => {
const flightDataPath = flightData[0] const flightDataPath = flightData[0]
const flightSegmentPath = flightDataPath.slice(0, -3) const flightSegmentPath = flightDataPath.slice(0, -3)
// @ts-expect-error TODO-APP: investigate why this is not a TS error in router-reducer.
cache.status = CacheStates.READY
// Copy subTreeData for the root node of the cache. // Copy subTreeData for the root node of the cache.
// @ts-expect-error TODO-APP: investigate why this is not a TS error in router-reducer.
cache.subTreeData = existingCache.subTreeData cache.subTreeData = existingCache.subTreeData
// Create a copy of the existing cache with the subTreeData applied. // Create a copy of the existing cache with the subTreeData applied.
fillCacheWithNewSubTreeData(cache, existingCache, flightDataPath, false) fillCacheWithNewSubTreeData(cache, existingCache, flightDataPath, false)
...@@ -115,21 +107,18 @@ describe('invalidateCacheBelowFlightSegmentPath', () => { ...@@ -115,21 +107,18 @@ describe('invalidateCacheBelowFlightSegmentPath', () => {
{ {
data: null, data: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
status: CacheStates.READY,
subTreeData: <React.Fragment>Page</React.Fragment>, subTreeData: <React.Fragment>Page</React.Fragment>,
}, },
], ],
]), ]),
], ],
]), ]),
status: CacheStates.READY,
subTreeData: <React.Fragment>Linking</React.Fragment>, subTreeData: <React.Fragment>Linking</React.Fragment>,
}, },
], ],
]), ]),
], ],
]), ]),
status: CacheStates.READY,
subTreeData: <>Root layout</>, subTreeData: <>Root layout</>,
} }
......
...@@ -47,7 +47,6 @@ export function invalidateCacheBelowFlightSegmentPath( ...@@ -47,7 +47,6 @@ export function invalidateCacheBelowFlightSegmentPath(
if (childCacheNode === existingChildCacheNode) { if (childCacheNode === existingChildCacheNode) {
childCacheNode = { childCacheNode = {
status: childCacheNode.status,
data: childCacheNode.data, data: childCacheNode.data,
subTreeData: childCacheNode.subTreeData, subTreeData: childCacheNode.subTreeData,
parallelRoutes: new Map(childCacheNode.parallelRoutes), parallelRoutes: new Map(childCacheNode.parallelRoutes),
......
import React from 'react' import React from 'react'
import { invalidateCacheByRouterState } from './invalidate-cache-by-router-state' import { invalidateCacheByRouterState } from './invalidate-cache-by-router-state'
import { CacheStates } from '../../../shared/lib/app-router-context.shared-runtime'
import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime' import type { CacheNode } from '../../../shared/lib/app-router-context.shared-runtime'
import type { FlightRouterState } from '../../../server/app-render/types' import type { FlightRouterState } from '../../../server/app-render/types'
describe('invalidateCacheByRouterState', () => { describe('invalidateCacheByRouterState', () => {
it('should invalidate the cache by router state', () => { it('should invalidate the cache by router state', () => {
const cache: CacheNode = { const cache: CacheNode = {
status: CacheStates.LAZY_INITIALIZED,
data: null, data: null,
subTreeData: null, subTreeData: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
} }
const existingCache: CacheNode = { const existingCache: CacheNode = {
data: null, data: null,
status: CacheStates.READY,
subTreeData: <>Root layout</>, subTreeData: <>Root layout</>,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
...@@ -24,7 +21,6 @@ describe('invalidateCacheByRouterState', () => { ...@@ -24,7 +21,6 @@ describe('invalidateCacheByRouterState', () => {
'linking', 'linking',
{ {
data: null, data: null,
status: CacheStates.READY,
subTreeData: <>Linking</>, subTreeData: <>Linking</>,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
...@@ -34,7 +30,6 @@ describe('invalidateCacheByRouterState', () => { ...@@ -34,7 +30,6 @@ describe('invalidateCacheByRouterState', () => {
'', '',
{ {
data: null, data: null,
status: CacheStates.READY,
subTreeData: <>Page</>, subTreeData: <>Page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
}, },
...@@ -73,7 +68,6 @@ describe('invalidateCacheByRouterState', () => { ...@@ -73,7 +68,6 @@ describe('invalidateCacheByRouterState', () => {
const expectedCache: CacheNode = { const expectedCache: CacheNode = {
data: null, data: null,
status: CacheStates.LAZY_INITIALIZED,
subTreeData: null, subTreeData: null,
parallelRoutes: new Map([['children', new Map()]]), parallelRoutes: new Map([['children', new Map()]]),
} }
......
import React from 'react' import React from 'react'
import type { FlightRouterState } from '../../../../server/app-render/types' import type { FlightRouterState } from '../../../../server/app-render/types'
import { CacheStates } from '../../../../shared/lib/app-router-context.shared-runtime'
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'
...@@ -28,7 +27,6 @@ describe('findHeadInCache', () => { ...@@ -28,7 +27,6 @@ describe('findHeadInCache', () => {
const cache: CacheNode = { const cache: CacheNode = {
data: null, data: null,
status: CacheStates.LAZY_INITIALIZED,
subTreeData: null, subTreeData: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
...@@ -38,7 +36,6 @@ describe('findHeadInCache', () => { ...@@ -38,7 +36,6 @@ describe('findHeadInCache', () => {
'linking', 'linking',
{ {
data: null, data: null,
status: CacheStates.LAZY_INITIALIZED,
subTreeData: null, subTreeData: null,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
...@@ -56,7 +53,6 @@ describe('findHeadInCache', () => { ...@@ -56,7 +53,6 @@ describe('findHeadInCache', () => {
'', '',
{ {
data: null, data: null,
status: CacheStates.LAZY_INITIALIZED,
subTreeData: null, subTreeData: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
head: ( head: (
...@@ -70,7 +66,6 @@ describe('findHeadInCache', () => { ...@@ -70,7 +66,6 @@ describe('findHeadInCache', () => {
], ],
]), ]),
subTreeData: null, subTreeData: null,
status: CacheStates.LAZY_INITIALIZED,
}, },
], ],
// TODO-APP: this segment should be preserved when creating the new cache // TODO-APP: this segment should be preserved when creating the new cache
...@@ -78,7 +73,6 @@ describe('findHeadInCache', () => { ...@@ -78,7 +73,6 @@ describe('findHeadInCache', () => {
// '', // '',
// { // {
// data: null, // data: null,
// status: CacheStates.READY,
// subTreeData: <>Page</>, // subTreeData: <>Page</>,
// parallelRoutes: new Map(), // parallelRoutes: new Map(),
// }, // },
......
import { CacheStates } from '../../../../shared/lib/app-router-context.shared-runtime'
import type { CacheNode } from '../../../../shared/lib/app-router-context.shared-runtime' import type { CacheNode } from '../../../../shared/lib/app-router-context.shared-runtime'
import type { import type {
FlightRouterState, FlightRouterState,
...@@ -78,7 +77,6 @@ function addRefetchToLeafSegments( ...@@ -78,7 +77,6 @@ function addRefetchToLeafSegments(
) { ) {
let appliedPatch = false let appliedPatch = false
newCache.status = CacheStates.READY
newCache.subTreeData = currentCache.subTreeData newCache.subTreeData = currentCache.subTreeData
newCache.parallelRoutes = new Map(currentCache.parallelRoutes) newCache.parallelRoutes = new Map(currentCache.parallelRoutes)
...@@ -239,7 +237,6 @@ export function navigateReducer( ...@@ -239,7 +237,6 @@ export function navigateReducer(
) )
if (hardNavigate) { if (hardNavigate) {
cache.status = CacheStates.READY
// Copy subTreeData for the root node of the cache. // Copy subTreeData for the root node of the cache.
cache.subTreeData = currentCache.subTreeData cache.subTreeData = currentCache.subTreeData
......
...@@ -2,7 +2,6 @@ import React from 'react' ...@@ -2,7 +2,6 @@ import React from 'react'
import type { fetchServerResponse as fetchServerResponseType } from '../fetch-server-response' import type { fetchServerResponse as fetchServerResponseType } from '../fetch-server-response'
import type { FlightData } from '../../../../server/app-render/types' import type { FlightData } from '../../../../server/app-render/types'
import type { FlightRouterState } from '../../../../server/app-render/types' import type { FlightRouterState } from '../../../../server/app-render/types'
import { CacheStates } from '../../../../shared/lib/app-router-context.shared-runtime'
import type { CacheNode } from '../../../../shared/lib/app-router-context.shared-runtime' import type { CacheNode } from '../../../../shared/lib/app-router-context.shared-runtime'
import { createInitialRouterState } from '../create-initial-router-state' import { createInitialRouterState } from '../create-initial-router-state'
import { ACTION_PREFETCH, PrefetchKind } from '../router-reducer-types' import { ACTION_PREFETCH, PrefetchKind } from '../router-reducer-types'
...@@ -87,7 +86,6 @@ describe('prefetchReducer', () => { ...@@ -87,7 +86,6 @@ describe('prefetchReducer', () => {
[ [
'linking', 'linking',
{ {
status: CacheStates.READY,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -95,7 +93,6 @@ describe('prefetchReducer', () => { ...@@ -95,7 +93,6 @@ describe('prefetchReducer', () => {
[ [
'', '',
{ {
status: CacheStates.READY,
data: null, data: null,
subTreeData: <>Linking page</>, subTreeData: <>Linking page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
...@@ -183,7 +180,6 @@ describe('prefetchReducer', () => { ...@@ -183,7 +180,6 @@ describe('prefetchReducer', () => {
}, },
canonicalUrl: '/linking', canonicalUrl: '/linking',
cache: { cache: {
status: CacheStates.READY,
data: null, data: null,
subTreeData: ( subTreeData: (
<html> <html>
...@@ -229,7 +225,6 @@ describe('prefetchReducer', () => { ...@@ -229,7 +225,6 @@ describe('prefetchReducer', () => {
[ [
'linking', 'linking',
{ {
status: CacheStates.READY,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -237,7 +232,6 @@ describe('prefetchReducer', () => { ...@@ -237,7 +232,6 @@ describe('prefetchReducer', () => {
[ [
'', '',
{ {
status: CacheStates.READY,
data: null, data: null,
subTreeData: <>Linking page</>, subTreeData: <>Linking page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
...@@ -339,7 +333,6 @@ describe('prefetchReducer', () => { ...@@ -339,7 +333,6 @@ describe('prefetchReducer', () => {
}, },
canonicalUrl: '/linking', canonicalUrl: '/linking',
cache: { cache: {
status: CacheStates.READY,
data: null, data: null,
subTreeData: ( subTreeData: (
<html> <html>
......
...@@ -2,7 +2,6 @@ import React from 'react' ...@@ -2,7 +2,6 @@ import React from 'react'
import type { fetchServerResponse } from '../fetch-server-response' import type { fetchServerResponse } from '../fetch-server-response'
import type { FlightData } from '../../../../server/app-render/types' import type { FlightData } from '../../../../server/app-render/types'
import type { FlightRouterState } from '../../../../server/app-render/types' import type { FlightRouterState } from '../../../../server/app-render/types'
import { CacheStates } from '../../../../shared/lib/app-router-context.shared-runtime'
import type { CacheNode } from '../../../../shared/lib/app-router-context.shared-runtime' import type { CacheNode } from '../../../../shared/lib/app-router-context.shared-runtime'
import { createInitialRouterState } from '../create-initial-router-state' import { createInitialRouterState } from '../create-initial-router-state'
import { ACTION_REFRESH } from '../router-reducer-types' import { ACTION_REFRESH } from '../router-reducer-types'
...@@ -98,7 +97,6 @@ describe('refreshReducer', () => { ...@@ -98,7 +97,6 @@ describe('refreshReducer', () => {
[ [
'linking', 'linking',
{ {
status: CacheStates.READY,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -106,7 +104,6 @@ describe('refreshReducer', () => { ...@@ -106,7 +104,6 @@ describe('refreshReducer', () => {
[ [
'', '',
{ {
status: CacheStates.READY,
data: null, data: null,
subTreeData: <>Linking page</>, subTreeData: <>Linking page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
...@@ -159,7 +156,6 @@ describe('refreshReducer', () => { ...@@ -159,7 +156,6 @@ describe('refreshReducer', () => {
canonicalUrl: '/linking', canonicalUrl: '/linking',
nextUrl: '/linking', nextUrl: '/linking',
cache: { cache: {
status: CacheStates.READY,
data: null, data: null,
subTreeData: ( subTreeData: (
<html> <html>
...@@ -176,7 +172,6 @@ describe('refreshReducer', () => { ...@@ -176,7 +172,6 @@ describe('refreshReducer', () => {
[ [
'linking', 'linking',
{ {
status: CacheStates.LAZY_INITIALIZED,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -184,7 +179,6 @@ describe('refreshReducer', () => { ...@@ -184,7 +179,6 @@ describe('refreshReducer', () => {
[ [
'', '',
{ {
status: CacheStates.LAZY_INITIALIZED,
data: null, data: null,
subTreeData: null, subTreeData: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
...@@ -241,7 +235,6 @@ describe('refreshReducer', () => { ...@@ -241,7 +235,6 @@ describe('refreshReducer', () => {
[ [
'linking', 'linking',
{ {
status: CacheStates.READY,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -249,7 +242,6 @@ describe('refreshReducer', () => { ...@@ -249,7 +242,6 @@ describe('refreshReducer', () => {
[ [
'', '',
{ {
status: CacheStates.READY,
data: null, data: null,
subTreeData: <>Linking page</>, subTreeData: <>Linking page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
...@@ -316,7 +308,6 @@ describe('refreshReducer', () => { ...@@ -316,7 +308,6 @@ describe('refreshReducer', () => {
canonicalUrl: '/linking', canonicalUrl: '/linking',
nextUrl: '/linking', nextUrl: '/linking',
cache: { cache: {
status: CacheStates.READY,
data: null, data: null,
subTreeData: ( subTreeData: (
<html> <html>
...@@ -333,7 +324,6 @@ describe('refreshReducer', () => { ...@@ -333,7 +324,6 @@ describe('refreshReducer', () => {
[ [
'linking', 'linking',
{ {
status: CacheStates.LAZY_INITIALIZED,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -341,7 +331,6 @@ describe('refreshReducer', () => { ...@@ -341,7 +331,6 @@ describe('refreshReducer', () => {
[ [
'', '',
{ {
status: CacheStates.LAZY_INITIALIZED,
data: null, data: null,
subTreeData: null, subTreeData: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
...@@ -398,7 +387,6 @@ describe('refreshReducer', () => { ...@@ -398,7 +387,6 @@ describe('refreshReducer', () => {
[ [
'linking', 'linking',
{ {
status: CacheStates.READY,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -406,7 +394,6 @@ describe('refreshReducer', () => { ...@@ -406,7 +394,6 @@ describe('refreshReducer', () => {
[ [
'', '',
{ {
status: CacheStates.READY,
data: null, data: null,
subTreeData: <>Linking page</>, subTreeData: <>Linking page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
...@@ -422,7 +409,6 @@ describe('refreshReducer', () => { ...@@ -422,7 +409,6 @@ describe('refreshReducer', () => {
[ [
'about', 'about',
{ {
status: CacheStates.READY,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -430,7 +416,6 @@ describe('refreshReducer', () => { ...@@ -430,7 +416,6 @@ describe('refreshReducer', () => {
[ [
'', '',
{ {
status: CacheStates.READY,
data: null, data: null,
subTreeData: <>About page</>, subTreeData: <>About page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
...@@ -497,7 +482,6 @@ describe('refreshReducer', () => { ...@@ -497,7 +482,6 @@ describe('refreshReducer', () => {
canonicalUrl: '/linking', canonicalUrl: '/linking',
nextUrl: '/linking', nextUrl: '/linking',
cache: { cache: {
status: CacheStates.READY,
data: null, data: null,
subTreeData: ( subTreeData: (
<html> <html>
...@@ -514,7 +498,6 @@ describe('refreshReducer', () => { ...@@ -514,7 +498,6 @@ describe('refreshReducer', () => {
[ [
'linking', 'linking',
{ {
status: CacheStates.LAZY_INITIALIZED,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -522,7 +505,6 @@ describe('refreshReducer', () => { ...@@ -522,7 +505,6 @@ describe('refreshReducer', () => {
[ [
'', '',
{ {
status: CacheStates.LAZY_INITIALIZED,
data: null, data: null,
subTreeData: null, subTreeData: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
...@@ -579,7 +561,6 @@ describe('refreshReducer', () => { ...@@ -579,7 +561,6 @@ describe('refreshReducer', () => {
[ [
'linking', 'linking',
{ {
status: CacheStates.READY,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -587,7 +568,6 @@ describe('refreshReducer', () => { ...@@ -587,7 +568,6 @@ describe('refreshReducer', () => {
[ [
'', '',
{ {
status: CacheStates.READY,
data: null, data: null,
subTreeData: <>Linking page</>, subTreeData: <>Linking page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
...@@ -603,7 +583,6 @@ describe('refreshReducer', () => { ...@@ -603,7 +583,6 @@ describe('refreshReducer', () => {
[ [
'about', 'about',
{ {
status: CacheStates.READY,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -611,7 +590,6 @@ describe('refreshReducer', () => { ...@@ -611,7 +590,6 @@ describe('refreshReducer', () => {
[ [
'', '',
{ {
status: CacheStates.READY,
data: null, data: null,
subTreeData: <>About page</>, subTreeData: <>About page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
...@@ -727,7 +705,6 @@ describe('refreshReducer', () => { ...@@ -727,7 +705,6 @@ describe('refreshReducer', () => {
canonicalUrl: '/linking', canonicalUrl: '/linking',
nextUrl: '/linking', nextUrl: '/linking',
cache: { cache: {
status: CacheStates.READY,
data: null, data: null,
subTreeData: ( subTreeData: (
<html> <html>
...@@ -744,7 +721,6 @@ describe('refreshReducer', () => { ...@@ -744,7 +721,6 @@ describe('refreshReducer', () => {
[ [
'linking', 'linking',
{ {
status: CacheStates.LAZY_INITIALIZED,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -752,7 +728,6 @@ describe('refreshReducer', () => { ...@@ -752,7 +728,6 @@ describe('refreshReducer', () => {
[ [
'', '',
{ {
status: CacheStates.LAZY_INITIALIZED,
data: null, data: null,
subTreeData: null, subTreeData: null,
parallelRoutes: new Map(), parallelRoutes: new Map(),
......
...@@ -10,10 +10,7 @@ import type { ...@@ -10,10 +10,7 @@ import type {
} from '../router-reducer-types' } from '../router-reducer-types'
import { handleExternalUrl } from './navigate-reducer' import { handleExternalUrl } from './navigate-reducer'
import { handleMutable } from '../handle-mutable' import { handleMutable } from '../handle-mutable'
import { import type { CacheNode } from '../../../../shared/lib/app-router-context.shared-runtime'
CacheStates,
type CacheNode,
} from '../../../../shared/lib/app-router-context.shared-runtime'
import { fillLazyItemsTillLeafWithHead } from '../fill-lazy-items-till-leaf-with-head' import { fillLazyItemsTillLeafWithHead } from '../fill-lazy-items-till-leaf-with-head'
import { createEmptyCacheNode } from '../../app-router' import { createEmptyCacheNode } from '../../app-router'
...@@ -98,7 +95,6 @@ export function refreshReducer( ...@@ -98,7 +95,6 @@ export function refreshReducer(
// Handles case where prefetch only returns the router tree patch without rendered components. // Handles case where prefetch only returns the router tree patch without rendered components.
if (cacheNodeSeedData !== null) { if (cacheNodeSeedData !== null) {
const subTreeData = cacheNodeSeedData[2] const subTreeData = cacheNodeSeedData[2]
cache.status = CacheStates.READY
cache.subTreeData = subTreeData cache.subTreeData = subTreeData
fillLazyItemsTillLeafWithHead( fillLazyItemsTillLeafWithHead(
cache, cache,
......
import React from 'react' import React from 'react'
import type { FlightRouterState } from '../../../../server/app-render/types' import type { FlightRouterState } from '../../../../server/app-render/types'
import { CacheStates } from '../../../../shared/lib/app-router-context.shared-runtime'
import type { CacheNode } from '../../../../shared/lib/app-router-context.shared-runtime' import type { CacheNode } from '../../../../shared/lib/app-router-context.shared-runtime'
import { createInitialRouterState } from '../create-initial-router-state' import { createInitialRouterState } from '../create-initial-router-state'
import { ACTION_RESTORE } from '../router-reducer-types' import { ACTION_RESTORE } from '../router-reducer-types'
...@@ -54,7 +53,6 @@ describe('serverPatchReducer', () => { ...@@ -54,7 +53,6 @@ describe('serverPatchReducer', () => {
[ [
'linking', 'linking',
{ {
status: CacheStates.READY,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -62,7 +60,6 @@ describe('serverPatchReducer', () => { ...@@ -62,7 +60,6 @@ describe('serverPatchReducer', () => {
[ [
'', '',
{ {
status: CacheStates.READY,
data: null, data: null,
subTreeData: <>Linking page</>, subTreeData: <>Linking page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
...@@ -134,7 +131,6 @@ describe('serverPatchReducer', () => { ...@@ -134,7 +131,6 @@ describe('serverPatchReducer', () => {
canonicalUrl: '/linking/about', canonicalUrl: '/linking/about',
nextUrl: '/linking/about', nextUrl: '/linking/about',
cache: { cache: {
status: CacheStates.READY,
data: null, data: null,
subTreeData: ( subTreeData: (
<html> <html>
...@@ -149,7 +145,6 @@ describe('serverPatchReducer', () => { ...@@ -149,7 +145,6 @@ describe('serverPatchReducer', () => {
[ [
'linking', 'linking',
{ {
status: CacheStates.READY,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -157,7 +152,6 @@ describe('serverPatchReducer', () => { ...@@ -157,7 +152,6 @@ describe('serverPatchReducer', () => {
[ [
'', '',
{ {
status: CacheStates.READY,
data: null, data: null,
subTreeData: <>Linking page</>, subTreeData: <>Linking page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
...@@ -209,7 +203,6 @@ describe('serverPatchReducer', () => { ...@@ -209,7 +203,6 @@ describe('serverPatchReducer', () => {
[ [
'linking', 'linking',
{ {
status: CacheStates.READY,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -217,7 +210,6 @@ describe('serverPatchReducer', () => { ...@@ -217,7 +210,6 @@ describe('serverPatchReducer', () => {
[ [
'', '',
{ {
status: CacheStates.READY,
data: null, data: null,
subTreeData: <>Linking page</>, subTreeData: <>Linking page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
...@@ -302,7 +294,6 @@ describe('serverPatchReducer', () => { ...@@ -302,7 +294,6 @@ describe('serverPatchReducer', () => {
canonicalUrl: '/linking/about', canonicalUrl: '/linking/about',
nextUrl: '/linking/about', nextUrl: '/linking/about',
cache: { cache: {
status: CacheStates.READY,
data: null, data: null,
subTreeData: ( subTreeData: (
<html> <html>
...@@ -317,7 +308,6 @@ describe('serverPatchReducer', () => { ...@@ -317,7 +308,6 @@ describe('serverPatchReducer', () => {
[ [
'linking', 'linking',
{ {
status: CacheStates.READY,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -325,7 +315,6 @@ describe('serverPatchReducer', () => { ...@@ -325,7 +315,6 @@ describe('serverPatchReducer', () => {
[ [
'', '',
{ {
status: CacheStates.READY,
data: null, data: null,
subTreeData: <>Linking page</>, subTreeData: <>Linking page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
......
...@@ -33,10 +33,7 @@ import { createHrefFromUrl } from '../create-href-from-url' ...@@ -33,10 +33,7 @@ import { createHrefFromUrl } from '../create-href-from-url'
import { handleExternalUrl } from './navigate-reducer' import { handleExternalUrl } from './navigate-reducer'
import { applyRouterStatePatchToTree } from '../apply-router-state-patch-to-tree' import { applyRouterStatePatchToTree } from '../apply-router-state-patch-to-tree'
import { isNavigatingToNewRootLayout } from '../is-navigating-to-new-root-layout' import { isNavigatingToNewRootLayout } from '../is-navigating-to-new-root-layout'
import { import type { CacheNode } from '../../../../shared/lib/app-router-context.shared-runtime'
CacheStates,
type CacheNode,
} from '../../../../shared/lib/app-router-context.shared-runtime'
import { handleMutable } from '../handle-mutable' import { handleMutable } from '../handle-mutable'
import { fillLazyItemsTillLeafWithHead } from '../fill-lazy-items-till-leaf-with-head' import { fillLazyItemsTillLeafWithHead } from '../fill-lazy-items-till-leaf-with-head'
import { createEmptyCacheNode } from '../../app-router' import { createEmptyCacheNode } from '../../app-router'
...@@ -247,7 +244,6 @@ export function serverActionReducer( ...@@ -247,7 +244,6 @@ export function serverActionReducer(
// Handles case where prefetch only returns the router tree patch without rendered components. // Handles case where prefetch only returns the router tree patch without rendered components.
if (subTreeData !== null) { if (subTreeData !== null) {
const cache: CacheNode = createEmptyCacheNode() const cache: CacheNode = createEmptyCacheNode()
cache.status = CacheStates.READY
cache.subTreeData = subTreeData cache.subTreeData = subTreeData
fillLazyItemsTillLeafWithHead( fillLazyItemsTillLeafWithHead(
cache, cache,
......
...@@ -4,7 +4,6 @@ import type { ...@@ -4,7 +4,6 @@ import type {
FlightData, FlightData,
FlightRouterState, FlightRouterState,
} from '../../../../server/app-render/types' } from '../../../../server/app-render/types'
import { CacheStates } from '../../../../shared/lib/app-router-context.shared-runtime'
import type { CacheNode } from '../../../../shared/lib/app-router-context.shared-runtime' import type { CacheNode } from '../../../../shared/lib/app-router-context.shared-runtime'
import { createInitialRouterState } from '../create-initial-router-state' import { createInitialRouterState } from '../create-initial-router-state'
import { ACTION_SERVER_PATCH, ACTION_NAVIGATE } from '../router-reducer-types' import { ACTION_SERVER_PATCH, ACTION_NAVIGATE } from '../router-reducer-types'
...@@ -105,7 +104,6 @@ describe('serverPatchReducer', () => { ...@@ -105,7 +104,6 @@ describe('serverPatchReducer', () => {
[ [
'linking', 'linking',
{ {
status: CacheStates.READY,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -113,7 +111,6 @@ describe('serverPatchReducer', () => { ...@@ -113,7 +111,6 @@ describe('serverPatchReducer', () => {
[ [
'', '',
{ {
status: CacheStates.READY,
data: null, data: null,
subTreeData: <>Linking page</>, subTreeData: <>Linking page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
...@@ -176,7 +173,6 @@ describe('serverPatchReducer', () => { ...@@ -176,7 +173,6 @@ describe('serverPatchReducer', () => {
"" => { "" => {
"data": null, "data": null,
"parallelRoutes": Map {}, "parallelRoutes": Map {},
"status": "READY",
"subTreeData": <React.Fragment> "subTreeData": <React.Fragment>
Linking page Linking page
</React.Fragment>, </React.Fragment>,
...@@ -193,26 +189,22 @@ describe('serverPatchReducer', () => { ...@@ -193,26 +189,22 @@ describe('serverPatchReducer', () => {
</title> </title>
</React.Fragment>, </React.Fragment>,
"parallelRoutes": Map {}, "parallelRoutes": Map {},
"status": "LAZYINITIALIZED",
"subTreeData": null, "subTreeData": null,
}, },
}, },
}, },
"status": "READY",
"subTreeData": <h1> "subTreeData": <h1>
Somewhere Page! Somewhere Page!
</h1>, </h1>,
}, },
}, },
}, },
"status": "READY",
"subTreeData": <React.Fragment> "subTreeData": <React.Fragment>
Linking layout level Linking layout level
</React.Fragment>, </React.Fragment>,
}, },
}, },
}, },
"status": "READY",
"subTreeData": <html> "subTreeData": <html>
<head /> <head />
<body> <body>
...@@ -276,7 +268,6 @@ describe('serverPatchReducer', () => { ...@@ -276,7 +268,6 @@ describe('serverPatchReducer', () => {
[ [
'linking', 'linking',
{ {
status: CacheStates.READY,
parallelRoutes: new Map([ parallelRoutes: new Map([
[ [
'children', 'children',
...@@ -284,7 +275,6 @@ describe('serverPatchReducer', () => { ...@@ -284,7 +275,6 @@ describe('serverPatchReducer', () => {
[ [
'', '',
{ {
status: CacheStates.READY,
data: null, data: null,
subTreeData: <>Linking page</>, subTreeData: <>Linking page</>,
parallelRoutes: new Map(), parallelRoutes: new Map(),
...@@ -359,7 +349,6 @@ describe('serverPatchReducer', () => { ...@@ -359,7 +349,6 @@ describe('serverPatchReducer', () => {
"" => { "" => {
"data": null, "data": null,
"parallelRoutes": Map {}, "parallelRoutes": Map {},
"status": "READY",
"subTreeData": <React.Fragment> "subTreeData": <React.Fragment>
Linking page Linking page
</React.Fragment>, </React.Fragment>,
...@@ -376,12 +365,10 @@ describe('serverPatchReducer', () => { ...@@ -376,12 +365,10 @@ describe('serverPatchReducer', () => {
</title> </title>
</React.Fragment>, </React.Fragment>,
"parallelRoutes": Map {}, "parallelRoutes": Map {},
"status": "LAZYINITIALIZED",
"subTreeData": null, "subTreeData": null,
}, },
}, },
}, },
"status": "READY",
"subTreeData": <h1> "subTreeData": <h1>
About Page! About Page!
</h1>, </h1>,
...@@ -398,26 +385,22 @@ describe('serverPatchReducer', () => { ...@@ -398,26 +385,22 @@ describe('serverPatchReducer', () => {
</title> </title>
</React.Fragment>, </React.Fragment>,
"parallelRoutes": Map {}, "parallelRoutes": Map {},
"status": "LAZYINITIALIZED",
"subTreeData": null, "subTreeData": null,
}, },
}, },
}, },
"status": "READY",
"subTreeData": <h1> "subTreeData": <h1>
Somewhere Page! Somewhere Page!
</h1>, </h1>,
}, },
}, },
}, },
"status": "READY",
"subTreeData": <React.Fragment> "subTreeData": <React.Fragment>
Linking layout level Linking layout level
</React.Fragment>, </React.Fragment>,
}, },
}, },
}, },
"status": "READY",
"subTreeData": <html> "subTreeData": <html>
<head /> <head />
<body> <body>
......
...@@ -13,59 +13,57 @@ import React from 'react' ...@@ -13,59 +13,57 @@ import React from 'react'
export type ChildSegmentMap = Map<string, CacheNode> export type ChildSegmentMap = Map<string, CacheNode>
// eslint-disable-next-line no-shadow
export enum CacheStates {
LAZY_INITIALIZED = 'LAZYINITIALIZED',
DATA_FETCH = 'DATAFETCH',
READY = 'READY',
}
/** /**
* Cache node used in app-router / layout-router. * Cache node used in app-router / layout-router.
*/ */
export type CacheNode = export type CacheNode = ReadyCacheNode | LazyCacheNode
| {
status: CacheStates.DATA_FETCH export type LazyCacheNode = {
/** /**
* In-flight request for this node. * When subtreeData is null, this is a lazily-initialized cache node.
*/ *
data: Promise<FetchServerResponseResult> | null * If the app attempts to render it, it triggers a lazy data fetch,
head?: React.ReactNode * postpones the render, and schedules an update to a new tree.
/** *
* React Component for this node. * TODO: This mechanism should not be used when PPR is enabled, though it
*/ * currently is in some cases until we've implemented partial
subTreeData: null * segment fetching.
/** */
* Child parallel routes. subTreeData: null
*/
parallelRoutes: Map<string, ChildSegmentMap> /**
} * A pending response for the lazy data fetch. If this is not present
| { * during render, it is lazily created.
status: CacheStates.READY */
/** data: Promise<FetchServerResponseResult> | null
* In-flight request for this node.
*/ head?: React.ReactNode
data: null /**
head?: React.ReactNode * Child parallel routes.
/** */
* React Component for this node. parallelRoutes: Map<string, ChildSegmentMap>
*/ }
subTreeData: React.ReactNode
/** export type ReadyCacheNode = {
* Child parallel routes. /**
*/ * When subtreeData is not null, it represents the RSC data for the
parallelRoutes: Map<string, ChildSegmentMap> * corresponding segment.
} *
| { * `null` is a valid React Node but because segment data is always a
status: CacheStates.LAZY_INITIALIZED * <LayoutRouter> component, we can use `null` to represent empty.
data: null *
head?: React.ReactNode * TODO: For additional type safety, update this type to
subTreeData: null * Exclude<React.ReactNode, null>. Need to update createEmptyCacheNode to
/** * accept subTreeData as an argument, or just inline the callers.
* Child parallel routes. */
*/ subTreeData: React.ReactNode
parallelRoutes: Map<string, ChildSegmentMap> /**
} * There should never be a pending data request in this case.
*/
data: null
head?: React.ReactNode
parallelRoutes: Map<string, ChildSegmentMap>
}
export interface NavigateOptions { export interface NavigateOptions {
scroll?: boolean scroll?: boolean
......
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