Unverified Commit 5e3bac5c authored by Zack Tanner's avatar Zack Tanner Committed by GitHub

Store loading data in CacheNode (#62346)

This changes how loading components are provided to `LayoutRouter` to instead be part of the `CacheNode`. This makes it so that we can copy it over/expire it in a similar way to the `data` property on a `CacheNode`. Consequently, this fixes a bug in PPR navigations, where 2 different loading states (the prefetched one, followed by the updated one) might be displayed upon navigating. 

Note: This disables a PPR test that asserts the loading data gets expired after 5 minutes. As implemented, the loading data will remain cached for a particular segment. 

<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the PR.
- Read the Docs Contribution Guide to ensure your contribution follows the docs guidelines: https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. (A discussion must be opened, see https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added (https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to understand the PR)
- When linking to a Slack thread, you might want to share details of the conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->


Closes NEXT-2557
parent 39a8429a
......@@ -186,6 +186,7 @@ export function createEmptyCacheNode(): CacheNode {
prefetchHead: null,
parallelRoutes: new Map(),
lazyDataResolved: false,
loading: null,
}
}
......@@ -683,6 +684,7 @@ function Router({
// Root node always has `url`
// Provided in AppTreeContext to ensure it can be overwritten in layout-router
url: canonicalUrl,
loading: cache.loading,
}}
>
{content}
......
......@@ -357,6 +357,7 @@ function InnerLayoutRouter({
prefetchHead: null,
parallelRoutes: new Map(),
lazyDataResolved: false,
loading: null,
}
/**
......@@ -451,6 +452,7 @@ function InnerLayoutRouter({
childNodes: childNode.parallelRoutes,
// TODO-APP: overriding of url for parallel routes
url: url,
loading: childNode.loading,
}}
>
{resolvedRsc}
......@@ -469,15 +471,13 @@ function LoadingBoundary({
loading,
loadingStyles,
loadingScripts,
hasLoading,
}: {
children: React.ReactNode
loading?: React.ReactNode
loadingStyles?: React.ReactNode
loadingScripts?: React.ReactNode
hasLoading: boolean
}): JSX.Element {
if (hasLoading) {
if (loading) {
return (
<Suspense
fallback={
......@@ -508,10 +508,6 @@ export default function OuterLayoutRouter({
errorScripts,
templateStyles,
templateScripts,
loading,
loadingStyles,
loadingScripts,
hasLoading,
template,
notFound,
notFoundStyles,
......@@ -525,10 +521,6 @@ export default function OuterLayoutRouter({
templateStyles: React.ReactNode | undefined
templateScripts: React.ReactNode | undefined
template: React.ReactNode
loading: React.ReactNode | undefined
loadingStyles: React.ReactNode | undefined
loadingScripts: React.ReactNode | undefined
hasLoading: boolean
notFound: React.ReactNode | undefined
notFoundStyles: React.ReactNode | undefined
styles?: React.ReactNode
......@@ -538,7 +530,7 @@ export default function OuterLayoutRouter({
throw new Error('invariant expected layout router to be mounted')
}
const { childNodes, tree, url } = context
const { childNodes, tree, url, loading } = context
// Get the current parallelRouter cache node
let childNodesForParallelRouter = childNodes.get(parallelRouterKey)
......@@ -589,10 +581,9 @@ export default function OuterLayoutRouter({
errorScripts={errorScripts}
>
<LoadingBoundary
hasLoading={hasLoading}
loading={loading}
loadingStyles={loadingStyles}
loadingScripts={loadingScripts}
loading={loading?.[0]}
loadingStyles={loading?.[1]}
loadingScripts={loading?.[2]}
>
<NotFoundBoundary
notFound={notFound}
......
......@@ -20,6 +20,8 @@ export function applyFlightData(
if (flightDataPath.length === 3) {
const rsc = cacheNodeSeedData[2]
const loading = cacheNodeSeedData[3]
cache.loading = loading
cache.rsc = rsc
// This is a PPR-only field. When PPR is enabled, we shouldn't hit
// this path during a navigation, but until PPR is fully implemented
......@@ -43,6 +45,7 @@ export function applyFlightData(
// PPR value, if it exists.
cache.prefetchRsc = existingCache.prefetchRsc
cache.parallelRoutes = new Map(existingCache.parallelRoutes)
cache.loading = existingCache.loading
// Create a copy of the existing cache with the rsc applied.
fillCacheWithNewSubTreeData(
cache,
......
......@@ -37,7 +37,7 @@ describe('createInitialRouterState', () => {
buildId,
initialTree,
initialCanonicalUrl,
initialSeedData: ['', {}, children],
initialSeedData: ['', {}, children, null],
initialParallelRoutes,
location: new URL('/linking', 'https://localhost') as any,
initialHead: <title>Test</title>,
......@@ -48,7 +48,7 @@ describe('createInitialRouterState', () => {
buildId,
initialTree,
initialCanonicalUrl,
initialSeedData: ['', {}, children],
initialSeedData: ['', {}, children, null],
initialParallelRoutes,
location: new URL('/linking', 'https://localhost') as any,
initialHead: <title>Test</title>,
......@@ -61,6 +61,7 @@ describe('createInitialRouterState', () => {
head: null,
prefetchHead: null,
lazyDataResolved: false,
loading: null,
parallelRoutes: new Map([
[
'children',
......@@ -79,6 +80,7 @@ describe('createInitialRouterState', () => {
rsc: null,
prefetchRsc: null,
parallelRoutes: new Map(),
loading: null,
head: <title>Test</title>,
prefetchHead: null,
lazyDataResolved: false,
......@@ -93,6 +95,7 @@ describe('createInitialRouterState', () => {
head: null,
prefetchHead: null,
lazyDataResolved: false,
loading: null,
},
],
]),
......
......@@ -45,6 +45,7 @@ export function createInitialRouterState({
// 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,
lazyDataResolved: false,
loading: initialSeedData[3],
}
const prefetchCache = new Map<string, PrefetchCacheEntry>()
......
......@@ -29,6 +29,7 @@ describe('fillCacheWithDataProperty', () => {
prefetchHead: null,
parallelRoutes: new Map(),
lazyDataResolved: false,
loading: null,
}
const existingCache: CacheNode = {
lazyData: null,
......@@ -37,6 +38,7 @@ describe('fillCacheWithDataProperty', () => {
head: null,
prefetchHead: null,
lazyDataResolved: false,
loading: null,
parallelRoutes: new Map([
[
'children',
......@@ -50,6 +52,7 @@ describe('fillCacheWithDataProperty', () => {
lazyDataResolved: false,
head: null,
prefetchHead: null,
loading: null,
parallelRoutes: new Map([
[
'children',
......@@ -64,6 +67,7 @@ describe('fillCacheWithDataProperty', () => {
prefetchHead: null,
parallelRoutes: new Map(),
lazyDataResolved: false,
loading: null,
},
],
]),
......@@ -85,18 +89,21 @@ describe('fillCacheWithDataProperty', () => {
"head": null,
"lazyData": null,
"lazyDataResolved": false,
"loading": null,
"parallelRoutes": Map {
"children" => Map {
"linking" => {
"head": null,
"lazyData": null,
"lazyDataResolved": false,
"loading": null,
"parallelRoutes": Map {
"children" => Map {
"" => {
"head": null,
"lazyData": null,
"lazyDataResolved": false,
"loading": null,
"parallelRoutes": Map {},
"prefetchHead": null,
"prefetchRsc": null,
......@@ -116,6 +123,7 @@ describe('fillCacheWithDataProperty', () => {
"head": null,
"lazyData": Promise {},
"lazyDataResolved": false,
"loading": null,
"parallelRoutes": Map {},
"prefetchHead": null,
"prefetchRsc": null,
......
......@@ -45,6 +45,7 @@ export function fillCacheWithDataProperty(
prefetchHead: null,
parallelRoutes: new Map(),
lazyDataResolved: false,
loading: null,
})
}
return
......@@ -61,6 +62,7 @@ export function fillCacheWithDataProperty(
prefetchHead: null,
parallelRoutes: new Map(),
lazyDataResolved: false,
loading: null,
})
}
return
......@@ -75,6 +77,7 @@ export function fillCacheWithDataProperty(
prefetchHead: childCacheNode.prefetchHead,
parallelRoutes: new Map(childCacheNode.parallelRoutes),
lazyDataResolved: childCacheNode.lazyDataResolved,
loading: childCacheNode.loading,
} as CacheNode
childSegmentMap.set(cacheKey, childCacheNode)
}
......
......@@ -32,6 +32,7 @@ describe('fillCacheWithNewSubtreeData', () => {
prefetchRsc: null,
head: null,
prefetchHead: null,
loading: null,
parallelRoutes: new Map(),
lazyDataResolved: false,
}
......@@ -42,6 +43,7 @@ describe('fillCacheWithNewSubtreeData', () => {
head: null,
prefetchHead: null,
lazyDataResolved: false,
loading: null,
parallelRoutes: new Map([
[
'children',
......@@ -55,6 +57,7 @@ describe('fillCacheWithNewSubtreeData', () => {
head: null,
prefetchHead: null,
lazyDataResolved: false,
loading: null,
parallelRoutes: new Map([
[
'children',
......@@ -68,6 +71,7 @@ describe('fillCacheWithNewSubtreeData', () => {
head: null,
prefetchHead: null,
lazyDataResolved: false,
loading: null,
parallelRoutes: new Map(),
},
],
......@@ -99,6 +103,7 @@ describe('fillCacheWithNewSubtreeData', () => {
head: null,
prefetchHead: null,
lazyDataResolved: false,
loading: null,
parallelRoutes: new Map([
[
'children',
......@@ -112,6 +117,7 @@ describe('fillCacheWithNewSubtreeData', () => {
head: null,
prefetchHead: null,
lazyDataResolved: false,
loading: null,
parallelRoutes: new Map([
[
'children',
......@@ -126,6 +132,7 @@ describe('fillCacheWithNewSubtreeData', () => {
head: null,
prefetchHead: null,
lazyDataResolved: false,
loading: null,
parallelRoutes: new Map(),
},
],
......@@ -136,6 +143,7 @@ describe('fillCacheWithNewSubtreeData', () => {
lazyDataResolved: false,
head: null,
prefetchHead: null,
loading: null,
parallelRoutes: new Map([
[
'children',
......@@ -148,6 +156,7 @@ describe('fillCacheWithNewSubtreeData', () => {
prefetchRsc: null,
parallelRoutes: new Map(),
prefetchHead: null,
loading: null,
head: (
<>
<title>Head Injected!</title>
......
......@@ -48,12 +48,14 @@ export function fillCacheWithNewSubTreeData(
) {
const seedData: CacheNodeSeedData = flightDataPath[3]
const rsc = seedData[2]
const loading = seedData[3]
childCacheNode = {
lazyData: null,
rsc,
prefetchRsc: null,
head: null,
prefetchHead: null,
loading,
// Ensure segments other than the one we got data for are preserved.
parallelRoutes: existingChildCacheNode
? new Map(existingChildCacheNode.parallelRoutes)
......@@ -98,6 +100,7 @@ export function fillCacheWithNewSubTreeData(
prefetchHead: childCacheNode.prefetchHead,
parallelRoutes: new Map(childCacheNode.parallelRoutes),
lazyDataResolved: false,
loading: childCacheNode.loading,
} as CacheNode
childSegmentMap.set(cacheKey, childCacheNode)
}
......
......@@ -43,6 +43,7 @@ describe('fillLazyItemsTillLeafWithHead', () => {
prefetchHead: null,
parallelRoutes: new Map(),
lazyDataResolved: false,
loading: null,
}
const existingCache: CacheNode = {
lazyData: null,
......@@ -51,6 +52,7 @@ describe('fillLazyItemsTillLeafWithHead', () => {
head: null,
prefetchHead: null,
lazyDataResolved: false,
loading: null,
parallelRoutes: new Map([
[
'children',
......@@ -64,6 +66,7 @@ describe('fillLazyItemsTillLeafWithHead', () => {
head: null,
prefetchHead: null,
lazyDataResolved: false,
loading: null,
parallelRoutes: new Map([
[
'children',
......@@ -77,6 +80,7 @@ describe('fillLazyItemsTillLeafWithHead', () => {
head: null,
prefetchHead: null,
lazyDataResolved: false,
loading: null,
parallelRoutes: new Map(),
},
],
......@@ -114,6 +118,7 @@ describe('fillLazyItemsTillLeafWithHead', () => {
head: null,
prefetchHead: null,
lazyDataResolved: false,
loading: null,
parallelRoutes: new Map([
[
'children',
......@@ -127,6 +132,7 @@ describe('fillLazyItemsTillLeafWithHead', () => {
head: null,
prefetchHead: null,
lazyDataResolved: false,
loading: null,
parallelRoutes: new Map([
[
'children',
......@@ -136,6 +142,7 @@ describe('fillLazyItemsTillLeafWithHead', () => {
{
lazyData: null,
lazyDataResolved: false,
loading: null,
parallelRoutes: new Map([
[
'children',
......@@ -147,6 +154,7 @@ describe('fillLazyItemsTillLeafWithHead', () => {
rsc: null,
prefetchRsc: null,
prefetchHead: null,
loading: null,
parallelRoutes: new Map(),
lazyDataResolved: false,
head: (
......@@ -173,6 +181,7 @@ describe('fillLazyItemsTillLeafWithHead', () => {
prefetchRsc: null,
head: null,
prefetchHead: null,
loading: null,
parallelRoutes: new Map(),
lazyDataResolved: false,
},
......
......@@ -56,6 +56,7 @@ export function fillLazyItemsTillLeafWithHead(
if (parallelSeedData !== null) {
// New data was sent from the server.
const seedNode = parallelSeedData[2]
const loading = parallelSeedData[3]
newCacheNode = {
lazyData: null,
rsc: seedNode,
......@@ -67,6 +68,7 @@ export function fillLazyItemsTillLeafWithHead(
prefetchRsc: null,
head: null,
prefetchHead: null,
loading,
parallelRoutes: new Map(existingCacheNode?.parallelRoutes),
lazyDataResolved: false,
}
......@@ -84,6 +86,7 @@ export function fillLazyItemsTillLeafWithHead(
prefetchHead: existingCacheNode.prefetchHead,
parallelRoutes: new Map(existingCacheNode.parallelRoutes),
lazyDataResolved: existingCacheNode.lazyDataResolved,
loading: existingCacheNode.loading,
} as CacheNode
} else {
// No data available for this node. This will trigger a lazy fetch
......@@ -96,6 +99,7 @@ export function fillLazyItemsTillLeafWithHead(
prefetchHead: null,
parallelRoutes: new Map(existingCacheNode?.parallelRoutes),
lazyDataResolved: false,
loading: null,
}
}
......@@ -120,6 +124,7 @@ export function fillLazyItemsTillLeafWithHead(
if (parallelSeedData !== null) {
// New data was sent from the server.
const seedNode = parallelSeedData[2]
const loading = parallelSeedData[3]
newCacheNode = {
lazyData: null,
rsc: seedNode,
......@@ -128,6 +133,7 @@ export function fillLazyItemsTillLeafWithHead(
prefetchHead: null,
parallelRoutes: new Map(),
lazyDataResolved: false,
loading,
}
} else {
// No data available for this node. This will trigger a lazy fetch
......@@ -140,6 +146,7 @@ export function fillLazyItemsTillLeafWithHead(
prefetchHead: null,
parallelRoutes: new Map(),
lazyDataResolved: false,
loading: null,
}
}
......
......@@ -33,6 +33,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => {
prefetchRsc: null,
head: null,
prefetchHead: null,
loading: null,
parallelRoutes: new Map(),
lazyDataResolved: false,
}
......@@ -43,6 +44,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => {
head: null,
prefetchHead: null,
lazyDataResolved: false,
loading: null,
parallelRoutes: new Map([
[
'children',
......@@ -56,6 +58,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => {
head: null,
prefetchHead: null,
lazyDataResolved: false,
loading: null,
parallelRoutes: new Map([
[
'children',
......@@ -69,6 +72,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => {
head: null,
prefetchHead: null,
lazyDataResolved: false,
loading: null,
parallelRoutes: new Map(),
},
],
......@@ -110,6 +114,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => {
lazyDataResolved: false,
head: null,
prefetchHead: null,
loading: null,
parallelRoutes: new Map([
[
'children',
......@@ -121,6 +126,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => {
lazyDataResolved: false,
head: null,
prefetchHead: null,
loading: null,
parallelRoutes: new Map([
[
'children',
......@@ -129,6 +135,7 @@ describe('invalidateCacheBelowFlightSegmentPath', () => {
'',
{
lazyData: null,
loading: null,
parallelRoutes: new Map(),
rsc: <React.Fragment>Page</React.Fragment>,
prefetchRsc: null,
......
......@@ -11,6 +11,7 @@ describe('invalidateCacheByRouterState', () => {
prefetchRsc: null,
head: null,
prefetchHead: null,
loading: null,
parallelRoutes: new Map(),
lazyDataResolved: false,
}
......@@ -21,6 +22,7 @@ describe('invalidateCacheByRouterState', () => {
head: null,
prefetchHead: null,
lazyDataResolved: false,
loading: null,
parallelRoutes: new Map([
[
'children',
......@@ -34,6 +36,7 @@ describe('invalidateCacheByRouterState', () => {
head: null,
prefetchHead: null,
lazyDataResolved: false,
loading: null,
parallelRoutes: new Map([
[
'children',
......@@ -47,6 +50,7 @@ describe('invalidateCacheByRouterState', () => {
head: null,
prefetchHead: null,
lazyDataResolved: false,
loading: null,
parallelRoutes: new Map(),
},
],
......@@ -89,6 +93,7 @@ describe('invalidateCacheByRouterState', () => {
head: null,
prefetchHead: null,
lazyDataResolved: false,
loading: null,
parallelRoutes: new Map([['children', new Map()]]),
}
......
......@@ -233,6 +233,7 @@ export function updateCacheNodeOnNavigation(
prefetchRsc: oldCacheNode.prefetchRsc,
head: oldCacheNode.head,
prefetchHead: oldCacheNode.prefetchHead,
loading: oldCacheNode.loading,
// Everything is cloned except for the children, which we computed above.
parallelRoutes: prefetchParallelRoutes,
......@@ -512,13 +513,14 @@ function createPendingCacheNode(
const isLeafSegment = parallelRoutes.size === 0
const maybePrefetchRsc = prefetchData !== null ? prefetchData[2] : null
const maybePrefetchLoading = prefetchData !== null ? prefetchData[3] : null
return {
lazyData: null,
parallelRoutes: parallelRoutes,
prefetchRsc: maybePrefetchRsc !== undefined ? maybePrefetchRsc : null,
prefetchHead: isLeafSegment ? prefetchHead : null,
loading: maybePrefetchLoading !== undefined ? maybePrefetchLoading : null,
// Create a deferred promise. This will be fulfilled once the dynamic
// response is received from the server.
......@@ -762,6 +764,7 @@ export function updateCacheNodeOnPopstateRestoration(
prefetchHead: shouldUsePrefetch ? oldCacheNode.prefetchHead : null,
prefetchRsc: shouldUsePrefetch ? oldCacheNode.prefetchRsc : null,
loading: shouldUsePrefetch ? oldCacheNode.loading : null,
// These are the cloned children we computed above
parallelRoutes: newParallelRoutes,
......
......@@ -32,6 +32,7 @@ describe('findHeadInCache', () => {
head: null,
prefetchHead: null,
lazyDataResolved: false,
loading: null,
parallelRoutes: new Map([
[
'children',
......@@ -45,6 +46,7 @@ describe('findHeadInCache', () => {
head: null,
prefetchHead: null,
lazyDataResolved: false,
loading: null,
parallelRoutes: new Map([
[
'children',
......@@ -56,6 +58,7 @@ describe('findHeadInCache', () => {
lazyDataResolved: false,
head: null,
prefetchHead: null,
loading: null,
parallelRoutes: new Map([
[
'children',
......@@ -68,6 +71,7 @@ describe('findHeadInCache', () => {
prefetchRsc: null,
prefetchHead: null,
lazyDataResolved: false,
loading: null,
parallelRoutes: new Map(),
head: (
<>
......
......@@ -536,6 +536,7 @@ async function ReactServerError({
<head></head>
<body></body>
</html>,
null,
]
return (
<AppRouter
......
......@@ -14,6 +14,7 @@ import { PARALLEL_ROUTE_DEFAULT_PATH } from '../../client/components/parallel-ro
import { getTracer } from '../lib/trace/tracer'
import { NextNodeServerSpan } from '../lib/trace/constants'
import { StaticGenBailoutError } from '../../client/components/static-generation-bailout'
import type { LoadingModuleData } from '../../shared/lib/app-router-context.shared-runtime'
type ComponentTree = {
seedData: CacheNodeSeedData
......@@ -457,11 +458,7 @@ async function createComponentTreeInternal({
<LayoutRouter
parallelRouterKey={parallelRouteKey}
segmentPath={createSegmentPath(currentSegmentPath)}
loading={Loading ? <Loading /> : undefined}
loadingStyles={loadingStyles}
loadingScripts={loadingScripts}
// TODO-APP: Add test for loading returning `undefined`. This currently can't be tested as the `webdriver()` tab will wait for the full page to load before returning.
hasLoading={Boolean(Loading)}
error={ErrorComponent}
errorStyles={errorStyles}
errorScripts={errorScripts}
......@@ -493,6 +490,10 @@ async function createComponentTreeInternal({
parallelRouteCacheNodeSeedData[parallelRouteKey] = flightData
}
const loadingData: LoadingModuleData = Loading
? [<Loading />, loadingStyles, loadingScripts]
: null
// When the segment does not have a layout or page we still have to add the layout router to ensure the path holds the loading component
if (!Component) {
return {
......@@ -505,6 +506,7 @@ async function createComponentTreeInternal({
// reason that I'm not aware of, so I'm leaving it as-is out of extreme
// caution, for now.
<>{parallelRouteProps.children}</>,
loadingData,
],
styles: layerAssets,
}
......@@ -534,6 +536,7 @@ async function createComponentTreeInternal({
reason='dynamic = "force-dynamic" was used'
pathname={staticGenerationStore.urlPathname}
/>,
loadingData,
],
styles: layerAssets,
}
......@@ -625,6 +628,7 @@ async function createComponentTreeInternal({
TODO-APP update router to use a Symbol for partial tree detection */}
{null}
</>,
loadingData,
],
styles: layerAssets,
}
......
......@@ -6,6 +6,7 @@ import type { NextFontManifest } from '../../build/webpack/plugins/next-font-man
import type { ParsedUrlQuery } from 'querystring'
import type { AppPageModule } from '../future/route-modules/app-page/module'
import type { SwrDelta } from '../lib/revalidate'
import type { LoadingModuleData } from '../../shared/lib/app-router-context.shared-runtime'
import s from 'next/dist/compiled/superstruct'
......@@ -75,7 +76,8 @@ export type CacheNodeSeedData = [
parallelRoutes: {
[parallelRouterKey: string]: CacheNodeSeedData | null
},
node: React.ReactNode | null
node: React.ReactNode | null,
loading: LoadingModuleData
]
export type FlightDataPath =
......
......@@ -16,6 +16,10 @@ export type ChildSegmentMap = Map<string, CacheNode>
*/
export type CacheNode = ReadyCacheNode | LazyCacheNode
export type LoadingModuleData =
| [React.JSX.Element, React.ReactNode, React.ReactNode]
| null
export type LazyCacheNode = {
/**
* Whether the lazy cache node data promise has been resolved.
......@@ -53,6 +57,9 @@ export type LazyCacheNode = {
prefetchHead: React.ReactNode
head: React.ReactNode
loading: LoadingModuleData
/**
* Child parallel routes.
*/
......@@ -97,6 +104,9 @@ export type ReadyCacheNode = {
lazyData: null
prefetchHead: React.ReactNode
head: React.ReactNode
loading: LoadingModuleData
parallelRoutes: Map<string, ChildSegmentMap>
}
......@@ -149,6 +159,7 @@ export const LayoutRouterContext = React.createContext<{
childNodes: CacheNode['parallelRoutes']
tree: FlightRouterState
url: string
loading: LoadingModuleData
} | null>(null)
export const GlobalLayoutRouterContext = React.createContext<{
......
......@@ -13,7 +13,8 @@
"failed": [
"app dir client cache semantics prefetch={undefined} - default should re-use the full cache for only 30 seconds",
"app dir client cache semantics prefetch={undefined} - default should refetch below the fold after 30 seconds",
"app dir client cache semantics prefetch={undefined} - default should renew the 30s cache once the data is revalidated"
"app dir client cache semantics prefetch={undefined} - default should renew the 30s cache once the data is revalidated",
"app dir client cache semantics prefetch={undefined} - default should refetch the full page after 5 mins"
]
},
"test/e2e/app-dir/headers-static-bailout/headers-static-bailout.test.ts": {
......
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