Unverified Commit f7dd09fd authored by Janka Uryga's avatar Janka Uryga Committed by GitHub

[Instant] Validation on client navs (#89777)

This PR makes instant validation work for client navigations, albeit in
a pretty inefficent way. If we're navigating and have an `instant`
config somewhere in the tree, we won't skip shared layouts like a client
navigation usually would. Instead, we render all the shared segments too
(via `createFullTreeFlightDataForNavigation`, a very simplified
variation of `walkTreeWithFlightRouterState`) and use them to perform
instant validation on the current page. The client router doesn't mind
getting extra segments -- `startPPRNavigation` (and
`updateCacheNodeOnNavigation` specifically) ignore segments that are
already present in the old tree.

This approach has some downsides:
- It doesn't match prod behavior (parent layouts don't render there), so
it could lead to user confusion
- We're validating using different segments that the browser actually
has, so we could see an error in the validation that isn't present in
the browser

but we'll iterate on this later. We only do this when a page is using
`instant`, so for now the impact is narrowed down to early adopters.

### Test changes

For each test case we have, we now run it both on initial load and on
client nav.

This got somewhat noisy because i had to reorganize the test files a
bit. We use the index pages to test client navigations, but in order to
do that, we need the source and the target to be inside the same root
layout -- otherwise, they'd be an MPA nav.
parent 4385ed36
......@@ -92,7 +92,10 @@ import { createServerInsertedHTML } from './server-inserted-html'
import { getRequiredScripts } from './required-scripts'
import { addPathPrefix } from '../../shared/lib/router/utils/add-path-prefix'
import { makeGetServerInsertedHTML } from './make-get-server-inserted-html'
import { walkTreeWithFlightRouterState } from './walk-tree-with-flight-router-state'
import {
walkTreeWithFlightRouterState,
createFullTreeFlightDataForNavigation,
} from './walk-tree-with-flight-router-state'
import { createComponentTree, getRootParams } from './create-component-tree'
import { getAssetQueryString } from './get-asset-query-string'
import {
......@@ -532,6 +535,14 @@ async function generateDynamicRSCPayload(
if (!options?.skipPageRendering) {
const preloadCallbacks: PreloadCallbacks = []
// If we're performing instant validation, we need to render the whole tree,
// without skipping shared layouts.
const needsFullTree =
process.env.NODE_ENV === 'development' &&
ctx.renderOpts.cacheComponents &&
!options?.actionResult && // Only for navigations
(await anySegmentNeedsInstantValidation(loaderTree))
const { Viewport, Metadata, MetadataOutlet } = createMetadataComponents({
tree: loaderTree,
parsedQuery: query,
......@@ -542,38 +553,50 @@ async function generateDynamicRSCPayload(
serveStreamingMetadata,
})
const rscHead = createElement(
Fragment,
{
key: flightDataPathHeadKey,
},
createElement(NonIndex, {
createElement,
pagePath: ctx.pagePath,
statusCode: ctx.res.statusCode,
isPossibleServerAction: ctx.isPossibleServerAction,
}),
createElement(Viewport, {
key: getFlightViewportKey(requestId),
}),
createElement(Metadata, {
key: getFlightMetadataKey(requestId),
})
)
flightData = (
await walkTreeWithFlightRouterState({
ctx,
loaderTreeToFilter: loaderTree,
parentParams: {},
flightRouterState,
// For flight, render metadata inside leaf page
rscHead: createElement(
Fragment,
{
key: flightDataPathHeadKey,
},
createElement(NonIndex, {
createElement,
pagePath: ctx.pagePath,
statusCode: ctx.res.statusCode,
isPossibleServerAction: ctx.isPossibleServerAction,
}),
createElement(Viewport, {
key: getFlightViewportKey(requestId),
}),
createElement(Metadata, {
key: getFlightMetadataKey(requestId),
needsFullTree
? await createFullTreeFlightDataForNavigation({
ctx,
loaderTree,
rscHead,
injectedCSS: new Set(),
injectedJS: new Set(),
injectedFontPreloadTags: new Set(),
preloadCallbacks,
MetadataOutlet,
})
: await walkTreeWithFlightRouterState({
ctx,
loaderTreeToFilter: loaderTree,
parentParams: {},
flightRouterState,
rscHead,
injectedCSS: new Set(),
injectedJS: new Set(),
injectedFontPreloadTags: new Set(),
rootLayoutIncluded: false,
preloadCallbacks,
MetadataOutlet,
})
),
injectedCSS: new Set(),
injectedJS: new Set(),
injectedFontPreloadTags: new Set(),
rootLayoutIncluded: false,
preloadCallbacks,
MetadataOutlet,
})
).map((path) => path.slice(1)) // remove the '' (root) segment
}
......@@ -806,7 +829,12 @@ async function generateDynamicFlightRenderResultWithStagesInDev(
renderOpts,
requestId,
workStore,
componentMod: { createElement },
componentMod: {
createElement,
routeModule: {
userland: { loaderTree },
},
},
url,
} = ctx
......@@ -834,11 +862,13 @@ async function generateDynamicFlightRenderResultWithStagesInDev(
onFlightDataRenderError
)
// We only validate RSC requests if it is for HMR refreshes since we know we
// will render all the layouts necessary to perform the validation.
// We validate RSC requests for HMR refreshes and client navigations when
// instant configs exist, since we render all the layouts necessary to perform
// the validation in those cases.
const shouldValidate =
!isBypassingCachesInDev(renderOpts, initialRequestStore) &&
initialRequestStore.isHmrRefresh === true
(initialRequestStore.isHmrRefresh === true ||
(await anySegmentNeedsInstantValidation(loaderTree)))
const getPayload = async (requestStore: RequestStore) => {
const payload: RSCPayload &
......
......@@ -2,6 +2,10 @@ import { getLayoutOrPageModule } from '../../lib/app-dir-module'
import type { LoaderTree } from '../../lib/app-dir-module'
import { parseLoaderTree } from '../../../shared/lib/router/utils/parse-loader-tree'
import type { AppSegmentConfig } from '../../../build/segment-config/app/app-segment-config'
import {
workAsyncStorage,
type WorkStore,
} from '../work-async-storage.external'
export async function anySegmentHasRuntimePrefetchEnabled(
tree: LoaderTree
......@@ -70,53 +74,90 @@ type FoundSegmentWithConfig = {
config: NonNullable<AppSegmentConfig['unstable_instant']>
}
export async function anySegmentNeedsInstantValidation(
rootTree: LoaderTree
): Promise<boolean> {
const segments = await findSegmentsWithInstantConfig(rootTree)
// Check if there's any configs with `prefetch: 'static'` or `mode: 'instant'`.
// (If there's only `false`, there's no need to run validation).
// If any segment has `unstable_disableValidation`, we skip validation for the whole tree.
let needsValidation = false
for (const { config } of segments) {
if (typeof config === 'object') {
if (config.unstable_disableValidation) {
return false
/**
* Checks if any segments in the loader tree have `instant` configs that need validating.
* NOTE: Client navigations call this multiple times, so we cache it.
* */
export const anySegmentNeedsInstantValidation = cacheScopedToWorkStore(
async (rootTree: LoaderTree): Promise<boolean> => {
const segments = await findSegmentsWithInstantConfig(rootTree)
// Check if there's any configs with `prefetch: 'static'` or `mode: 'instant'`.
// (If there's only `false`, there's no need to run validation).
// If any segment has `unstable_disableValidation`, we skip validation for the whole tree.
let needsValidation = false
for (const { config } of segments) {
if (typeof config === 'object') {
if (config.unstable_disableValidation) {
return false
}
// do not short-circuit, some other segment might still have `unstable_disableValidation`
needsValidation = true
}
// do not short-circuit, some other segment might still have `unstable_disableValidation`
needsValidation = true
}
return needsValidation
}
return needsValidation
}
)
export const findSegmentsWithInstantConfig = cacheScopedToWorkStore(
async (rootTree: LoaderTree): Promise<FoundSegmentWithConfig[]> => {
const results: FoundSegmentWithConfig[] = []
async function visit(tree: LoaderTree, path: string[]): Promise<void> {
const { mod: layoutOrPageMod } = await getLayoutOrPageModule(tree)
// TODO(restart-on-cache-miss): Does this work correctly for client page/layout modules?
const instantConfig = layoutOrPageMod
? (layoutOrPageMod as AppSegmentConfig).unstable_instant
: undefined
if (instantConfig !== undefined) {
results.push({
path,
config: instantConfig,
})
}
export async function findSegmentsWithInstantConfig(
rootTree: LoaderTree
): Promise<FoundSegmentWithConfig[]> {
const results: FoundSegmentWithConfig[] = []
async function visit(tree: LoaderTree, path: string[]): Promise<void> {
const { mod: layoutOrPageMod } = await getLayoutOrPageModule(tree)
// TODO(restart-on-cache-miss): Does this work correctly for client page/layout modules?
const instantConfig = layoutOrPageMod
? (layoutOrPageMod as AppSegmentConfig).unstable_instant
: undefined
if (instantConfig !== undefined) {
results.push({
path,
config: instantConfig,
})
const { parallelRoutes } = parseLoaderTree(tree)
for (const parallelRouteKey in parallelRoutes) {
const childTree = parallelRoutes[parallelRouteKey]
await visit(childTree, [...path, parallelRouteKey])
}
}
const { parallelRoutes } = parseLoaderTree(tree)
for (const parallelRouteKey in parallelRoutes) {
const childTree = parallelRoutes[parallelRouteKey]
await visit(childTree, [...path, parallelRouteKey])
}
await visit(rootTree, [])
return results
}
)
/**
* A simple cache wrapper for 1-argument functions.
* The cache will live as long as the current WorkStore,
* i.e. it's scoped to a single request.
*/
function cacheScopedToWorkStore<TArg extends WeakKey, TRes>(
func: (arg: TArg) => TRes
): (arg: TArg) => TRes {
const resultsPerWorkStore = new WeakMap<WorkStore, WeakMap<TArg, TRes>>()
return (arg: TArg): TRes => {
const workStore = workAsyncStorage.getStore()
if (!workStore) {
// No caching.
return func(arg)
}
await visit(rootTree, [])
return results
let results = resultsPerWorkStore.get(workStore)
if (results && results.has(arg)) {
return results.get(arg)!
}
const result = func(arg)
if (!results) {
results = new WeakMap()
resultsPerWorkStore.set(workStore, results)
}
results.set(arg, result)
return result
}
}
......@@ -294,6 +294,70 @@ export async function walkTreeWithFlightRouterState({
return paths
}
/**
* A simplified version of `walkTreeWithFlightRouterState` that doesn't skip any layouts
* but returns a result of the same shape.
* Intended to be used for instant validation, where we need the complete tree.
*/
export async function createFullTreeFlightDataForNavigation({
loaderTree,
rscHead,
injectedCSS,
injectedJS,
injectedFontPreloadTags,
ctx,
preloadCallbacks,
MetadataOutlet,
}: {
loaderTree: LoaderTree
flightRouterState?: FlightRouterState
rscHead: HeadData
injectedCSS: Set<string>
injectedJS: Set<string>
injectedFontPreloadTags: Set<string>
ctx: AppRenderContext
preloadCallbacks: PreloadCallbacks
MetadataOutlet: React.ComponentType
}): Promise<[rootSegment: FlightDataPath]> {
const {
renderOpts: { experimental },
query,
getDynamicParamFromSegment,
} = ctx
const routerState = createFlightRouterStateFromLoaderTree(
loaderTree,
getDynamicParamFromSegment,
query
)
const rootSegment = routerState[0]
const seedData = await createComponentTree({
ctx,
loaderTree,
parentParams: {},
injectedCSS,
injectedJS,
injectedFontPreloadTags,
rootLayoutIncluded: false,
preloadCallbacks,
authInterrupts: experimental.authInterrupts,
MetadataOutlet,
})
return [
[
// TODO: app-render slices this Segment off.
// why is that valid, and why are we including it in the first place?
rootSegment,
routerState,
seedData,
rscHead,
false,
] satisfies FlightDataSegment,
]
}
/*
* This function is used to determine if an existing segment can be overridden
* by the incoming segment.
......
......@@ -3,18 +3,7 @@ import { ReactNode } from 'react'
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html>
<body style={{ fontFamily: 'monospace' }}>
<Header />
{children}
</body>
<body style={{ fontFamily: 'monospace' }}>{children}</body>
</html>
)
}
function Header() {
return (
<header>
<a href="/">Home</a>
</header>
)
}
import Link from 'next/link'
export default function IndexPage() {
return (
<main>
<h1>Instant Validation Test</h1>
<ul>
<li>
<Link href="/default">Default (plain root layout)</Link>
</li>
<li>
<Link href="/suspense-in-root">Suspense in Root</Link>
</li>
</ul>
</main>
)
}
import { ReactNode } from 'react'
import { connection } from 'next/server'
import { ReactNode, Suspense } from 'react'
export default function RootLayout({ children }: { children: ReactNode }) {
return (
<html>
<body style={{ fontFamily: 'monospace' }}>
<Header />
<hr />
{children}
</body>
</html>
......@@ -14,7 +16,17 @@ export default function RootLayout({ children }: { children: ReactNode }) {
function Header() {
return (
<header>
<a href="/">Home</a>
<a href="/">Home</a>{' '}
<Suspense fallback="...">
<div id="root-layout-timestamp">
<Now />
</div>
</Suspense>
</header>
)
}
async function Now() {
await connection()
return Date.now()
}
import { cacheLife } from 'next/cache'
import { DebugLinks } from '../shared'
export default async function Page() {
'use cache'
cacheLife('minutes')
return (
<main>
<h2>Static</h2>
<ul>
<li>
<DebugLinks href="/default/static/valid-blocked-children" />
</li>
<li>
<DebugLinks href="/default/static/valid-blocking-inside-static" />
</li>
</ul>
</main>
)
}
import { cacheLife } from 'next/cache'
import Link from 'next/link'
import { setTimeout } from 'timers/promises'
export function DebugLinks({ href }: { href: string }) {
return (
<span>
<span>{href}</span>{' '}
<Link data-link-type="soft" href={href}>
[SPA]
</Link>{' '}
<a data-link-type="hard" href={href}>
[MPA]
</a>
</span>
)
}
export async function uncachedIO() {
await setTimeout(0)
}
......
import { connection } from 'next/server'
import { ReactNode, Suspense } from 'react'
export default function RootLayout({ children }: { children: ReactNode }) {
......@@ -9,6 +10,7 @@ export default function RootLayout({ children }: { children: ReactNode }) {
<html>
<body style={{ fontFamily: 'monospace' }}>
<Header />
<hr />
{children}
</body>
</html>
......@@ -19,7 +21,17 @@ export default function RootLayout({ children }: { children: ReactNode }) {
function Header() {
return (
<header>
<a href="/">Home</a>
<a href="/">Home</a>{' '}
<Suspense fallback="...">
<div id="root-layout-timestamp">
<Now />
</div>
</Suspense>
</header>
)
}
async function Now() {
await connection()
return Date.now()
}
import { DebugLinkMPA } from '../../components/debug-link'
import { cacheLife } from 'next/cache'
import { DebugLinks } from '../shared'
export default async function Page() {
'use cache'
......@@ -9,90 +9,84 @@ export default async function Page() {
<h2>Runtime</h2>
<ul>
<li>
<DebugLinkMPA href="/runtime/suspense-around-dynamic" />
<DebugLinks href="/suspense-in-root/runtime/suspense-around-dynamic" />
</li>
<li>
<DebugLinkMPA href="/runtime/no-suspense-around-params/123" />
<DebugLinks href="/suspense-in-root/runtime/no-suspense-around-params/123" />
</li>
<li>
<DebugLinkMPA href="/runtime/missing-suspense-around-dynamic" />
<DebugLinks href="/suspense-in-root/runtime/missing-suspense-around-dynamic" />
</li>
<li>
<DebugLinkMPA href="/runtime/missing-suspense-around-dynamic-layout" />
<DebugLinks href="/suspense-in-root/runtime/missing-suspense-around-dynamic-layout" />
</li>
<li>
<DebugLinkMPA href="/runtime/suspense-too-high" />
<DebugLinks href="/suspense-in-root/runtime/suspense-too-high" />
</li>
<li>
<DebugLinkMPA href="/runtime/invalid-blocking-inside-runtime" />
<DebugLinks href="/suspense-in-root/static/invalid-blocking-inside-static" />
</li>
<li>
<DebugLinkMPA href="/runtime/invalid-sync-io" />
<DebugLinks href="/suspense-in-root/runtime/invalid-blocking-inside-runtime" />
</li>
<li>
<DebugLinkMPA href="/runtime/valid-blocking-inside-runtime" />
<DebugLinks href="/suspense-in-root/runtime/invalid-sync-io" />
</li>
<li>
<DebugLinks href="/suspense-in-root/runtime/valid-blocking-inside-runtime" />
</li>
</ul>
<h2>Static</h2>
<ul>
<li>
<DebugLinkMPA href="/static/suspense-around-dynamic" />
</li>
<li>
<DebugLinkMPA href="/static/missing-suspense-around-dynamic" />
</li>
<li>
<DebugLinkMPA href="/static/missing-suspense-around-params/123" />
</li>
<li>
<DebugLinkMPA href="/static/missing-suspense-around-dynamic-layout" />
<DebugLinks href="/suspense-in-root/static/suspense-around-dynamic" />
</li>
<li>
<DebugLinkMPA href="/static/suspense-too-high" />
<DebugLinks href="/suspense-in-root/static/missing-suspense-around-dynamic" />
</li>
<li>
<DebugLinkMPA href="/static/blocking-layout" />
<DebugLinks href="/suspense-in-root/static/missing-suspense-around-params/123" />
</li>
<li>
<DebugLinkMPA href="/static/blocking-layout/missing-suspense-around-dynamic" />
<DebugLinks href="/suspense-in-root/static/missing-suspense-around-dynamic-layout" />
</li>
<li>
<DebugLinkMPA href="/static/invalid-only-loading-around-dynamic" />
<DebugLinks href="/suspense-in-root/static/suspense-too-high" />
</li>
<li>
<DebugLinkMPA href="/static/missing-suspense-around-runtime" />
<DebugLinks href="/suspense-in-root/static/blocking-layout" />
</li>
<li>
<DebugLinkMPA href="/static/missing-suspense-in-parallel-route" />
<DebugLinks href="/suspense-in-root/static/blocking-layout/missing-suspense-around-dynamic" />
</li>
<li>
<DebugLinkMPA href="/static/missing-suspense-in-parallel-route/foo" />
<DebugLinks href="/suspense-in-root/static/invalid-only-loading-around-dynamic" />
</li>
<li>
<DebugLinkMPA href="/static/missing-suspense-in-parallel-route/bar" />
<DebugLinks href="/suspense-in-root/static/missing-suspense-around-runtime" />
</li>
<li>
<DebugLinkMPA href="/static/invalid-blocking-inside-static" />
<DebugLinks href="/suspense-in-root/static/missing-suspense-in-parallel-route" />
</li>
<li>
<DebugLinkMPA href="/static/valid-blocked-children" />
<DebugLinks href="/suspense-in-root/static/missing-suspense-in-parallel-route/foo" />
</li>
<li>
<DebugLinkMPA href="/static/valid-blocking-inside-static" />
<DebugLinks href="/suspense-in-root/static/missing-suspense-in-parallel-route/bar" />
</li>
</ul>
<h2>Disable Validation</h2>
<ul>
<li>
<DebugLinkMPA href="/disable-validation/in-layout" />
<DebugLinks href="/suspense-in-root/disable-validation/in-layout" />
</li>
<li>
<DebugLinkMPA href="/disable-validation/in-page" />
<DebugLinks href="/suspense-in-root/disable-validation/in-page" />
</li>
<li>
<DebugLinkMPA href="/disable-validation/in-page-with-outer" />
<DebugLinks href="/suspense-in-root/disable-validation/in-page-with-outer" />
</li>
</ul>
</main>
......
import Link from 'next/link'
export const unstable_instant = { prefetch: 'static' }
export default async function Page() {
return (
<main>
<p>This is a static page below a blocking layout</p>
<div>
<Link href="/suspense-in-root/static/blocking-layout/missing-suspense-around-dynamic">
/suspense-in-root/static/blocking-layout/missing-suspense-around-dynamic
</Link>
</div>
</main>
)
}
......@@ -6,7 +6,9 @@ export default async function Page() {
return (
<main>
<p>This is a static page</p>
<Link href="./missing-suspense-in-parallel-route/foo">./foo</Link>
<Link href="/suspense-in-root/static/missing-suspense-in-parallel-route/foo">
./foo
</Link>
</main>
)
}
'use client'
import Link from 'next/link'
import { ComponentProps } from 'react'
export function DebugLink({
href,
...props
}: Omit<ComponentProps<typeof Link>, 'children' | 'href'> & { href: string }) {
return (
<Link href={href} {...props}>
{href}
</Link>
)
}
export function DebugLinkMPA({
href,
...props
......
import { nextTestSetup } from 'e2e-utils'
import { waitForNoErrorToast } from '../../../lib/next-test-utils'
import { retry, waitForNoErrorToast } from '../../../lib/next-test-utils'
describe.each([
{ debugChannelEnabled: true, description: 'with debug channel' },
......@@ -18,347 +18,68 @@ describe.each([
return
}
it('valid - static prefetch - suspense around runtime and dynamic', async () => {
const browser = await next.browser('/static/suspense-around-dynamic')
await browser.elementByCss('main')
await waitForNoErrorToast(browser)
})
it('valid - runtime prefetch - suspense only around dynamic', async () => {
const browser = await next.browser('/runtime/suspense-around-dynamic')
await browser.elementByCss('main')
await waitForNoErrorToast(browser)
})
it('invalid - static prefetch - missing suspense around runtime', async () => {
const browser = await next.browser(
'/static/missing-suspense-around-runtime'
)
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Runtime data was accessed outside of <Suspense>
This delays the entire page from rendering, resulting in a slow user experience. Next.js uses this error to ensure your app loads instantly on every navigation. cookies(), headers(), and searchParams, are examples of Runtime data that can only come from a user request.
To fix this:
Provide a fallback UI using <Suspense> around this component.
or
Move the Runtime data access into a deeper component wrapped in <Suspense>.
In either case this allows Next.js to stream its contents to the user when they request the page, while still providing an initial UI that is prerendered and prefetchable for instant navigations.
Learn more: https://nextjs.org/docs/messages/blocking-route",
"environmentLabel": "Server",
"label": "Blocking Route",
"source": "app/(suspense-in-root)/static/missing-suspense-around-runtime/page.tsx (6:16) @ Page
> 6 | await cookies()
| ^",
"stack": [
"Page app/(suspense-in-root)/static/missing-suspense-around-runtime/page.tsx (6:16)",
],
}
`)
})
it('invalid - static prefetch - missing suspense around dynamic', async () => {
const browser = await next.browser(
'/static/missing-suspense-around-dynamic'
)
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Data that blocks navigation was accessed outside of <Suspense>
This delays the entire page from rendering, resulting in a slow user experience. Next.js uses this error to ensure your app loads instantly on every navigation. Uncached data such as fetch(...), cached data with a low expire time, or connection() are all examples of data that only resolve on navigation.
To fix this, you can either:
Provide a fallback UI using <Suspense> around this component. This allows Next.js to stream its contents to the user as soon as it's ready, without blocking the rest of the app.
or
Move the asynchronous await into a Cache Component ("use cache"). This allows Next.js to statically prerender the component as part of the HTML document, so it's instantly visible to the user.
Learn more: https://nextjs.org/docs/messages/blocking-route",
"environmentLabel": "Server",
"label": "Blocking Route",
"source": "app/(suspense-in-root)/static/missing-suspense-around-dynamic/page.tsx (6:19) @ Page
> 6 | await connection()
| ^",
"stack": [
"Page app/(suspense-in-root)/static/missing-suspense-around-dynamic/page.tsx (6:19)",
],
}
`)
})
it('invalid - runtime prefetch - missing suspense around dynamic', async () => {
const browser = await next.browser(
'/runtime/missing-suspense-around-dynamic'
)
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Data that blocks navigation was accessed outside of <Suspense>
This delays the entire page from rendering, resulting in a slow user experience. Next.js uses this error to ensure your app loads instantly on every navigation. Uncached data such as fetch(...), cached data with a low expire time, or connection() are all examples of data that only resolve on navigation.
To fix this, you can either:
Provide a fallback UI using <Suspense> around this component. This allows Next.js to stream its contents to the user as soon as it's ready, without blocking the rest of the app.
or
Move the asynchronous await into a Cache Component ("use cache"). This allows Next.js to statically prerender the component as part of the HTML document, so it's instantly visible to the user.
Learn more: https://nextjs.org/docs/messages/blocking-route",
"environmentLabel": "Server",
"label": "Blocking Route",
"source": "app/(suspense-in-root)/runtime/missing-suspense-around-dynamic/page.tsx (25:19) @ Dynamic
> 25 | await connection()
| ^",
"stack": [
"Dynamic app/(suspense-in-root)/runtime/missing-suspense-around-dynamic/page.tsx (25:19)",
"Page app/(suspense-in-root)/runtime/missing-suspense-around-dynamic/page.tsx (18:9)",
],
}
`)
})
it('invalid - static prefetch - missing suspense around dynamic in a layout', async () => {
const browser = await next.browser(
'/static/missing-suspense-around-dynamic-layout'
)
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Runtime data was accessed outside of <Suspense>
This delays the entire page from rendering, resulting in a slow user experience. Next.js uses this error to ensure your app loads instantly on every navigation. cookies(), headers(), and searchParams, are examples of Runtime data that can only come from a user request.
To fix this:
Provide a fallback UI using <Suspense> around this component.
or
Move the Runtime data access into a deeper component wrapped in <Suspense>.
In either case this allows Next.js to stream its contents to the user when they request the page, while still providing an initial UI that is prerendered and prefetchable for instant navigations.
Learn more: https://nextjs.org/docs/messages/blocking-route",
"environmentLabel": "Server",
"label": "Blocking Route",
"source": "app/(suspense-in-root)/static/missing-suspense-around-dynamic-layout/layout.tsx (7:16) @ Layout
> 7 | await cookies()
| ^",
"stack": [
"Layout app/(suspense-in-root)/static/missing-suspense-around-dynamic-layout/layout.tsx (7:16)",
],
}
`)
})
it('invalid - runtime prefetch - missing suspense around dynamic in a layout', async () => {
const browser = await next.browser(
'/runtime/missing-suspense-around-dynamic-layout'
)
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Data that blocks navigation was accessed outside of <Suspense>
This delays the entire page from rendering, resulting in a slow user experience. Next.js uses this error to ensure your app loads instantly on every navigation. Uncached data such as fetch(...), cached data with a low expire time, or connection() are all examples of data that only resolve on navigation.
To fix this, you can either:
Provide a fallback UI using <Suspense> around this component. This allows Next.js to stream its contents to the user as soon as it's ready, without blocking the rest of the app.
or
Move the asynchronous await into a Cache Component ("use cache"). This allows Next.js to statically prerender the component as part of the HTML document, so it's instantly visible to the user.
Learn more: https://nextjs.org/docs/messages/blocking-route",
"environmentLabel": "Server",
"label": "Blocking Route",
"source": "app/(suspense-in-root)/runtime/missing-suspense-around-dynamic-layout/layout.tsx (10:19) @ Layout
> 10 | await connection()
| ^",
"stack": [
"Layout app/(suspense-in-root)/runtime/missing-suspense-around-dynamic-layout/layout.tsx (10:19)",
],
}
`)
})
it('invalid - static prefetch - missing suspense around params', async () => {
const browser = await next.browser(
'/static/missing-suspense-around-params/123'
)
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Runtime data was accessed outside of <Suspense>
This delays the entire page from rendering, resulting in a slow user experience. Next.js uses this error to ensure your app loads instantly on every navigation. cookies(), headers(), and searchParams, are examples of Runtime data that can only come from a user request.
To fix this:
Provide a fallback UI using <Suspense> around this component.
or
Move the Runtime data access into a deeper component wrapped in <Suspense>.
In either case this allows Next.js to stream its contents to the user when they request the page, while still providing an initial UI that is prerendered and prefetchable for instant navigations.
Learn more: https://nextjs.org/docs/messages/blocking-route",
"environmentLabel": "Server",
"label": "Blocking Route",
"source": "app/(suspense-in-root)/static/missing-suspense-around-params/[param]/page.tsx (17:21) @ Runtime
> 17 | const { param } = await params
| ^",
"stack": [
"Runtime app/(suspense-in-root)/static/missing-suspense-around-params/[param]/page.tsx (17:21)",
"Page app/(suspense-in-root)/static/missing-suspense-around-params/[param]/page.tsx (11:7)",
],
}
`)
})
it('valid - runtime prefetch - does not require Suspense around params', async () => {
const browser = await next.browser('/runtime/no-suspense-around-params/123')
await browser.elementByCss('main')
await waitForNoErrorToast(browser)
})
it('valid - target segment not visible in all navigations', async () => {
// Notable special case -- we accept that the segment with the assertion might not
// *itself* be visible in all navigations as long as they're instant.
// A parent layout might be blocked from rendering the children slot,
// but that's fine as long as it provides a fallback.
//
// This is in opposition to an alternate model we considered at some point,
// where putting an assertion on a segment would mean that it must be visible
// in all navigations (which would require that its parent layouts must never
// block the children slots)
const browser = await next.browser('/static/valid-blocked-children')
await browser.elementByCss('main')
await waitForNoErrorToast(browser)
})
it('invalid - static prefetch - suspense too high', async () => {
const browser = await next.browser('/static/suspense-too-high')
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Runtime data was accessed outside of <Suspense>
This delays the entire page from rendering, resulting in a slow user experience. Next.js uses this error to ensure your app loads instantly on every navigation. cookies(), headers(), and searchParams, are examples of Runtime data that can only come from a user request.
To fix this:
Provide a fallback UI using <Suspense> around this component.
or
Move the Runtime data access into a deeper component wrapped in <Suspense>.
In either case this allows Next.js to stream its contents to the user when they request the page, while still providing an initial UI that is prerendered and prefetchable for instant navigations.
Learn more: https://nextjs.org/docs/messages/blocking-route",
"environmentLabel": "Server",
"label": "Blocking Route",
"source": "app/(suspense-in-root)/static/suspense-too-high/page.tsx (6:16) @ Page
> 6 | await cookies()
| ^",
"stack": [
"Page app/(suspense-in-root)/static/suspense-too-high/page.tsx (6:16)",
],
}
`)
})
it('invalid - runtime prefetch - suspense too high', async () => {
const browser = await next.browser('/runtime/suspense-too-high')
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Data that blocks navigation was accessed outside of <Suspense>
This delays the entire page from rendering, resulting in a slow user experience. Next.js uses this error to ensure your app loads instantly on every navigation. Uncached data such as fetch(...), cached data with a low expire time, or connection() are all examples of data that only resolve on navigation.
To fix this, you can either:
Provide a fallback UI using <Suspense> around this component. This allows Next.js to stream its contents to the user as soon as it's ready, without blocking the rest of the app.
or
Move the asynchronous await into a Cache Component ("use cache"). This allows Next.js to statically prerender the component as part of the HTML document, so it's instantly visible to the user.
Learn more: https://nextjs.org/docs/messages/blocking-route",
"environmentLabel": "Server",
"label": "Blocking Route",
"source": "app/(suspense-in-root)/runtime/suspense-too-high/page.tsx (26:19) @ Dynamic
> 26 | await connection()
| ^",
"stack": [
"Dynamic app/(suspense-in-root)/runtime/suspense-too-high/page.tsx (26:19)",
"Page app/(suspense-in-root)/runtime/suspense-too-high/page.tsx (19:9)",
],
}
`)
})
it('invalid - runtime prefetch - sync IO after runtime API', async () => {
const browser = await next.browser('/runtime/invalid-sync-io')
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Route "/runtime/invalid-sync-io" used \`Date.now()\` before accessing either uncached data (e.g. \`fetch()\`) or awaiting \`connection()\`. When configured for Runtime prefetching, accessing the current time in a Server Component requires reading one of these data sources first. Alternatively, consider moving this expression into a Client Component or Cache Component. See more info here: https://nextjs.org/docs/messages/next-prerender-runtime-current-time",
"environmentLabel": "Server",
"label": "Console Error",
"source": "app/(suspense-in-root)/runtime/invalid-sync-io/page.tsx (10:20) @ Page
> 10 | const now = Date.now()
| ^",
"stack": [
"Page app/(suspense-in-root)/runtime/invalid-sync-io/page.tsx (10:20)",
"Page <anonymous>",
],
}
`)
})
it('invalid - missing suspense around dynamic (with loading.js)', async () => {
const browser = await next.browser(
'/static/invalid-only-loading-around-dynamic'
)
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Data that blocks navigation was accessed outside of <Suspense>
This delays the entire page from rendering, resulting in a slow user experience. Next.js uses this error to ensure your app loads instantly on every navigation. Uncached data such as fetch(...), cached data with a low expire time, or connection() are all examples of data that only resolve on navigation.
To fix this, you can either:
Provide a fallback UI using <Suspense> around this component. This allows Next.js to stream its contents to the user as soon as it's ready, without blocking the rest of the app.
or
Move the asynchronous await into a Cache Component ("use cache"). This allows Next.js to statically prerender the component as part of the HTML document, so it's instantly visible to the user.
Learn more: https://nextjs.org/docs/messages/blocking-route",
"environmentLabel": "Server",
"label": "Blocking Route",
"source": "app/(suspense-in-root)/static/invalid-only-loading-around-dynamic/page.tsx (32:19) @ Dynamic
> 32 | await connection()
| ^",
"stack": [
"Dynamic app/(suspense-in-root)/static/invalid-only-loading-around-dynamic/page.tsx (32:19)",
"Page app/(suspense-in-root)/static/invalid-only-loading-around-dynamic/page.tsx (19:9)",
],
}
`)
})
describe.each([
{ clientNav: false, description: 'initial load' },
{ clientNav: true, description: 'client navigation' },
])('$description', ({ clientNav }) => {
/**
* Navigate to a page either via initial load or soft navigation.
* For soft nav, navigates to the index page first, then clicks the link.
*/
async function navigateTo(href: string) {
if (!clientNav) {
// Initial load - navigate directly
const browser = await next.browser(href)
await browser.elementByCss('main')
return browser
}
// Soft nav - go to index page first, then click link
const indexPage = href.startsWith('/default/')
? '/default'
: '/suspense-in-root'
const browser = await next.browser(indexPage)
const initialRootLayoutTimestamp = await browser
.elementById('root-layout-timestamp')
.text()
await browser
.elementByCss(`[data-link-type="soft"][href="${href}"]`)
.click()
await retry(
async () => {
expect(await browser.url()).toContain(href)
},
undefined,
undefined,
'wait for url to change'
)
describe('blocking', () => {
it('valid - blocking layout with unstable_instant = false is allowed to block', async () => {
const browser = await next.browser('/static/blocking-layout')
await browser.elementByCss('main')
// Sanity check: we shouldn't have switched or otherwise refetched the root layout
const finalRootLayoutTimestamp = await browser
.elementById('root-layout-timestamp')
.text()
expect(initialRootLayoutTimestamp).toBe(finalRootLayoutTimestamp)
return browser
}
it('valid - static prefetch - suspense around runtime and dynamic', async () => {
const browser = await navigateTo(
'/suspense-in-root/static/suspense-around-dynamic'
)
await waitForNoErrorToast(browser)
})
it('valid - runtime prefetch - suspense only around dynamic', async () => {
const browser = await navigateTo(
'/suspense-in-root/runtime/suspense-around-dynamic'
)
await waitForNoErrorToast(browser)
})
it('invalid - missing suspense inside blocking layout', async () => {
const browser = await next.browser(
'/static/blocking-layout/missing-suspense-around-dynamic'
it('invalid - static prefetch - missing suspense around runtime', async () => {
const browser = await navigateTo(
'/suspense-in-root/static/missing-suspense-around-runtime'
)
await expect(browser).toDisplayCollapsedRedbox(`
{
......@@ -379,32 +100,80 @@ describe.each([
Learn more: https://nextjs.org/docs/messages/blocking-route",
"environmentLabel": "Server",
"label": "Blocking Route",
"source": "app/(suspense-in-root)/static/blocking-layout/missing-suspense-around-dynamic/page.tsx (6:16) @ Page
"source": "app/suspense-in-root/static/missing-suspense-around-runtime/page.tsx (6:16) @ Page
> 6 | await cookies()
| ^",
"stack": [
"Page app/(suspense-in-root)/static/blocking-layout/missing-suspense-around-dynamic/page.tsx (6:16)",
"Page app/suspense-in-root/static/missing-suspense-around-runtime/page.tsx (6:16)",
],
}
`)
})
it('invalid - static prefetch - missing suspense around dynamic', async () => {
const browser = await navigateTo(
'/suspense-in-root/static/missing-suspense-around-dynamic'
)
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Data that blocks navigation was accessed outside of <Suspense>
it('valid - blocking page inside a static layout is allowed if the layout has suspense', async () => {
const browser = await next.browser('/static/valid-blocking-inside-static')
await browser.elementByCss('main')
await waitForNoErrorToast(browser)
This delays the entire page from rendering, resulting in a slow user experience. Next.js uses this error to ensure your app loads instantly on every navigation. Uncached data such as fetch(...), cached data with a low expire time, or connection() are all examples of data that only resolve on navigation.
To fix this, you can either:
Provide a fallback UI using <Suspense> around this component. This allows Next.js to stream its contents to the user as soon as it's ready, without blocking the rest of the app.
or
Move the asynchronous await into a Cache Component ("use cache"). This allows Next.js to statically prerender the component as part of the HTML document, so it's instantly visible to the user.
Learn more: https://nextjs.org/docs/messages/blocking-route",
"environmentLabel": "Server",
"label": "Blocking Route",
"source": "app/suspense-in-root/static/missing-suspense-around-dynamic/page.tsx (6:19) @ Page
> 6 | await connection()
| ^",
"stack": [
"Page app/suspense-in-root/static/missing-suspense-around-dynamic/page.tsx (6:19)",
],
}
`)
})
it('valid - blocking page inside a runtime layout is allowed if the layout has suspense', async () => {
const browser = await next.browser(
'/runtime/valid-blocking-inside-runtime'
it('invalid - runtime prefetch - missing suspense around dynamic', async () => {
const browser = await navigateTo(
'/suspense-in-root/runtime/missing-suspense-around-dynamic'
)
await browser.elementByCss('main')
await waitForNoErrorToast(browser)
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Data that blocks navigation was accessed outside of <Suspense>
This delays the entire page from rendering, resulting in a slow user experience. Next.js uses this error to ensure your app loads instantly on every navigation. Uncached data such as fetch(...), cached data with a low expire time, or connection() are all examples of data that only resolve on navigation.
To fix this, you can either:
Provide a fallback UI using <Suspense> around this component. This allows Next.js to stream its contents to the user as soon as it's ready, without blocking the rest of the app.
or
Move the asynchronous await into a Cache Component ("use cache"). This allows Next.js to statically prerender the component as part of the HTML document, so it's instantly visible to the user.
Learn more: https://nextjs.org/docs/messages/blocking-route",
"environmentLabel": "Server",
"label": "Blocking Route",
"source": "app/suspense-in-root/runtime/missing-suspense-around-dynamic/page.tsx (25:19) @ Dynamic
> 25 | await connection()
| ^",
"stack": [
"Dynamic app/suspense-in-root/runtime/missing-suspense-around-dynamic/page.tsx (25:19)",
"Page app/suspense-in-root/runtime/missing-suspense-around-dynamic/page.tsx (18:9)",
],
}
`)
})
it('invalid - blocking page inside a static layout is not allowed if the layout has no suspense', async () => {
const browser = await next.browser(
'/static/invalid-blocking-inside-static'
it('invalid - static prefetch - missing suspense around dynamic in a layout', async () => {
const browser = await navigateTo(
'/suspense-in-root/static/missing-suspense-around-dynamic-layout'
)
await expect(browser).toDisplayCollapsedRedbox(`
{
......@@ -425,18 +194,18 @@ describe.each([
Learn more: https://nextjs.org/docs/messages/blocking-route",
"environmentLabel": "Server",
"label": "Blocking Route",
"source": "app/(suspense-in-root)/static/invalid-blocking-inside-static/page.tsx (6:16) @ BlockingPage
> 6 | await cookies()
| ^",
"source": "app/suspense-in-root/static/missing-suspense-around-dynamic-layout/layout.tsx (7:16) @ Layout
> 7 | await cookies()
| ^",
"stack": [
"BlockingPage app/(suspense-in-root)/static/invalid-blocking-inside-static/page.tsx (6:16)",
"Layout app/suspense-in-root/static/missing-suspense-around-dynamic-layout/layout.tsx (7:16)",
],
}
`)
})
it('invalid - blocking page inside a runtime layout is not allowed if the layout has no suspense', async () => {
const browser = await next.browser(
'/runtime/invalid-blocking-inside-runtime'
it('invalid - runtime prefetch - missing suspense around dynamic in a layout', async () => {
const browser = await navigateTo(
'/suspense-in-root/runtime/missing-suspense-around-dynamic-layout'
)
await expect(browser).toDisplayCollapsedRedbox(`
{
......@@ -455,21 +224,19 @@ describe.each([
Learn more: https://nextjs.org/docs/messages/blocking-route",
"environmentLabel": "Server",
"label": "Blocking Route",
"source": "app/(suspense-in-root)/runtime/invalid-blocking-inside-runtime/page.tsx (6:19) @ BlockingPage
> 6 | await connection()
| ^",
"source": "app/suspense-in-root/runtime/missing-suspense-around-dynamic-layout/layout.tsx (10:19) @ Layout
> 10 | await connection()
| ^",
"stack": [
"BlockingPage app/(suspense-in-root)/runtime/invalid-blocking-inside-runtime/page.tsx (6:19)",
"Layout app/suspense-in-root/runtime/missing-suspense-around-dynamic-layout/layout.tsx (10:19)",
],
}
`)
})
})
describe('invalid - missing suspense in parallel slot', () => {
it('index', async () => {
const browser = await next.browser(
'/static/missing-suspense-in-parallel-route'
it('invalid - static prefetch - missing suspense around params', async () => {
const browser = await navigateTo(
'/suspense-in-root/static/missing-suspense-around-params/123'
)
await expect(browser).toDisplayCollapsedRedbox(`
{
......@@ -490,19 +257,40 @@ describe.each([
Learn more: https://nextjs.org/docs/messages/blocking-route",
"environmentLabel": "Server",
"label": "Blocking Route",
"source": "app/(suspense-in-root)/static/missing-suspense-in-parallel-route/@slot/page.tsx (4:16) @ IndexSlot
> 4 | await cookies()
| ^",
"source": "app/suspense-in-root/static/missing-suspense-around-params/[param]/page.tsx (17:21) @ Runtime
> 17 | const { param } = await params
| ^",
"stack": [
"IndexSlot app/(suspense-in-root)/static/missing-suspense-in-parallel-route/@slot/page.tsx (4:16)",
"Runtime app/suspense-in-root/static/missing-suspense-around-params/[param]/page.tsx (17:21)",
"Page app/suspense-in-root/static/missing-suspense-around-params/[param]/page.tsx (11:7)",
],
}
`)
})
it('valid - runtime prefetch - does not require Suspense around params', async () => {
const browser = await navigateTo(
'/suspense-in-root/runtime/no-suspense-around-params/123'
)
await waitForNoErrorToast(browser)
})
it('subpage', async () => {
const browser = await next.browser(
'/static/missing-suspense-in-parallel-route/foo'
it('valid - target segment not visible in all navigations', async () => {
// Notable special case -- we accept that the segment with the assertion might not
// *itself* be visible in all navigations as long as they're instant.
// A parent layout might be blocked from rendering the children slot,
// but that's fine as long as it provides a fallback.
//
// This is in opposition to an alternate model we considered at some point,
// where putting an assertion on a segment would mean that it must be visible
// in all navigations (which would require that its parent layouts must never
// block the children slots)
const browser = await navigateTo('/default/static/valid-blocked-children')
await waitForNoErrorToast(browser)
})
it('invalid - static prefetch - suspense too high', async () => {
const browser = await navigateTo(
'/suspense-in-root/static/suspense-too-high'
)
await expect(browser).toDisplayCollapsedRedbox(`
{
......@@ -523,67 +311,336 @@ describe.each([
Learn more: https://nextjs.org/docs/messages/blocking-route",
"environmentLabel": "Server",
"label": "Blocking Route",
"source": "app/(suspense-in-root)/static/missing-suspense-in-parallel-route/@slot/foo/page.tsx (4:16) @ FooSlot
> 4 | await cookies()
"source": "app/suspense-in-root/static/suspense-too-high/page.tsx (6:16) @ Page
> 6 | await cookies()
| ^",
"stack": [
"FooSlot app/(suspense-in-root)/static/missing-suspense-in-parallel-route/@slot/foo/page.tsx (4:16)",
"Page app/suspense-in-root/static/suspense-too-high/page.tsx (6:16)",
],
}
`)
})
it('default slot', async () => {
const browser = await next.browser(
'/static/missing-suspense-in-parallel-route/bar'
it('invalid - runtime prefetch - suspense too high', async () => {
const browser = await navigateTo(
'/suspense-in-root/runtime/suspense-too-high'
)
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Runtime data was accessed outside of <Suspense>
"description": "Data that blocks navigation was accessed outside of <Suspense>
This delays the entire page from rendering, resulting in a slow user experience. Next.js uses this error to ensure your app loads instantly on every navigation. cookies(), headers(), and searchParams, are examples of Runtime data that can only come from a user request.
This delays the entire page from rendering, resulting in a slow user experience. Next.js uses this error to ensure your app loads instantly on every navigation. Uncached data such as fetch(...), cached data with a low expire time, or connection() are all examples of data that only resolve on navigation.
To fix this:
To fix this, you can either:
Provide a fallback UI using <Suspense> around this component.
Provide a fallback UI using <Suspense> around this component. This allows Next.js to stream its contents to the user as soon as it's ready, without blocking the rest of the app.
or
Move the Runtime data access into a deeper component wrapped in <Suspense>.
Move the asynchronous await into a Cache Component ("use cache"). This allows Next.js to statically prerender the component as part of the HTML document, so it's instantly visible to the user.
In either case this allows Next.js to stream its contents to the user when they request the page, while still providing an initial UI that is prerendered and prefetchable for instant navigations.
Learn more: https://nextjs.org/docs/messages/blocking-route",
"environmentLabel": "Server",
"label": "Blocking Route",
"source": "app/suspense-in-root/runtime/suspense-too-high/page.tsx (26:19) @ Dynamic
> 26 | await connection()
| ^",
"stack": [
"Dynamic app/suspense-in-root/runtime/suspense-too-high/page.tsx (26:19)",
"Page app/suspense-in-root/runtime/suspense-too-high/page.tsx (19:9)",
],
}
`)
})
it('invalid - runtime prefetch - sync IO after runtime API', async () => {
const browser = await navigateTo(
'/suspense-in-root/runtime/invalid-sync-io'
)
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Route "/suspense-in-root/runtime/invalid-sync-io" used \`Date.now()\` before accessing either uncached data (e.g. \`fetch()\`) or awaiting \`connection()\`. When configured for Runtime prefetching, accessing the current time in a Server Component requires reading one of these data sources first. Alternatively, consider moving this expression into a Client Component or Cache Component. See more info here: https://nextjs.org/docs/messages/next-prerender-runtime-current-time",
"environmentLabel": "Server",
"label": "Console Error",
"source": "app/suspense-in-root/runtime/invalid-sync-io/page.tsx (10:20) @ Page
> 10 | const now = Date.now()
| ^",
"stack": [
"Page app/suspense-in-root/runtime/invalid-sync-io/page.tsx (10:20)",
"Page <anonymous>",
],
}
`)
})
it('invalid - missing suspense around dynamic (with loading.js)', async () => {
const browser = await navigateTo(
'/suspense-in-root/static/invalid-only-loading-around-dynamic'
)
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Data that blocks navigation was accessed outside of <Suspense>
This delays the entire page from rendering, resulting in a slow user experience. Next.js uses this error to ensure your app loads instantly on every navigation. Uncached data such as fetch(...), cached data with a low expire time, or connection() are all examples of data that only resolve on navigation.
To fix this, you can either:
Provide a fallback UI using <Suspense> around this component. This allows Next.js to stream its contents to the user as soon as it's ready, without blocking the rest of the app.
or
Move the asynchronous await into a Cache Component ("use cache"). This allows Next.js to statically prerender the component as part of the HTML document, so it's instantly visible to the user.
Learn more: https://nextjs.org/docs/messages/blocking-route",
"environmentLabel": "Server",
"label": "Blocking Route",
"source": "app/(suspense-in-root)/static/missing-suspense-in-parallel-route/@slot/default.tsx (4:16) @ DefaultSlot
> 4 | await cookies()
| ^",
"source": "app/suspense-in-root/static/invalid-only-loading-around-dynamic/page.tsx (32:19) @ Dynamic
> 32 | await connection()
| ^",
"stack": [
"DefaultSlot app/(suspense-in-root)/static/missing-suspense-in-parallel-route/@slot/default.tsx (4:16)",
"Dynamic app/suspense-in-root/static/invalid-only-loading-around-dynamic/page.tsx (32:19)",
"Page app/suspense-in-root/static/invalid-only-loading-around-dynamic/page.tsx (19:9)",
],
}
`)
})
})
describe('disabling validation', () => {
it('in a layout', async () => {
const browser = await next.browser('/disable-validation/in-layout')
await browser.elementByCss('main')
await waitForNoErrorToast(browser)
describe('blocking', () => {
it('valid - blocking layout with unstable_instant = false is allowed to block', async () => {
const browser = await navigateTo(
'/suspense-in-root/static/blocking-layout'
)
await waitForNoErrorToast(browser)
})
it('invalid - missing suspense inside blocking layout', async () => {
const browser = await navigateTo(
'/suspense-in-root/static/blocking-layout/missing-suspense-around-dynamic'
)
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Runtime data was accessed outside of <Suspense>
This delays the entire page from rendering, resulting in a slow user experience. Next.js uses this error to ensure your app loads instantly on every navigation. cookies(), headers(), and searchParams, are examples of Runtime data that can only come from a user request.
To fix this:
Provide a fallback UI using <Suspense> around this component.
or
Move the Runtime data access into a deeper component wrapped in <Suspense>.
In either case this allows Next.js to stream its contents to the user when they request the page, while still providing an initial UI that is prerendered and prefetchable for instant navigations.
Learn more: https://nextjs.org/docs/messages/blocking-route",
"environmentLabel": "Server",
"label": "Blocking Route",
"source": "app/suspense-in-root/static/blocking-layout/missing-suspense-around-dynamic/page.tsx (6:16) @ Page
> 6 | await cookies()
| ^",
"stack": [
"Page app/suspense-in-root/static/blocking-layout/missing-suspense-around-dynamic/page.tsx (6:16)",
],
}
`)
})
it('valid - blocking page inside a static layout is allowed if the layout has suspense', async () => {
const browser = await navigateTo(
'/default/static/valid-blocking-inside-static'
)
await waitForNoErrorToast(browser)
})
it('valid - blocking page inside a runtime layout is allowed if the layout has suspense', async () => {
const browser = await navigateTo(
'/suspense-in-root/runtime/valid-blocking-inside-runtime'
)
await waitForNoErrorToast(browser)
})
it('invalid - blocking page inside a static layout is not allowed if the layout has no suspense', async () => {
const browser = await navigateTo(
'/suspense-in-root/static/invalid-blocking-inside-static'
)
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Runtime data was accessed outside of <Suspense>
This delays the entire page from rendering, resulting in a slow user experience. Next.js uses this error to ensure your app loads instantly on every navigation. cookies(), headers(), and searchParams, are examples of Runtime data that can only come from a user request.
To fix this:
Provide a fallback UI using <Suspense> around this component.
or
Move the Runtime data access into a deeper component wrapped in <Suspense>.
In either case this allows Next.js to stream its contents to the user when they request the page, while still providing an initial UI that is prerendered and prefetchable for instant navigations.
Learn more: https://nextjs.org/docs/messages/blocking-route",
"environmentLabel": "Server",
"label": "Blocking Route",
"source": "app/suspense-in-root/static/invalid-blocking-inside-static/page.tsx (6:16) @ BlockingPage
> 6 | await cookies()
| ^",
"stack": [
"BlockingPage app/suspense-in-root/static/invalid-blocking-inside-static/page.tsx (6:16)",
],
}
`)
})
it('invalid - blocking page inside a runtime layout is not allowed if the layout has no suspense', async () => {
const browser = await navigateTo(
'/suspense-in-root/runtime/invalid-blocking-inside-runtime'
)
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Data that blocks navigation was accessed outside of <Suspense>
This delays the entire page from rendering, resulting in a slow user experience. Next.js uses this error to ensure your app loads instantly on every navigation. Uncached data such as fetch(...), cached data with a low expire time, or connection() are all examples of data that only resolve on navigation.
To fix this, you can either:
Provide a fallback UI using <Suspense> around this component. This allows Next.js to stream its contents to the user as soon as it's ready, without blocking the rest of the app.
or
Move the asynchronous await into a Cache Component ("use cache"). This allows Next.js to statically prerender the component as part of the HTML document, so it's instantly visible to the user.
Learn more: https://nextjs.org/docs/messages/blocking-route",
"environmentLabel": "Server",
"label": "Blocking Route",
"source": "app/suspense-in-root/runtime/invalid-blocking-inside-runtime/page.tsx (6:19) @ BlockingPage
> 6 | await connection()
| ^",
"stack": [
"BlockingPage app/suspense-in-root/runtime/invalid-blocking-inside-runtime/page.tsx (6:19)",
],
}
`)
})
})
it('in a page', async () => {
const browser = await next.browser('/disable-validation/in-page')
await browser.elementByCss('main')
await waitForNoErrorToast(browser)
describe('invalid - missing suspense in parallel slot', () => {
it('index', async () => {
const browser = await navigateTo(
'/suspense-in-root/static/missing-suspense-in-parallel-route'
)
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Runtime data was accessed outside of <Suspense>
This delays the entire page from rendering, resulting in a slow user experience. Next.js uses this error to ensure your app loads instantly on every navigation. cookies(), headers(), and searchParams, are examples of Runtime data that can only come from a user request.
To fix this:
Provide a fallback UI using <Suspense> around this component.
or
Move the Runtime data access into a deeper component wrapped in <Suspense>.
In either case this allows Next.js to stream its contents to the user when they request the page, while still providing an initial UI that is prerendered and prefetchable for instant navigations.
Learn more: https://nextjs.org/docs/messages/blocking-route",
"environmentLabel": "Server",
"label": "Blocking Route",
"source": "app/suspense-in-root/static/missing-suspense-in-parallel-route/@slot/page.tsx (4:16) @ IndexSlot
> 4 | await cookies()
| ^",
"stack": [
"IndexSlot app/suspense-in-root/static/missing-suspense-in-parallel-route/@slot/page.tsx (4:16)",
],
}
`)
})
it('subpage', async () => {
const browser = await navigateTo(
'/suspense-in-root/static/missing-suspense-in-parallel-route/foo'
)
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Runtime data was accessed outside of <Suspense>
This delays the entire page from rendering, resulting in a slow user experience. Next.js uses this error to ensure your app loads instantly on every navigation. cookies(), headers(), and searchParams, are examples of Runtime data that can only come from a user request.
To fix this:
Provide a fallback UI using <Suspense> around this component.
or
Move the Runtime data access into a deeper component wrapped in <Suspense>.
In either case this allows Next.js to stream its contents to the user when they request the page, while still providing an initial UI that is prerendered and prefetchable for instant navigations.
Learn more: https://nextjs.org/docs/messages/blocking-route",
"environmentLabel": "Server",
"label": "Blocking Route",
"source": "app/suspense-in-root/static/missing-suspense-in-parallel-route/@slot/foo/page.tsx (4:16) @ FooSlot
> 4 | await cookies()
| ^",
"stack": [
"FooSlot app/suspense-in-root/static/missing-suspense-in-parallel-route/@slot/foo/page.tsx (4:16)",
],
}
`)
})
it('default slot', async () => {
const browser = await navigateTo(
'/suspense-in-root/static/missing-suspense-in-parallel-route/bar'
)
await expect(browser).toDisplayCollapsedRedbox(`
{
"description": "Runtime data was accessed outside of <Suspense>
This delays the entire page from rendering, resulting in a slow user experience. Next.js uses this error to ensure your app loads instantly on every navigation. cookies(), headers(), and searchParams, are examples of Runtime data that can only come from a user request.
To fix this:
Provide a fallback UI using <Suspense> around this component.
or
Move the Runtime data access into a deeper component wrapped in <Suspense>.
In either case this allows Next.js to stream its contents to the user when they request the page, while still providing an initial UI that is prerendered and prefetchable for instant navigations.
Learn more: https://nextjs.org/docs/messages/blocking-route",
"environmentLabel": "Server",
"label": "Blocking Route",
"source": "app/suspense-in-root/static/missing-suspense-in-parallel-route/@slot/default.tsx (4:16) @ DefaultSlot
> 4 | await cookies()
| ^",
"stack": [
"DefaultSlot app/suspense-in-root/static/missing-suspense-in-parallel-route/@slot/default.tsx (4:16)",
],
}
`)
})
})
it('in a page with a parent that has a config', async () => {
const browser = await next.browser(
'/disable-validation/in-page-with-outer'
)
await browser.elementByCss('main')
await waitForNoErrorToast(browser)
describe('disabling validation', () => {
it('in a layout', async () => {
const browser = await navigateTo(
'/suspense-in-root/disable-validation/in-layout'
)
await waitForNoErrorToast(browser)
})
it('in a page', async () => {
const browser = await navigateTo(
'/suspense-in-root/disable-validation/in-page'
)
await waitForNoErrorToast(browser)
})
it('in a page with a parent that has a config', async () => {
const browser = await navigateTo(
'/suspense-in-root/disable-validation/in-page-with-outer'
)
await waitForNoErrorToast(browser)
})
})
})
})
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