Unverified Commit 5aa4568b authored by Andrew Clark's avatar Andrew Clark Committed by GitHub

Ignore `prefetch={true}` on Links to routes with `instant` (#90061)

When a route has `unstable_instant` defined on any segment, setting
`prefetch={true}` on a Link to that route is now a no-op. The prefetch
behaves the same as the default auto strategy — cached content is
prefetched but dynamic content is deferred to navigation time.

A full static prefetch doesn't make sense for routes with instant
configs, since those segments use runtime prefetching. Rather than
silently doing something the developer didn't intend, we ignore the prop
entirely.

To detect this on the client, the server now sends a bitmask instead of
a boolean for the per-segment prefetch metadata. One bit tracks whether
the subtree contains any instant config, which propagates up so the
client can check it at the root without traversing.
parent 24e36901
...@@ -154,11 +154,12 @@ type RouteTreeShared = { ...@@ -154,11 +154,12 @@ type RouteTreeShared = {
// like any other Suspense boundary.) // like any other Suspense boundary.)
hasLoadingBoundary: HasLoadingBoundary hasLoadingBoundary: HasLoadingBoundary
// Indicates whether this route has a runtime prefetch that we can request. // Bitmask of PrefetchHint flags. Indicates whether this segment has a
// This is determined by the server; it's not purely a user configuration // runtime prefetch, and whether the subtree contains any instant configs.
// because the server may determine that a route is fully static and doesn't // Determined by the server; not purely a user configuration because the
// need runtime prefetching regardless of the configuration. // server may determine that a route is fully static and doesn't need
hasRuntimePrefetch: boolean // runtime prefetching regardless of the configuration.
prefetchHints: number
} }
export type RefreshState = { export type RefreshState = {
...@@ -722,7 +723,7 @@ function deprecated_createOptimisticRouteTree( ...@@ -722,7 +723,7 @@ function deprecated_createOptimisticRouteTree(
slots: clonedSlots, slots: clonedSlots,
isRootLayout: tree.isRootLayout, isRootLayout: tree.isRootLayout,
hasLoadingBoundary: tree.hasLoadingBoundary, hasLoadingBoundary: tree.hasLoadingBoundary,
hasRuntimePrefetch: tree.hasRuntimePrefetch, prefetchHints: tree.prefetchHints,
} }
} }
...@@ -735,7 +736,7 @@ function deprecated_createOptimisticRouteTree( ...@@ -735,7 +736,7 @@ function deprecated_createOptimisticRouteTree(
slots: clonedSlots, slots: clonedSlots,
isRootLayout: tree.isRootLayout, isRootLayout: tree.isRootLayout,
hasLoadingBoundary: tree.hasLoadingBoundary, hasLoadingBoundary: tree.hasLoadingBoundary,
hasRuntimePrefetch: tree.hasRuntimePrefetch, prefetchHints: tree.prefetchHints,
} }
} }
...@@ -1018,7 +1019,7 @@ export function createMetadataRouteTree( ...@@ -1018,7 +1019,7 @@ export function createMetadataRouteTree(
slots: null, slots: null,
isRootLayout: false, isRootLayout: false,
hasLoadingBoundary: HasLoadingBoundary.SubtreeHasNoLoadingBoundary, hasLoadingBoundary: HasLoadingBoundary.SubtreeHasNoLoadingBoundary,
hasRuntimePrefetch: false, prefetchHints: 0,
} }
return metadata return metadata
} }
...@@ -1321,7 +1322,7 @@ function convertTreePrefetchToRouteTree( ...@@ -1321,7 +1322,7 @@ function convertTreePrefetchToRouteTree(
// This field is only relevant to dynamic routes. For a PPR/static route, // This field is only relevant to dynamic routes. For a PPR/static route,
// there's always some partial loading state we can fetch. // there's always some partial loading state we can fetch.
hasLoadingBoundary: HasLoadingBoundary.SegmentHasLoadingBoundary, hasLoadingBoundary: HasLoadingBoundary.SegmentHasLoadingBoundary,
hasRuntimePrefetch: prefetch.hasRuntimePrefetch, prefetchHints: prefetch.prefetchHints,
} }
} }
...@@ -1507,8 +1508,8 @@ function convertFlightRouterStateToRouteTree( ...@@ -1507,8 +1508,8 @@ function convertFlightRouterStateToRouteTree(
: HasLoadingBoundary.SubtreeHasNoLoadingBoundary, : HasLoadingBoundary.SubtreeHasNoLoadingBoundary,
// Non-static tree responses are only used by apps that haven't adopted // Non-static tree responses are only used by apps that haven't adopted
// Cache Components. So this is always false. // Cache Components. So this is always 0.
hasRuntimePrefetch: false, prefetchHints: 0,
} }
} }
......
...@@ -764,7 +764,7 @@ function convertServerPatchToFullTreeImpl( ...@@ -764,7 +764,7 @@ function convertServerPatchToFullTreeImpl(
newSeedDataChildren, newSeedDataChildren,
null, null,
isEmptySeedDataPartial, isEmptySeedDataPartial,
false, 0,
null, null,
] ]
......
...@@ -799,7 +799,7 @@ function reifyRouteTree( ...@@ -799,7 +799,7 @@ function reifyRouteTree(
slots: newSlots, slots: newSlots,
isRootLayout: pattern.isRootLayout, isRootLayout: pattern.isRootLayout,
hasLoadingBoundary: pattern.hasLoadingBoundary, hasLoadingBoundary: pattern.hasLoadingBoundary,
hasRuntimePrefetch: pattern.hasRuntimePrefetch, prefetchHints: pattern.prefetchHints,
isPage: true, isPage: true,
varyPath: newVaryPath, varyPath: newVaryPath,
} }
...@@ -816,7 +816,7 @@ function reifyRouteTree( ...@@ -816,7 +816,7 @@ function reifyRouteTree(
slots: newSlots, slots: newSlots,
isRootLayout: pattern.isRootLayout, isRootLayout: pattern.isRootLayout,
hasLoadingBoundary: pattern.hasLoadingBoundary, hasLoadingBoundary: pattern.hasLoadingBoundary,
hasRuntimePrefetch: pattern.hasRuntimePrefetch, prefetchHints: pattern.prefetchHints,
isPage: false, isPage: false,
varyPath: newVaryPath, varyPath: newVaryPath,
} }
......
...@@ -3,7 +3,10 @@ import type { ...@@ -3,7 +3,10 @@ import type {
Segment as FlightRouterStateSegment, Segment as FlightRouterStateSegment,
Segment, Segment,
} from '../../../shared/lib/app-router-types' } from '../../../shared/lib/app-router-types'
import { HasLoadingBoundary } from '../../../shared/lib/app-router-types' import {
HasLoadingBoundary,
PrefetchHint,
} from '../../../shared/lib/app-router-types'
import { matchSegment } from '../match-segments' import { matchSegment } from '../match-segments'
import { import {
readOrCreateRouteCacheEntry, readOrCreateRouteCacheEntry,
...@@ -710,12 +713,28 @@ function pingRootRouteTree( ...@@ -710,12 +713,28 @@ function pingRootRouteTree(
// If it turned out that the route isn't PPR-enabled, we need to use `LoadingBoundary` instead. // If it turned out that the route isn't PPR-enabled, we need to use `LoadingBoundary` instead.
// We don't need to do this for runtime prefetches, because those are only available in // We don't need to do this for runtime prefetches, because those are only available in
// `cacheComponents`, where every route is PPR. // `cacheComponents`, where every route is PPR.
const fetchStrategy = let fetchStrategy: FetchStrategy
task.fetchStrategy === FetchStrategy.PPR if (tree.prefetchHints & PrefetchHint.SubtreeHasInstant) {
? route.isPPREnabled // If `instant` is defined anywhere on the target route, ignore the
// fetch strategy and switch to unified strategy used by Cache
// Components (called `PPR` for now, will likely be renamed).
//
// In practice, this just means that a "full" prefetch (<Link
// prefetch={true}>) has no effect. You're meant to use Runtime
// Prefetching instead — that's the new pattern that replaces
// prefetch={true}.
//
// The reason we check for `instant` rather than the `cacheComponents`
// flag is to support incremental adoption. `prefetch={true}` will
// continue to work until you opt into `instant`.
fetchStrategy = FetchStrategy.PPR
} else if (task.fetchStrategy === FetchStrategy.PPR) {
fetchStrategy = route.isPPREnabled
? FetchStrategy.PPR ? FetchStrategy.PPR
: FetchStrategy.LoadingBoundary : FetchStrategy.LoadingBoundary
: task.fetchStrategy } else {
fetchStrategy = task.fetchStrategy
}
switch (fetchStrategy) { switch (fetchStrategy) {
case FetchStrategy.PPR: { case FetchStrategy.PPR: {
...@@ -962,7 +981,7 @@ function pingNewPartOfCacheComponentsTree( ...@@ -962,7 +981,7 @@ function pingNewPartOfCacheComponentsTree(
// shared layouts.) Segments in here default to being prefetched statically. // shared layouts.) Segments in here default to being prefetched statically.
// However, if the server instructs us to, we may switch to a runtime // However, if the server instructs us to, we may switch to a runtime
// prefetch instead. Traverse the tree and check at each segment. // prefetch instead. Traverse the tree and check at each segment.
if (tree.hasRuntimePrefetch) { if (tree.prefetchHints & PrefetchHint.HasRuntimePrefetch) {
// This route has a runtime prefetch response. Since we're below the shared // This route has a runtime prefetch response. Since we're below the shared
// layout, everything from this point should be prefetched using a single, // layout, everything from this point should be prefetched using a single,
// combined runtime request, rather than using per-segment static requests. // combined runtime request, rather than using per-segment static requests.
......
...@@ -1720,7 +1720,7 @@ async function getErrorRSCPayload( ...@@ -1720,7 +1720,7 @@ async function getErrorRSCPayload(
{}, {},
null, null,
false, false,
false, // We don't currently support runtime prefetching for error pages. 0, // We don't currently support runtime prefetching for error pages.
null, // varyParams - not tracked for error pages null, // varyParams - not tracked for error pages
] ]
......
...@@ -66,8 +66,8 @@ export type TreePrefetch = { ...@@ -66,8 +66,8 @@ export type TreePrefetch = {
[parallelRouteKey: string]: TreePrefetch [parallelRouteKey: string]: TreePrefetch
} }
/** Whether this segment should be fetched using a runtime prefetch */ /** Bitmask of PrefetchHint flags for this segment and its subtree */
hasRuntimePrefetch: boolean prefetchHints: number
// Extra fields that only exist so we can reconstruct a FlightRouterState on // Extra fields that only exist so we can reconstruct a FlightRouterState on
// the client. We may be able to unify TreePrefetch and FlightRouterState // the client. We may be able to unify TreePrefetch and FlightRouterState
...@@ -345,7 +345,7 @@ function collectSegmentDataImpl( ...@@ -345,7 +345,7 @@ function collectSegmentDataImpl(
slotMetadata[parallelRouteKey] = childTree slotMetadata[parallelRouteKey] = childTree
} }
const hasRuntimePrefetch = seedData !== null ? seedData[4] : false const prefetchHints = seedData !== null ? seedData[4] : 0
// Determine which params this segment varies on. // Determine which params this segment varies on.
// Read the vary params thenable directly from the seed data. By the time // Read the vary params thenable directly from the seed data. By the time
...@@ -402,7 +402,7 @@ function collectSegmentDataImpl( ...@@ -402,7 +402,7 @@ function collectSegmentDataImpl(
return { return {
name, name,
param, param,
hasRuntimePrefetch, prefetchHints,
slots: slotMetadata, slots: slotMetadata,
isRootLayout: route[4] === true, isRootLayout: route[4] === true,
} }
......
import type { ComponentType } from 'react' import type { ComponentType } from 'react'
import type { import {
CacheNodeSeedData, PrefetchHint,
LoadingModuleData, type CacheNodeSeedData,
type LoadingModuleData,
} from '../../shared/lib/app-router-types' } from '../../shared/lib/app-router-types'
import type { PreloadCallbacks } from './types' import type { PreloadCallbacks } from './types'
import { import {
...@@ -228,11 +229,13 @@ async function createComponentTreeInternal( ...@@ -228,11 +229,13 @@ async function createComponentTreeInternal(
const instantConfig = layoutOrPageMod const instantConfig = layoutOrPageMod
? (layoutOrPageMod as AppSegmentConfig).unstable_instant ? (layoutOrPageMod as AppSegmentConfig).unstable_instant
: undefined : undefined
/** Whether this segment should use a runtime prefetch instead of a static prefetch. */ let prefetchHints = 0
const hasRuntimePrefetch = if (instantConfig && typeof instantConfig === 'object') {
instantConfig && typeof instantConfig === 'object' prefetchHints |= PrefetchHint.SubtreeHasInstant
? instantConfig.prefetch === 'runtime' if (instantConfig.prefetch === 'runtime') {
: false prefetchHints |= PrefetchHint.HasRuntimePrefetch
}
}
const [Forbidden, forbiddenStyles] = const [Forbidden, forbiddenStyles] =
authInterrupts && forbidden authInterrupts && forbidden
...@@ -694,7 +697,7 @@ async function createComponentTreeInternal( ...@@ -694,7 +697,7 @@ async function createComponentTreeInternal(
parallelRouteCacheNodeSeedData, parallelRouteCacheNodeSeedData,
loadingData, loadingData,
isPossiblyPartialResponse, isPossiblyPartialResponse,
hasRuntimePrefetch, prefetchHints,
// No user-provided component, so no params will be accessed. Use the // No user-provided component, so no params will be accessed. Use the
// pre-resolved empty tracker. // pre-resolved empty tracker.
emptyVaryParamsAccumulator emptyVaryParamsAccumulator
...@@ -734,7 +737,7 @@ async function createComponentTreeInternal( ...@@ -734,7 +737,7 @@ async function createComponentTreeInternal(
parallelRouteCacheNodeSeedData, parallelRouteCacheNodeSeedData,
loadingData, loadingData,
true, true,
hasRuntimePrefetch, prefetchHints,
// force-dynamic postpones without rendering the component, so no params // force-dynamic postpones without rendering the component, so no params
// are accessed. The vary params are empty. // are accessed. The vary params are empty.
emptyVaryParamsAccumulator emptyVaryParamsAccumulator
...@@ -862,7 +865,7 @@ async function createComponentTreeInternal( ...@@ -862,7 +865,7 @@ async function createComponentTreeInternal(
parallelRouteCacheNodeSeedData, parallelRouteCacheNodeSeedData,
loadingData, loadingData,
isPossiblyPartialResponse, isPossiblyPartialResponse,
hasRuntimePrefetch, prefetchHints,
varyParamsAccumulator varyParamsAccumulator
) )
} else { } else {
...@@ -1077,7 +1080,7 @@ async function createComponentTreeInternal( ...@@ -1077,7 +1080,7 @@ async function createComponentTreeInternal(
parallelRouteCacheNodeSeedData, parallelRouteCacheNodeSeedData,
loadingData, loadingData,
isPossiblyPartialResponse, isPossiblyPartialResponse,
hasRuntimePrefetch, prefetchHints,
varyParamsAccumulator varyParamsAccumulator
) )
} }
...@@ -1229,7 +1232,7 @@ function createSeedData( ...@@ -1229,7 +1232,7 @@ function createSeedData(
parallelRoutes: Record<string, CacheNodeSeedData | null>, parallelRoutes: Record<string, CacheNodeSeedData | null>,
loading: LoadingModuleData | null, loading: LoadingModuleData | null,
isPossiblyPartialResponse: boolean, isPossiblyPartialResponse: boolean,
hasRuntimePrefetch: boolean, prefetchHints: number,
varyParamsAccumulator: VaryParamsAccumulator | null varyParamsAccumulator: VaryParamsAccumulator | null
): CacheNodeSeedData { ): CacheNodeSeedData {
if (loading !== null) { if (loading !== null) {
...@@ -1245,12 +1248,22 @@ function createSeedData( ...@@ -1245,12 +1248,22 @@ function createSeedData(
children: rsc, children: rsc,
}) })
} }
// Propagate SubtreeHasInstant from children so the root reflects the
// entire subtree.
// TODO: We should send the prefetch hints bitmask as part of the route tree,
// rather than the CacheNodeSeedData.
for (const key in parallelRoutes) {
const child = parallelRoutes[key]
if (child !== null) {
prefetchHints |= child[4] & PrefetchHint.SubtreeHasInstant
}
}
return [ return [
rsc, rsc,
parallelRoutes, parallelRoutes,
null, null,
isPossiblyPartialResponse, isPossiblyPartialResponse,
hasRuntimePrefetch, prefetchHints,
varyParamsAccumulator ? getVaryParamsThenable(varyParamsAccumulator) : null, varyParamsAccumulator ? getVaryParamsThenable(varyParamsAccumulator) : null,
] ]
} }
...@@ -1041,7 +1041,7 @@ function deserializeFromChunks<T>( ...@@ -1041,7 +1041,7 @@ function deserializeFromChunks<T>(
type SegmentData = { type SegmentData = {
node: React.ReactNode | null node: React.ReactNode | null
isPartial: boolean isPartial: boolean
hasRuntimePrefetch: boolean prefetchHints: number
varyParams: VaryParamsThenable | null varyParams: VaryParamsThenable | null
} }
...@@ -1051,13 +1051,13 @@ function createSegmentData(seedData: CacheNodeSeedData): SegmentData { ...@@ -1051,13 +1051,13 @@ function createSegmentData(seedData: CacheNodeSeedData): SegmentData {
_parallelRoutesData, _parallelRoutesData,
_unused, _unused,
isPartial, isPartial,
hasRuntimePrefetch, prefetchHints,
varyParams, varyParams,
] = seedData ] = seedData
return { return {
node, node,
isPartial, isPartial,
hasRuntimePrefetch, prefetchHints,
varyParams, varyParams,
} }
} }
...@@ -1072,7 +1072,7 @@ function getCacheNodeSeedDataFromSegment( ...@@ -1072,7 +1072,7 @@ function getCacheNodeSeedDataFromSegment(
slots, slots,
/* unused (previously `loading`) */ null, /* unused (previously `loading`) */ null,
data.isPartial, data.isPartial,
data.hasRuntimePrefetch, data.prefetchHints,
data.varyParams, data.varyParams,
] ]
} }
......
...@@ -162,6 +162,16 @@ export const enum HasLoadingBoundary { ...@@ -162,6 +162,16 @@ export const enum HasLoadingBoundary {
SubtreeHasNoLoadingBoundary = 3, SubtreeHasNoLoadingBoundary = 3,
} }
export const enum PrefetchHint {
// This segment has a runtime prefetch enabled (via unstable_instant with
// prefetch: 'runtime'). Per-segment only, does not propagate to ancestors.
HasRuntimePrefetch = 0b01,
// This segment or one of its descendants has an instant config defined
// (any truthy unstable_instant, regardless of prefetch mode). Propagates
// upward so the root segment reflects the entire subtree.
SubtreeHasInstant = 0b10,
}
/** /**
* Individual Flight response path * Individual Flight response path
*/ */
...@@ -194,7 +204,7 @@ export type CacheNodeSeedData = [ ...@@ -194,7 +204,7 @@ export type CacheNodeSeedData = [
loading: null, loading: null,
isPartial: boolean, isPartial: boolean,
/** TODO: this doesn't feel like it belongs here, because it's only used during build, in `collectSegmentData` */ /** TODO: this doesn't feel like it belongs here, because it's only used during build, in `collectSegmentData` */
hasRuntimePrefetch: boolean, prefetchHints: number,
/** /**
* A thenable that resolves to the set of route params this segment accessed * A thenable that resolves to the set of route params this segment accessed
* during server rendering. Used by the client router to determine cache key * during server rendering. Used by the client router to determine cache key
......
import { ReactNode } from 'react'
export const unstable_instant = {
prefetch: 'runtime',
samples: [{}],
}
export default function Layout({ children }: { children: ReactNode }) {
return <div>{children}</div>
}
import { Suspense } from 'react'
import { cookies } from 'next/headers'
import { connection } from 'next/server'
// No instant config on the page — only the layout has it.
export default async function Page() {
return (
<main>
<Suspense fallback={<div>Loading cached...</div>}>
<CachedWrapper />
</Suspense>
<Suspense fallback={<div>Loading dynamic...</div>}>
<Dynamic />
</Suspense>
</main>
)
}
async function CachedWrapper() {
const cookieStore = await cookies()
const value = cookieStore.get('test')?.value ?? 'default'
return <Cached value={value} />
}
async function Cached({ value }: { value: string }) {
'use cache'
return <div id="cached-content">Cached content: {value}</div>
}
async function Dynamic() {
await connection()
return <div id="dynamic-content">Dynamic content</div>
}
import Link from 'next/link'
import { ReactNode } from 'react'
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html>
<body>
<header>
<Link href="/" prefetch={false}>
Home
</Link>
</header>
{children}
</body>
</html>
)
}
import { LinkAccordion } from '../components/link-accordion'
export default function Page() {
return (
<main>
<h1>Home</h1>
<ul>
<li>
<LinkAccordion href="/target-page" prefetch={true}>
/target-page (prefetch=true, instant on page)
</LinkAccordion>
</li>
<li>
<LinkAccordion href="/layout-instant" prefetch={true}>
/layout-instant (prefetch=true, instant on layout)
</LinkAccordion>
</li>
</ul>
</main>
)
}
import { Suspense } from 'react'
import { cookies } from 'next/headers'
import { connection } from 'next/server'
export const unstable_instant = {
prefetch: 'runtime',
samples: [{}],
}
export default async function Page() {
return (
<main>
<Suspense fallback={<div>Loading cached...</div>}>
<Cached />
</Suspense>
<Suspense fallback={<div>Loading dynamic...</div>}>
<Dynamic />
</Suspense>
</main>
)
}
async function Cached() {
const cookieStore = await cookies()
const value = cookieStore.get('test')?.value ?? 'default'
return <div id="cached-content">Cached content: {value}</div>
}
async function Dynamic() {
await connection()
return <div id="dynamic-content">Dynamic content</div>
}
'use client'
import Link, { type LinkProps } from 'next/link'
import { useState } from 'react'
export function LinkAccordion({
href,
children,
prefetch,
}: {
href: string
children: React.ReactNode
prefetch?: LinkProps['prefetch']
}) {
const [isVisible, setIsVisible] = useState(false)
return (
<>
<input
type="checkbox"
checked={isVisible}
onChange={() => setIsVisible(!isVisible)}
data-link-accordion={href}
/>
{isVisible ? (
<Link href={href} prefetch={prefetch}>
{children}
</Link>
) : (
<>{children} (link is hidden)</>
)}
</>
)
}
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
cacheComponents: true,
}
module.exports = nextConfig
import { nextTestSetup } from 'e2e-utils'
import type * as Playwright from 'playwright'
import { createRouterAct } from 'router-act'
describe('prefetch={true} with instant route', () => {
const { next, isNextDev } = nextTestSetup({
files: __dirname,
})
if (isNextDev) {
it('is skipped', () => {})
return
}
it('does not include dynamic content in the prefetch when the target route has instant', async () => {
let page: Playwright.Page
const browser = await next.browser('/', {
beforePageLoad(p: Playwright.Page) {
page = p
},
})
const act = createRouterAct(page)
// Reveal the link to trigger a prefetch. Even though the Link has
// prefetch={true}, the route has unstable_instant defined, so the
// prefetch should be downgraded — it should include cached content
// but NOT dynamic content.
await act(async () => {
const linkToggle = await browser.elementByCss(
'input[data-link-accordion="/target-page"]'
)
await linkToggle.click()
}, [
{
includes: 'Cached content',
},
{
includes: 'Dynamic content',
block: 'reject',
},
])
// Navigate to the page. Block the navigation request so we can
// verify which parts appear instantly from the prefetch cache.
await act(async () => {
await act(
async () => {
await browser.elementByCss('a[href="/target-page"]').click()
},
{
// Temporarily block the navigation request that fetches the
// dynamic content. While blocked, the cached parts should
// already be visible on screen.
includes: 'Dynamic content',
block: true,
}
)
// The cached content should be visible immediately from the prefetch.
expect(await browser.elementById('cached-content').text()).toContain(
'Cached content'
)
// The dynamic content should NOT be on screen yet because the
// navigation response is still blocked.
const dynamicElement = await browser.elementsByCss('#dynamic-content')
expect(dynamicElement.length).toBe(0)
})
// After the navigation response is unblocked, both parts should
// be visible.
expect(await browser.elementById('cached-content').text()).toContain(
'Cached content'
)
expect(await browser.elementById('dynamic-content').text()).toEqual(
'Dynamic content'
)
})
it('also disables full prefetch when instant is on a layout, not the page', async () => {
let page: Playwright.Page
const browser = await next.browser('/', {
beforePageLoad(p: Playwright.Page) {
page = p
},
})
const act = createRouterAct(page)
// The layout has unstable_instant but the page does not. The
// SubtreeHasInstant bit should propagate up from the layout, so
// prefetch={true} on the Link should still be downgraded.
await act(async () => {
const linkToggle = await browser.elementByCss(
'input[data-link-accordion="/layout-instant"]'
)
await linkToggle.click()
}, [
{
includes: 'Cached content',
},
{
includes: 'Dynamic content',
block: 'reject',
},
])
// Navigate and verify the cached content appears instantly.
await act(async () => {
await act(
async () => {
await browser.elementByCss('a[href="/layout-instant"]').click()
},
{
includes: 'Dynamic content',
block: true,
}
)
expect(await browser.elementById('cached-content').text()).toContain(
'Cached content'
)
const dynamicElement = await browser.elementsByCss('#dynamic-content')
expect(dynamicElement.length).toBe(0)
})
expect(await browser.elementById('cached-content').text()).toContain(
'Cached content'
)
expect(await browser.elementById('dynamic-content').text()).toEqual(
'Dynamic content'
)
})
})
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