Unverified Commit 15d2272c authored by Aurora Scharff's avatar Aurora Scharff Committed by GitHub

Distinguish in-navigation errors in the instant error overlay (#93843)

### What?

When instant validation flags a route that can't load instantly, the
overlay shows a warning. This PR (1) distinguishes nav-phase warnings
from initial-render ones in the overlay text, and (2) clears the
nav-phase warnings on route change so they don't accumulate after the
user has moved on.

### Why?

The redbox previously couldn't tell whether a route's instant warning
was raised while rendering it directly or while navigating into it — the
text and stack looked the same. And once one was surfaced, it stuck
around even after the user navigated elsewhere, where it was no longer
actionable. The two changes together make each warning describe the
phase that produced it and only stay visible while it's still relevant.

### Demo

- Subnav under Suspense:
[cookies](https://error-messages-overhaul-ibsl.labs.vercel.dev/scenario/41-subnav-cookies)
·
[fetch](https://error-messages-overhaul-ibsl.labs.vercel.dev/scenario/42-subnav-fetch)

### How

- New in-navigation variants of the body factory messages ("during the
initial render or a navigation") let the overlay tell nav warnings apart
from initial-render ones. The diagnostic clause stays aligned ("accessed
outside of \`<Suspense>\`"); only the phase and consequence change.
- The overlay reads the phase off the message, picks a matching
headline, and on route change drops nav warnings while keeping
initial-render errors in the redbox stack.
- Renames the \`GuidanceVariant\` value (\`'navigation' → 'dynamic'\`)
that collided with the new in-nav phase concept.

---------
Co-authored-by: 's avatarCursor <cursoragent@cursor.com>
parent f46db1c4
...@@ -11,6 +11,7 @@ import { ...@@ -11,6 +11,7 @@ import {
ACTION_BUILDING_INDICATOR_HIDE, ACTION_BUILDING_INDICATOR_HIDE,
ACTION_BUILDING_INDICATOR_SHOW, ACTION_BUILDING_INDICATOR_SHOW,
ACTION_CACHE_INDICATOR, ACTION_CACHE_INDICATOR,
ACTION_INSTANT_ERRORS_CLEAR,
ACTION_INSTANT_NAVS_TOGGLE, ACTION_INSTANT_NAVS_TOGGLE,
ACTION_INSTANT_NAVS_RESET, ACTION_INSTANT_NAVS_RESET,
ACTION_DEBUG_INFO, ACTION_DEBUG_INFO,
...@@ -88,6 +89,7 @@ export function useStorybookOverlayReducer(initialState?: OverlayState) { ...@@ -88,6 +89,7 @@ export function useStorybookOverlayReducer(initialState?: OverlayState) {
case ACTION_RENDERING_INDICATOR_HIDE: case ACTION_RENDERING_INDICATOR_HIDE:
case ACTION_RENDERING_INDICATOR_SHOW: case ACTION_RENDERING_INDICATOR_SHOW:
case ACTION_CACHE_INDICATOR: case ACTION_CACHE_INDICATOR:
case ACTION_INSTANT_ERRORS_CLEAR:
case ACTION_INSTANT_NAVS_TOGGLE: case ACTION_INSTANT_NAVS_TOGGLE:
case ACTION_INSTANT_NAVS_RESET: case ACTION_INSTANT_NAVS_RESET:
case ACTION_STATIC_INDICATOR: case ACTION_STATIC_INDICATOR:
......
...@@ -1244,8 +1244,13 @@ ...@@ -1244,8 +1244,13 @@
"1243": "This \"use cache\" has a dynamic cache life that was propagated to its parent.", "1243": "This \"use cache\" has a dynamic cache life that was propagated to its parent.",
"1244": "A \"use cache\" with short \\`expire\\` (under 5 minutes) is nested inside another \"use cache\" that has no explicit \\`cacheLife\\`, which is not allowed during prerendering. Add \\`cacheLife()\\` to the outer \"use cache\" to choose whether it should be prerendered (with longer \\`expire\\`) or remain dynamic (with short \\`expire\\`). Read more: https://nextjs.org/docs/messages/nested-use-cache-no-explicit-cachelife", "1244": "A \"use cache\" with short \\`expire\\` (under 5 minutes) is nested inside another \"use cache\" that has no explicit \\`cacheLife\\`, which is not allowed during prerendering. Add \\`cacheLife()\\` to the outer \"use cache\" to choose whether it should be prerendered (with longer \\`expire\\`) or remain dynamic (with short \\`expire\\`). Read more: https://nextjs.org/docs/messages/nested-use-cache-no-explicit-cachelife",
"1245": "A \"use cache\" with zero \\`revalidate\\` is nested inside another \"use cache\" that has no explicit \\`cacheLife\\`, which is not allowed during prerendering. Add \\`cacheLife()\\` to the outer \"use cache\" to choose whether it should be prerendered (with non-zero \\`revalidate\\`) or remain dynamic (with zero \\`revalidate\\`). Read more: https://nextjs.org/docs/messages/nested-use-cache-no-explicit-cachelife", "1245": "A \"use cache\" with zero \\`revalidate\\` is nested inside another \"use cache\" that has no explicit \\`cacheLife\\`, which is not allowed during prerendering. Add \\`cacheLife()\\` to the outer \"use cache\" to choose whether it should be prerendered (with non-zero \\`revalidate\\`) or remain dynamic (with zero \\`revalidate\\`). Read more: https://nextjs.org/docs/messages/nested-use-cache-no-explicit-cachelife",
"1246": "Could not validate instant UI because an expected segment was not rendered.", "1246": "Route \"%s\": Next.js encountered uncached data during the initial render or a navigation.\\n\\n\\`fetch(...)\\` or \\`connection()\\` accessed under \\`<Suspense>\\` prevents the route from being prerendered or the navigation from being instant, leading to a slower user experience.\\n\\nWays to fix this:\\n - Cache the data access with \\`\"use cache\"\\`\\n - Provide a placeholder with \\`<Suspense fallback={...}>\\` around the data access\\n - Set \\`export const instant = false\\` to allow a blocking route\\n\\nLearn more: https://nextjs.org/docs/messages/blocking-route",
"1247": "\\`experimental.cssChunking: \"graph\"\\` is only supported with Turbopack. Please remove the option or run Next.js with Turbopack in %s.", "1247": "Route \"%s\": Next.js encountered runtime data during the initial render or a navigation.\\n\\n\\`cookies()\\`, \\`headers()\\`, \\`params\\`, or \\`searchParams\\` accessed under \\`<Suspense>\\` prevents the route from being prerendered or the navigation from being instant, leading to a slower user experience.\\n\\nWays to fix this:\\n - Use \\`generateStaticParams\\` to make route params static\\n - Provide a placeholder with \\`<Suspense fallback={...}>\\` around the data access\\n - Set \\`export const instant = false\\` to allow a blocking route\\n\\nLearn more: https://nextjs.org/docs/messages/blocking-route",
"1248": "\\`experimental.cssChunking: \"strict\"\\` is only supported with webpack. Please remove the option or run Next.js with webpack in %s.", "1248": "Could not validate instant UI because an expected segment was not rendered.",
"1249": "\\`experimental.cssChunking: false\\` is only supported with webpack. Please remove the option or run Next.js with webpack in %s." "1249": "Route \"%s\": Next.js encountered uncached data during the initial render or a navigation.\\n\\n\\`fetch(...)\\` or \\`connection()\\` accessed outside of \\`<Suspense>\\` prevents the route from being prerendered or the navigation from being instant, leading to a slower user experience.\\n\\nWays to fix this:\\n - Cache the data access with \\`\"use cache\"\\`\\n - Provide a placeholder with \\`<Suspense fallback={...}>\\` around the data access\\n - Set \\`export const instant = false\\` to allow a blocking route\\n\\nLearn more: https://nextjs.org/docs/messages/blocking-route",
"1250": "Route \"%s\": Next.js encountered runtime data during the initial render or a navigation.\\n\\n\\`cookies()\\`, \\`headers()\\`, \\`params\\`, or \\`searchParams\\` accessed outside of \\`<Suspense>\\` prevents the route from being prerendered or the navigation from being instant, leading to a slower user experience.\\n\\nWays to fix this:\\n - Use \\`generateStaticParams\\` to make route params static\\n - Provide a placeholder with \\`<Suspense fallback={...}>\\` around the data access\\n - Set \\`export const instant = false\\` to allow a blocking route\\n\\nLearn more: https://nextjs.org/docs/messages/blocking-route",
"1251": "Route \"%s\": Next.js encountered runtime data during the initial render or a navigation.\\n\\n\\`cookies()\\`, \\`headers()\\`, \\`params\\`, or \\`searchParams\\` accessed outside of \\`<Suspense>\\` prevents the route from being prerendered or the navigation from being instant, leading to a slower user experience.\\n\\nWays to fix this:\\n - Provide a placeholder with \\`<Suspense fallback={...}>\\` around the data access\\n - Use \\`generateStaticParams\\` to make route params static\\n - Set \\`export const instant = false\\` to allow a blocking route\\n\\nLearn more: https://nextjs.org/docs/messages/blocking-route",
"1252": "\\`experimental.cssChunking: \"graph\"\\` is only supported with Turbopack. Please remove the option or run Next.js with Turbopack in %s.",
"1253": "\\`experimental.cssChunking: \"strict\"\\` is only supported with webpack. Please remove the option or run Next.js with webpack in %s.",
"1254": "\\`experimental.cssChunking: false\\` is only supported with webpack. Please remove the option or run Next.js with webpack in %s."
} }
...@@ -486,7 +486,7 @@ export type GuidanceKind = ...@@ -486,7 +486,7 @@ export type GuidanceKind =
| 'sync-io' | 'sync-io'
| 'sync-io-client' | 'sync-io-client'
export type GuidanceVariant = 'runtime' | 'navigation' export type GuidanceVariant = 'runtime' | 'dynamic'
export const DOCS_URLS: Record<GuidanceKind, string> = { export const DOCS_URLS: Record<GuidanceKind, string> = {
'blocking-route': 'https://nextjs.org/docs/messages/blocking-route', 'blocking-route': 'https://nextjs.org/docs/messages/blocking-route',
...@@ -562,6 +562,9 @@ export const EXPLANATIONS: Record<GuidanceKind, string> = { ...@@ -562,6 +562,9 @@ export const EXPLANATIONS: Record<GuidanceKind, string> = {
'This value would be evaluated during the prerender and fixed at build time, instead of recomputed on each visit.', 'This value would be evaluated during the prerender and fixed at build time, instead of recomputed on each visit.',
} }
export const BLOCKING_ROUTE_NAVIGATION_EXPLANATION =
'This prevents the navigation from being instant, leading to a slower user experience.'
const syncCardsByCause: Record<string, FixCard[]> = { const syncCardsByCause: Record<string, FixCard[]> = {
'Math.random()': syncMathCards, 'Math.random()': syncMathCards,
'Date.now()': syncDateCards, 'Date.now()': syncDateCards,
...@@ -601,7 +604,7 @@ export function getCards( ...@@ -601,7 +604,7 @@ export function getCards(
): FixCard[] { ): FixCard[] {
switch (kind) { switch (kind) {
case 'blocking-route': case 'blocking-route':
return variant === 'navigation' ? dynamicCards : runtimeCards return variant === 'dynamic' ? dynamicCards : runtimeCards
case 'metadata': case 'metadata':
return variant === 'runtime' ? metadataRuntimeCards : metadataDynamicCards return variant === 'runtime' ? metadataRuntimeCards : metadataDynamicCards
case 'viewport': case 'viewport':
......
import { import {
createDynamicBodyError, createDynamicBodyError,
createDynamicBodyErrorInNavigation,
createDynamicMetadataError, createDynamicMetadataError,
createDynamicOrRuntimeBodyError, createDynamicOrRuntimeBodyError,
createDynamicOrRuntimeMetadataError, createDynamicOrRuntimeMetadataError,
createDynamicOrRuntimeViewportError, createDynamicOrRuntimeViewportError,
createDynamicViewportError, createDynamicViewportError,
createRuntimeBodyError, createRuntimeBodyError,
createRuntimeBodyErrorInNavigation,
createRuntimeMetadataError, createRuntimeMetadataError,
createRuntimeViewportError, createRuntimeViewportError,
} from '../../../server/app-render/blocking-route-messages' } from '../../../server/app-render/blocking-route-messages'
...@@ -24,14 +26,6 @@ import { ...@@ -24,14 +26,6 @@ import {
const ROUTE = '/example' const ROUTE = '/example'
// Every detection helper in errors.tsx walks the user-facing error message
// produced by the server-side factories in `blocking-route-messages.ts` and
// `sync-io-messages.ts`. These tests guard the contract between the two
// modules: if a factory's wording shifts in a way the detector can't
// recognize, classification silently falls back to "not an instant error"
// and the overlay shows the wrong UI. Three regressions in this exact spot
// during the redesign motivated this test.
describe('isRuntimeVariant', () => { describe('isRuntimeVariant', () => {
it('returns true for runtime body factory output', () => { it('returns true for runtime body factory output', () => {
expect(isRuntimeVariant(createRuntimeBodyError(ROUTE).message)).toBe(true) expect(isRuntimeVariant(createRuntimeBodyError(ROUTE).message)).toBe(true)
...@@ -128,24 +122,48 @@ describe('isSyncIOClientError', () => { ...@@ -128,24 +122,48 @@ describe('isSyncIOClientError', () => {
}) })
describe('getBlockingRouteErrorDetails', () => { describe('getBlockingRouteErrorDetails', () => {
it('classifies createRuntimeBodyError as blocking-route + runtime', () => { it('classifies createRuntimeBodyError as blocking-route + runtime (SSR-only)', () => {
expect(getBlockingRouteErrorDetails(createRuntimeBodyError(ROUTE))).toEqual( expect(getBlockingRouteErrorDetails(createRuntimeBodyError(ROUTE))).toEqual(
{ type: 'blocking-route', variant: 'runtime' } { type: 'blocking-route', variant: 'runtime', inNavigation: false }
) )
}) })
it('classifies createDynamicBodyError as blocking-route + navigation', () => { it('classifies createDynamicBodyError as blocking-route + dynamic (SSR-only)', () => {
expect(getBlockingRouteErrorDetails(createDynamicBodyError(ROUTE))).toEqual( expect(getBlockingRouteErrorDetails(createDynamicBodyError(ROUTE))).toEqual(
{ type: 'blocking-route', variant: 'navigation' } { type: 'blocking-route', variant: 'dynamic', inNavigation: false }
) )
}) })
it('classifies createDynamicOrRuntimeBodyError as blocking-route + navigation', () => { it('classifies createRuntimeBodyErrorInNavigation as blocking-route + runtime + inNavigation', () => {
expect(
getBlockingRouteErrorDetails(createRuntimeBodyErrorInNavigation(ROUTE))
).toEqual({
type: 'blocking-route',
variant: 'runtime',
inNavigation: true,
})
})
it('classifies createDynamicBodyErrorInNavigation as blocking-route + dynamic + inNavigation', () => {
expect(
getBlockingRouteErrorDetails(createDynamicBodyErrorInNavigation(ROUTE))
).toEqual({
type: 'blocking-route',
variant: 'dynamic',
inNavigation: true,
})
})
it('classifies createDynamicOrRuntimeBodyError as blocking-route + dynamic (SSR-only)', () => {
// The "either" factory has no clear runtime signal — falls into the // The "either" factory has no clear runtime signal — falls into the
// navigation branch by `isRuntimeVariant`. Documents current behavior. // dynamic branch by `isRuntimeVariant`. Documents current behavior.
expect( expect(
getBlockingRouteErrorDetails(createDynamicOrRuntimeBodyError(ROUTE)) getBlockingRouteErrorDetails(createDynamicOrRuntimeBodyError(ROUTE))
).toEqual({ type: 'blocking-route', variant: 'navigation' }) ).toEqual({
type: 'blocking-route',
variant: 'dynamic',
inNavigation: false,
})
}) })
it('classifies createRuntimeMetadataError as dynamic-metadata + runtime', () => { it('classifies createRuntimeMetadataError as dynamic-metadata + runtime', () => {
...@@ -154,16 +172,16 @@ describe('getBlockingRouteErrorDetails', () => { ...@@ -154,16 +172,16 @@ describe('getBlockingRouteErrorDetails', () => {
).toEqual({ type: 'dynamic-metadata', variant: 'runtime' }) ).toEqual({ type: 'dynamic-metadata', variant: 'runtime' })
}) })
it('classifies createDynamicMetadataError as dynamic-metadata + navigation', () => { it('classifies createDynamicMetadataError as dynamic-metadata + dynamic', () => {
expect( expect(
getBlockingRouteErrorDetails(createDynamicMetadataError(ROUTE)) getBlockingRouteErrorDetails(createDynamicMetadataError(ROUTE))
).toEqual({ type: 'dynamic-metadata', variant: 'navigation' }) ).toEqual({ type: 'dynamic-metadata', variant: 'dynamic' })
}) })
it('classifies createDynamicOrRuntimeMetadataError as dynamic-metadata + navigation', () => { it('classifies createDynamicOrRuntimeMetadataError as dynamic-metadata + dynamic', () => {
expect( expect(
getBlockingRouteErrorDetails(createDynamicOrRuntimeMetadataError(ROUTE)) getBlockingRouteErrorDetails(createDynamicOrRuntimeMetadataError(ROUTE))
).toEqual({ type: 'dynamic-metadata', variant: 'navigation' }) ).toEqual({ type: 'dynamic-metadata', variant: 'dynamic' })
}) })
it('classifies createRuntimeViewportError as dynamic-viewport + runtime', () => { it('classifies createRuntimeViewportError as dynamic-viewport + runtime', () => {
...@@ -172,16 +190,16 @@ describe('getBlockingRouteErrorDetails', () => { ...@@ -172,16 +190,16 @@ describe('getBlockingRouteErrorDetails', () => {
).toEqual({ type: 'dynamic-viewport', variant: 'runtime' }) ).toEqual({ type: 'dynamic-viewport', variant: 'runtime' })
}) })
it('classifies createDynamicViewportError as dynamic-viewport + navigation', () => { it('classifies createDynamicViewportError as dynamic-viewport + dynamic', () => {
expect( expect(
getBlockingRouteErrorDetails(createDynamicViewportError(ROUTE)) getBlockingRouteErrorDetails(createDynamicViewportError(ROUTE))
).toEqual({ type: 'dynamic-viewport', variant: 'navigation' }) ).toEqual({ type: 'dynamic-viewport', variant: 'dynamic' })
}) })
it('classifies createDynamicOrRuntimeViewportError as dynamic-viewport + navigation', () => { it('classifies createDynamicOrRuntimeViewportError as dynamic-viewport + dynamic', () => {
expect( expect(
getBlockingRouteErrorDetails(createDynamicOrRuntimeViewportError(ROUTE)) getBlockingRouteErrorDetails(createDynamicOrRuntimeViewportError(ROUTE))
).toEqual({ type: 'dynamic-viewport', variant: 'navigation' }) ).toEqual({ type: 'dynamic-viewport', variant: 'dynamic' })
}) })
it.each<[SyncIOApiType, string, string]>([ it.each<[SyncIOApiType, string, string]>([
......
...@@ -28,6 +28,7 @@ import { ...@@ -28,6 +28,7 @@ import {
type GuidanceKind, type GuidanceKind,
type GuidanceVariant, type GuidanceVariant,
} from '../components/instant/instant-guidance' } from '../components/instant/instant-guidance'
import { BLOCKING_ROUTE_NAVIGATION_EXPLANATION } from '../components/instant/instant-guidance-data'
import { CodeFrame } from '../components/code-frame/code-frame' import { CodeFrame } from '../components/code-frame/code-frame'
import { ErrorOverlayCallStack } from '../components/errors/error-overlay-call-stack/error-overlay-call-stack' import { ErrorOverlayCallStack } from '../components/errors/error-overlay-call-stack/error-overlay-call-stack'
import { ErrorCause } from './runtime-error/error-cause' import { ErrorCause } from './runtime-error/error-cause'
...@@ -129,17 +130,18 @@ type HydrationErrorDetails = { ...@@ -129,17 +130,18 @@ type HydrationErrorDetails = {
type BlockingRouteErrorDetails = { type BlockingRouteErrorDetails = {
type: 'blocking-route' type: 'blocking-route'
variant: 'navigation' | 'runtime' variant: 'dynamic' | 'runtime'
inNavigation: boolean
} }
type DynamicMetadataErrorDetails = { type DynamicMetadataErrorDetails = {
type: 'dynamic-metadata' type: 'dynamic-metadata'
variant: 'navigation' | 'runtime' variant: 'dynamic' | 'runtime'
} }
type DynamicViewportErrorDetails = { type DynamicViewportErrorDetails = {
type: 'dynamic-viewport' type: 'dynamic-viewport'
variant: 'navigation' | 'runtime' variant: 'dynamic' | 'runtime'
} }
type SyncIOErrorDetails = { type SyncIOErrorDetails = {
...@@ -320,16 +322,31 @@ export function isSyncIOClientError(message: string): boolean { ...@@ -320,16 +322,31 @@ export function isSyncIOClientError(message: string): boolean {
return match !== null && match[2] === '-client' return match !== null && match[2] === '-client'
} }
// Detects errors emitted during navigation-phase instant validation: body
// errors from `createRuntimeBodyErrorInNavigation` /
// `createDynamicBodyErrorInNavigation` (SSR factories instead say "during
// the initial render"), and validation errors from
// `trackDynamicHoleInNavigation` / `getNavigationDisallowedDynamicReasons`.
export function isBlockingRouteInNavError(message: string): boolean {
return (
message.includes('or a navigation') ||
message.includes('Could not validate `unstable_instant`') ||
message.includes('Could not validate instant UI')
)
}
export function getBlockingRouteErrorDetails( export function getBlockingRouteErrorDetails(
error: Error error: Error
): null | ErrorDetails { ): null | ErrorDetails {
const message = error.message const message = error.message
const inNavigation = isBlockingRouteInNavError(message)
const isBlockingPageLoadError = message.includes('/blocking-route') const isBlockingPageLoadError = message.includes('/blocking-route')
if (isBlockingPageLoadError) { if (isBlockingPageLoadError) {
return { return {
type: 'blocking-route', type: 'blocking-route',
variant: isRuntimeVariant(message) ? 'runtime' : 'navigation', variant: isRuntimeVariant(message) ? 'runtime' : 'dynamic',
inNavigation,
} }
} }
...@@ -339,7 +356,7 @@ export function getBlockingRouteErrorDetails( ...@@ -339,7 +356,7 @@ export function getBlockingRouteErrorDetails(
if (isDynamicMetadataError) { if (isDynamicMetadataError) {
return { return {
type: 'dynamic-metadata', type: 'dynamic-metadata',
variant: isRuntimeVariant(message) ? 'runtime' : 'navigation', variant: isRuntimeVariant(message) ? 'runtime' : 'dynamic',
} }
} }
...@@ -349,7 +366,7 @@ export function getBlockingRouteErrorDetails( ...@@ -349,7 +366,7 @@ export function getBlockingRouteErrorDetails(
if (isBlockingViewportError) { if (isBlockingViewportError) {
return { return {
type: 'dynamic-viewport', type: 'dynamic-viewport',
variant: isRuntimeVariant(message) ? 'runtime' : 'navigation', variant: isRuntimeVariant(message) ? 'runtime' : 'dynamic',
} }
} }
...@@ -540,10 +557,23 @@ Next.js version: ${props.versionInfo.installed} (${process.env.__NEXT_BUNDLER})\ ...@@ -540,10 +557,23 @@ Next.js version: ${props.versionInfo.installed} (${process.env.__NEXT_BUNDLER})\
errorType={errorType} errorType={errorType}
errorMessage={ errorMessage={
errorDetails.variant === 'runtime' errorDetails.variant === 'runtime'
? 'Next.js encountered runtime data during the initial render.' ? errorDetails.inNavigation
: 'Next.js encountered uncached data during the initial render.' ? 'Next.js encountered runtime data during a navigation.'
: 'Next.js encountered runtime data during the initial render.'
: errorDetails.inNavigation
? 'Next.js encountered uncached data during a navigation.'
: 'Next.js encountered uncached data during the initial render.'
}
headerChildren={
<InstantHeaderExplanation
kind="blocking-route"
explanation={
errorDetails.inNavigation
? BLOCKING_ROUTE_NAVIGATION_EXPLANATION
: undefined
}
/>
} }
headerChildren={<InstantHeaderExplanation kind="blocking-route" />}
onClose={isServerError ? undefined : onClose} onClose={isServerError ? undefined : onClose}
debugInfo={debugInfo} debugInfo={debugInfo}
error={error} error={error}
......
import { createContext, useContext, useRef, useState } from 'react' import { createContext, useContext, useEffect, useRef, useState } from 'react'
import { ShadowPortal } from './components/shadow-portal' import { ShadowPortal } from './components/shadow-portal'
import { ComponentStyles } from './styles/component-styles' import { ComponentStyles } from './styles/component-styles'
import { ErrorOverlay } from './components/errors/error-overlay/error-overlay' import { ErrorOverlay } from './components/errors/error-overlay/error-overlay'
...@@ -9,6 +9,7 @@ import { DevToolsIndicator } from './components/devtools-indicator/devtools-indi ...@@ -9,6 +9,7 @@ import { DevToolsIndicator } from './components/devtools-indicator/devtools-indi
import { PanelRouter } from './menu/panel-router' import { PanelRouter } from './menu/panel-router'
import { PanelRouterContext, type PanelStateKind } from './menu/context' import { PanelRouterContext, type PanelStateKind } from './menu/context'
import { useDevOverlayContext } from '../dev-overlay.browser' import { useDevOverlayContext } from '../dev-overlay.browser'
import { ACTION_INSTANT_ERRORS_CLEAR, type DispatcherEvent } from './shared'
export const RenderErrorContext = createContext<{ export const RenderErrorContext = createContext<{
runtimeErrors: ReadyRuntimeError[] runtimeErrors: ReadyRuntimeError[]
...@@ -17,6 +18,26 @@ export const RenderErrorContext = createContext<{ ...@@ -17,6 +18,26 @@ export const RenderErrorContext = createContext<{
export const useRenderErrorContext = () => useContext(RenderErrorContext) export const useRenderErrorContext = () => useContext(RenderErrorContext)
// Dispatches `ACTION_INSTANT_ERRORS_CLEAR` whenever the page changes to a
// new non-empty value. The first non-empty value is recorded as a baseline
// (the route the user landed on) and does not trigger a clear.
function useClearInstantErrorsOnNav(
page: string,
dispatch: (action: DispatcherEvent) => void
) {
const baselinePageRef = useRef<string | null>(null)
useEffect(() => {
if (page === '') return
if (baselinePageRef.current === null) {
baselinePageRef.current = page
return
}
if (page === baselinePageRef.current) return
baselinePageRef.current = page
dispatch({ type: ACTION_INSTANT_ERRORS_CLEAR, currentPath: page })
}, [page, dispatch])
}
export function DevOverlay() { export function DevOverlay() {
const [selectedIndex, setSelectedIndex] = useState(-1) const [selectedIndex, setSelectedIndex] = useState(-1)
const { state, dispatch, getSquashedHydrationErrorDetails } = const { state, dispatch, getSquashedHydrationErrorDetails } =
...@@ -25,6 +46,8 @@ export function DevOverlay() { ...@@ -25,6 +46,8 @@ export function DevOverlay() {
state.instantNavs ? 'instant-navs' : null state.instantNavs ? 'instant-navs' : null
) )
useClearInstantErrorsOnNav(state.page, dispatch)
const triggerRef = useRef<HTMLButtonElement>(null) const triggerRef = useRef<HTMLButtonElement>(null)
return ( return (
<ShadowPortal> <ShadowPortal>
......
import {
createDynamicBodyError,
createDynamicBodyErrorInNavigation,
createRuntimeBodyError,
createRuntimeBodyErrorInNavigation,
} from '../../server/app-render/blocking-route-messages'
import { getInstantErrorRoute, routeTemplateMatchesPath } from './shared'
const STATIC_ROUTE = '/example'
const DYNAMIC_ROUTE_TEMPLATE = '/posts/[slug]'
const CATCH_ALL_ROUTE_TEMPLATE = '/docs/[...slug]'
describe('getInstantErrorRoute', () => {
it('returns the route for an in-navigation runtime body error', () => {
expect(
getInstantErrorRoute(createRuntimeBodyErrorInNavigation(STATIC_ROUTE))
).toBe(STATIC_ROUTE)
})
it('returns the route for an in-navigation dynamic body error', () => {
expect(
getInstantErrorRoute(
createDynamicBodyErrorInNavigation(DYNAMIC_ROUTE_TEMPLATE)
)
).toBe(DYNAMIC_ROUTE_TEMPLATE)
})
it('returns the route for the unrendered-segment wrapper', () => {
const error = new Error(
`Route "${STATIC_ROUTE}": Could not validate instant UI because an expected segment was not rendered.\n\nUnrendered segment:\n app/example/page.tsx`
)
expect(getInstantErrorRoute(error)).toBe(STATIC_ROUTE)
})
it('returns null for SSR-only body errors', () => {
expect(getInstantErrorRoute(createRuntimeBodyError(STATIC_ROUTE))).toBe(
null
)
expect(getInstantErrorRoute(createDynamicBodyError(STATIC_ROUTE))).toBe(
null
)
})
it('returns null for unrelated errors', () => {
expect(getInstantErrorRoute(new Error('regular bug'))).toBe(null)
})
it('returns null for non-Error inputs', () => {
expect(getInstantErrorRoute(null)).toBe(null)
expect(getInstantErrorRoute(undefined)).toBe(null)
expect(getInstantErrorRoute('string error')).toBe(null)
})
})
describe('routeTemplateMatchesPath', () => {
it('matches identical static routes', () => {
expect(routeTemplateMatchesPath(STATIC_ROUTE, STATIC_ROUTE)).toBe(true)
})
it('does not match different static routes', () => {
expect(routeTemplateMatchesPath('/foo', '/bar')).toBe(false)
})
it('matches a dynamic template against a resolved URL', () => {
expect(routeTemplateMatchesPath(DYNAMIC_ROUTE_TEMPLATE, '/posts/123')).toBe(
true
)
expect(
routeTemplateMatchesPath(DYNAMIC_ROUTE_TEMPLATE, '/posts/hello-world')
).toBe(true)
})
it('does not match a dynamic template against a sibling route', () => {
expect(routeTemplateMatchesPath(DYNAMIC_ROUTE_TEMPLATE, '/users/123')).toBe(
false
)
})
it('does not match a dynamic template against deeper path segments', () => {
expect(
routeTemplateMatchesPath(DYNAMIC_ROUTE_TEMPLATE, '/posts/2026/05/16')
).toBe(false)
})
it('matches a catch-all template against multiple resolved segments', () => {
expect(
routeTemplateMatchesPath(
CATCH_ALL_ROUTE_TEMPLATE,
'/docs/getting-started'
)
).toBe(true)
expect(
routeTemplateMatchesPath(
CATCH_ALL_ROUTE_TEMPLATE,
'/docs/app/api-reference/functions/cookies'
)
).toBe(true)
})
})
...@@ -9,6 +9,9 @@ import { parseStack } from '../../server/lib/parse-stack' ...@@ -9,6 +9,9 @@ import { parseStack } from '../../server/lib/parse-stack'
import { isConsoleError } from '../shared/console-error' import { isConsoleError } from '../shared/console-error'
import type { CacheIndicatorState } from './cache-indicator' import type { CacheIndicatorState } from './cache-indicator'
import { readInstantNavCookieState } from './components/instant-navs/instant-nav-cookie' import { readInstantNavCookieState } from './components/instant-navs/instant-nav-cookie'
import { isBlockingRouteInNavError } from './container/errors'
import { isDynamicRoute } from '../../shared/lib/router/utils/is-dynamic'
import { getRouteRegex } from '../../shared/lib/router/utils/route-regex'
export type DevToolsConfig = { export type DevToolsConfig = {
theme?: 'light' | 'dark' | 'system' theme?: 'light' | 'dark' | 'system'
...@@ -107,6 +110,7 @@ export const ACTION_DEVTOOLS_SCALE = 'devtools-scale' ...@@ -107,6 +110,7 @@ export const ACTION_DEVTOOLS_SCALE = 'devtools-scale'
export const ACTION_DEVTOOLS_CONFIG = 'devtools-config' export const ACTION_DEVTOOLS_CONFIG = 'devtools-config'
export const ACTION_INSTANT_NAVS_TOGGLE = 'instant-navs-toggle' export const ACTION_INSTANT_NAVS_TOGGLE = 'instant-navs-toggle'
export const ACTION_INSTANT_NAVS_RESET = 'instant-navs-reset' export const ACTION_INSTANT_NAVS_RESET = 'instant-navs-reset'
export const ACTION_INSTANT_ERRORS_CLEAR = 'instant-errors-clear'
export const STORAGE_KEY_PANEL_POSITION_PREFIX = export const STORAGE_KEY_PANEL_POSITION_PREFIX =
'__nextjs-dev-tools-panel-position' '__nextjs-dev-tools-panel-position'
...@@ -231,6 +235,11 @@ interface InstantNavResetAction { ...@@ -231,6 +235,11 @@ interface InstantNavResetAction {
type: typeof ACTION_INSTANT_NAVS_RESET type: typeof ACTION_INSTANT_NAVS_RESET
} }
interface InstantErrorsClearAction {
type: typeof ACTION_INSTANT_ERRORS_CLEAR
currentPath: string
}
export type DispatcherEvent = export type DispatcherEvent =
| BuildOkAction | BuildOkAction
| BuildErrorAction | BuildErrorAction
...@@ -258,6 +267,7 @@ export type DispatcherEvent = ...@@ -258,6 +267,7 @@ export type DispatcherEvent =
| DevToolsConfigAction | DevToolsConfigAction
| CacheOnlyToggleAction | CacheOnlyToggleAction
| InstantNavResetAction | InstantNavResetAction
| InstantErrorsClearAction
const REACT_ERROR_STACK_BOTTOM_FRAME_REGEX = const REACT_ERROR_STACK_BOTTOM_FRAME_REGEX =
// 1st group: new frame + v8 // 1st group: new frame + v8
...@@ -274,6 +284,33 @@ function getStackIgnoringStrictMode(stack: string | undefined) { ...@@ -274,6 +284,33 @@ function getStackIgnoringStrictMode(stack: string | undefined) {
return stack?.split(REACT_ERROR_STACK_BOTTOM_FRAME_REGEX)[0] return stack?.split(REACT_ERROR_STACK_BOTTOM_FRAME_REGEX)[0]
} }
export function getInstantErrorRoute(error: unknown): string | null {
if (!error || typeof error !== 'object') return null
const message = (error as Error).message
if (typeof message !== 'string') return null
if (!isBlockingRouteInNavError(message)) return null
// Most factories prefix `Route "<path>":`; the missing-segment factory in
// `dynamic-rendering.ts` writes `Route: <path>` on its own line in the body.
const prefixMatch = /^Route "([^"]+)":/.exec(message)
if (prefixMatch) return prefixMatch[1]
const lineMatch = /\nRoute: (\S+)/.exec(message)
return lineMatch ? lineMatch[1] : null
}
// The route stored on an instant error is the route *template* from
// `workStore.route` (e.g. `/foo/[slug]`), but the page we track in dev
// overlay state is the resolved URL (e.g. `/foo/123`). For dynamic routes
// we compile the template to a regex so the clear-on-nav reducer keeps
// errors whose template matches the page the user just landed on.
export function routeTemplateMatchesPath(
template: string,
path: string
): boolean {
if (template === path) return true
if (!isDynamicRoute(template)) return false
return getRouteRegex(template).re.test(path)
}
const shouldDisableDevIndicator = const shouldDisableDevIndicator =
process.env.__NEXT_DEV_INDICATOR?.toString() === 'false' process.env.__NEXT_DEV_INDICATOR?.toString() === 'false'
...@@ -539,6 +576,17 @@ export function useErrorOverlayReducer( ...@@ -539,6 +576,17 @@ export function useErrorOverlayReducer(
case ACTION_INSTANT_NAVS_RESET: { case ACTION_INSTANT_NAVS_RESET: {
return { ...state, instantNavs: false } return { ...state, instantNavs: false }
} }
case ACTION_INSTANT_ERRORS_CLEAR: {
const remaining = state.errors.filter((event) => {
const route = getInstantErrorRoute(event.error)
if (route === null) return true
return routeTemplateMatchesPath(route, action.currentPath)
})
if (remaining.length === state.errors.length) {
return state
}
return { ...state, errors: remaining }
}
default: { default: {
return state return state
} }
......
...@@ -22,6 +22,30 @@ export function createDynamicBodyError(route: string): Error { ...@@ -22,6 +22,30 @@ export function createDynamicBodyError(route: string): Error {
) )
} }
export function createRuntimeBodyErrorInNavigation(route: string): Error {
return new Error(
`Route "${route}": Next.js encountered runtime data during the initial render or a navigation.\n\n` +
`\`cookies()\`, \`headers()\`, \`params\`, or \`searchParams\` accessed outside of \`<Suspense>\` prevents the route from being prerendered or the navigation from being instant, leading to a slower user experience.\n\n` +
`Ways to fix this:\n` +
` - Provide a placeholder with \`<Suspense fallback={...}>\` around the data access\n` +
` - Use \`generateStaticParams\` to make route params static\n` +
` - Set \`export const instant = false\` to allow a blocking route\n\n` +
`Learn more: https://nextjs.org/docs/messages/blocking-route`
)
}
export function createDynamicBodyErrorInNavigation(route: string): Error {
return new Error(
`Route "${route}": Next.js encountered uncached data during the initial render or a navigation.\n\n` +
`\`fetch(...)\` or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered or the navigation from being instant, leading to a slower user experience.\n\n` +
`Ways to fix this:\n` +
` - Cache the data access with \`"use cache"\`\n` +
` - Provide a placeholder with \`<Suspense fallback={...}>\` around the data access\n` +
` - Set \`export const instant = false\` to allow a blocking route\n\n` +
`Learn more: https://nextjs.org/docs/messages/blocking-route`
)
}
/** /**
* NOTE: Prefer `createRuntimeBodyError` or `createDynamicBodyError`. * NOTE: Prefer `createRuntimeBodyError` or `createDynamicBodyError`.
* Only use this in situations like build-time static validation, where * Only use this in situations like build-time static validation, where
......
...@@ -50,6 +50,8 @@ import { BailoutToCSRError } from '../../shared/lib/lazy-dynamic/bailout-to-csr' ...@@ -50,6 +50,8 @@ import { BailoutToCSRError } from '../../shared/lib/lazy-dynamic/bailout-to-csr'
import { import {
createRuntimeBodyError, createRuntimeBodyError,
createDynamicBodyError, createDynamicBodyError,
createRuntimeBodyErrorInNavigation,
createDynamicBodyErrorInNavigation,
createDynamicOrRuntimeBodyError, createDynamicOrRuntimeBodyError,
createRuntimeMetadataError, createRuntimeMetadataError,
createDynamicMetadataError, createDynamicMetadataError,
...@@ -1026,8 +1028,8 @@ export function trackDynamicHoleInNavigation( ...@@ -1026,8 +1028,8 @@ export function trackDynamicHoleInNavigation(
const error = addErrorContext( const error = addErrorContext(
kind === DynamicHoleKind.Runtime kind === DynamicHoleKind.Runtime
? createRuntimeBodyError(workStore.route) ? createRuntimeBodyErrorInNavigation(workStore.route)
: createDynamicBodyError(workStore.route), : createDynamicBodyErrorInNavigation(workStore.route),
componentStack, componentStack,
effectiveCreateInstantStack effectiveCreateInstantStack
) )
......
...@@ -63,9 +63,9 @@ describe('instant-validation-build', () => { ...@@ -63,9 +63,9 @@ describe('instant-validation-build', () => {
) )
expect(extractBuildValidationError(result.cliOutput)) expect(extractBuildValidationError(result.cliOutput))
.toMatchInlineSnapshot(` .toMatchInlineSnapshot(`
"Error: Route "/invalid-missing-suspense-around-runtime": Next.js encountered uncached data during the initial render. "Error: Route "/invalid-missing-suspense-around-runtime": Next.js encountered uncached data during the initial render or a navigation.
\`fetch(...)\` or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered, blocking navigation and leading to a slower user experience. \`fetch(...)\` or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered or the navigation from being instant, leading to a slower user experience.
Ways to fix this: Ways to fix this:
- Cache the data access with \`"use cache"\` - Cache the data access with \`"use cache"\`
......
...@@ -105,8 +105,8 @@ describe('instant validation causes', () => { ...@@ -105,8 +105,8 @@ describe('instant validation causes', () => {
], ],
}, },
], ],
"code": "E1221", "code": "E1251",
"description": "Next.js encountered runtime data during the initial render.", "description": "Next.js encountered runtime data during a navigation.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Instant",
"source": "app/named-export/page.tsx (7:16) @ Page "source": "app/named-export/page.tsx (7:16) @ Page
...@@ -136,8 +136,8 @@ describe('instant validation causes', () => { ...@@ -136,8 +136,8 @@ describe('instant validation causes', () => {
], ],
}, },
], ],
"code": "E1221", "code": "E1251",
"description": "Next.js encountered runtime data during the initial render.", "description": "Next.js encountered runtime data during a navigation.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Instant",
"source": "app/aliased-export/page.tsx (7:16) @ Page "source": "app/aliased-export/page.tsx (7:16) @ Page
...@@ -167,8 +167,8 @@ describe('instant validation causes', () => { ...@@ -167,8 +167,8 @@ describe('instant validation causes', () => {
], ],
}, },
], ],
"code": "E1221", "code": "E1251",
"description": "Next.js encountered runtime data during the initial render.", "description": "Next.js encountered runtime data during a navigation.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Instant",
"source": "app/reexport/page.tsx (6:16) @ Page "source": "app/reexport/page.tsx (6:16) @ Page
...@@ -201,8 +201,8 @@ describe('instant validation causes', () => { ...@@ -201,8 +201,8 @@ describe('instant validation causes', () => {
], ],
}, },
], ],
"code": "E1221", "code": "E1251",
"description": "Next.js encountered runtime data during the initial render.", "description": "Next.js encountered runtime data during a navigation.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Instant",
"source": "app/indirect-export/page.tsx (8:16) @ Page "source": "app/indirect-export/page.tsx (8:16) @ Page
......
...@@ -60,8 +60,8 @@ describe('instant validation - level error', () => { ...@@ -60,8 +60,8 @@ describe('instant validation - level error', () => {
const browser = await next.browser('/bare') const browser = await next.browser('/bare')
await expect(browser).toDisplayCollapsedRedbox(` await expect(browser).toDisplayCollapsedRedbox(`
{ {
"code": "E1220", "code": "E1249",
"description": "Next.js encountered uncached data during the initial render.", "description": "Next.js encountered uncached data during a navigation.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Instant",
"source": "app/bare/page.tsx (11:19) @ Page "source": "app/bare/page.tsx (11:19) @ Page
...@@ -90,8 +90,8 @@ describe('instant validation - level error', () => { ...@@ -90,8 +90,8 @@ describe('instant validation - level error', () => {
], ],
}, },
], ],
"code": "E1220", "code": "E1249",
"description": "Next.js encountered uncached data during the initial render.", "description": "Next.js encountered uncached data during a navigation.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Instant",
"source": "app/explicit-error/page.tsx (11:19) @ Page "source": "app/explicit-error/page.tsx (11:19) @ Page
...@@ -120,8 +120,8 @@ describe('instant validation - level error', () => { ...@@ -120,8 +120,8 @@ describe('instant validation - level error', () => {
], ],
}, },
], ],
"code": "E1220", "code": "E1249",
"description": "Next.js encountered uncached data during the initial render.", "description": "Next.js encountered uncached data during a navigation.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Instant",
"source": "app/explicit-true/page.tsx (12:19) @ Page "source": "app/explicit-true/page.tsx (12:19) @ Page
...@@ -150,8 +150,8 @@ describe('instant validation - level error', () => { ...@@ -150,8 +150,8 @@ describe('instant validation - level error', () => {
], ],
}, },
], ],
"code": "E1220", "code": "E1249",
"description": "Next.js encountered uncached data during the initial render.", "description": "Next.js encountered uncached data during a navigation.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Instant",
"source": "app/explicit-warning/page.tsx (11:19) @ Page "source": "app/explicit-warning/page.tsx (11:19) @ Page
...@@ -177,8 +177,8 @@ describe('instant validation - level error', () => { ...@@ -177,8 +177,8 @@ describe('instant validation - level error', () => {
const browser = await next.browser('/layered') const browser = await next.browser('/layered')
await expect(browser).toDisplayCollapsedRedbox(` await expect(browser).toDisplayCollapsedRedbox(`
{ {
"code": "E1220", "code": "E1249",
"description": "Next.js encountered uncached data during the initial render.", "description": "Next.js encountered uncached data during a navigation.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Instant",
"source": "app/layered/page.tsx (8:19) @ Page "source": "app/layered/page.tsx (8:19) @ Page
...@@ -197,9 +197,9 @@ describe('instant validation - level error', () => { ...@@ -197,9 +197,9 @@ describe('instant validation - level error', () => {
const result = await prerender('/bare') const result = await prerender('/bare')
expect(extractBuildValidationError(result.cliOutput)) expect(extractBuildValidationError(result.cliOutput))
.toMatchInlineSnapshot(` .toMatchInlineSnapshot(`
"Error: Route "/bare": Next.js encountered uncached data during the initial render. "Error: Route "/bare": Next.js encountered uncached data during the initial render or a navigation.
\`fetch(...)\` or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered, blocking navigation and leading to a slower user experience. \`fetch(...)\` or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered or the navigation from being instant, leading to a slower user experience.
Ways to fix this: Ways to fix this:
- Cache the data access with \`"use cache"\` - Cache the data access with \`"use cache"\`
...@@ -223,9 +223,9 @@ describe('instant validation - level error', () => { ...@@ -223,9 +223,9 @@ describe('instant validation - level error', () => {
const result = await prerender('/explicit-error') const result = await prerender('/explicit-error')
expect(extractBuildValidationError(result.cliOutput)) expect(extractBuildValidationError(result.cliOutput))
.toMatchInlineSnapshot(` .toMatchInlineSnapshot(`
"Error: Route "/explicit-error": Next.js encountered uncached data during the initial render. "Error: Route "/explicit-error": Next.js encountered uncached data during the initial render or a navigation.
\`fetch(...)\` or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered, blocking navigation and leading to a slower user experience. \`fetch(...)\` or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered or the navigation from being instant, leading to a slower user experience.
Ways to fix this: Ways to fix this:
- Cache the data access with \`"use cache"\` - Cache the data access with \`"use cache"\`
...@@ -249,9 +249,9 @@ describe('instant validation - level error', () => { ...@@ -249,9 +249,9 @@ describe('instant validation - level error', () => {
const result = await prerender('/explicit-true') const result = await prerender('/explicit-true')
expect(extractBuildValidationError(result.cliOutput)) expect(extractBuildValidationError(result.cliOutput))
.toMatchInlineSnapshot(` .toMatchInlineSnapshot(`
"Error: Route "/explicit-true": Next.js encountered uncached data during the initial render. "Error: Route "/explicit-true": Next.js encountered uncached data during the initial render or a navigation.
\`fetch(...)\` or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered, blocking navigation and leading to a slower user experience. \`fetch(...)\` or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered or the navigation from being instant, leading to a slower user experience.
Ways to fix this: Ways to fix this:
- Cache the data access with \`"use cache"\` - Cache the data access with \`"use cache"\`
...@@ -288,9 +288,9 @@ describe('instant validation - level error', () => { ...@@ -288,9 +288,9 @@ describe('instant validation - level error', () => {
const result = await prerender('/layered') const result = await prerender('/layered')
expect(extractBuildValidationError(result.cliOutput)) expect(extractBuildValidationError(result.cliOutput))
.toMatchInlineSnapshot(` .toMatchInlineSnapshot(`
"Error: Route "/layered": Next.js encountered uncached data during the initial render. "Error: Route "/layered": Next.js encountered uncached data during the initial render or a navigation.
\`fetch(...)\` or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered, blocking navigation and leading to a slower user experience. \`fetch(...)\` or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered or the navigation from being instant, leading to a slower user experience.
Ways to fix this: Ways to fix this:
- Cache the data access with \`"use cache"\` - Cache the data access with \`"use cache"\`
......
...@@ -79,8 +79,8 @@ describe('instant validation - level manual-error', () => { ...@@ -79,8 +79,8 @@ describe('instant validation - level manual-error', () => {
], ],
}, },
], ],
"code": "E1220", "code": "E1249",
"description": "Next.js encountered uncached data during the initial render.", "description": "Next.js encountered uncached data during a navigation.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Instant",
"source": "app/explicit-error/page.tsx (11:19) @ Page "source": "app/explicit-error/page.tsx (11:19) @ Page
...@@ -109,8 +109,8 @@ describe('instant validation - level manual-error', () => { ...@@ -109,8 +109,8 @@ describe('instant validation - level manual-error', () => {
], ],
}, },
], ],
"code": "E1220", "code": "E1249",
"description": "Next.js encountered uncached data during the initial render.", "description": "Next.js encountered uncached data during a navigation.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Instant",
"source": "app/explicit-true/page.tsx (12:19) @ Page "source": "app/explicit-true/page.tsx (12:19) @ Page
...@@ -139,8 +139,8 @@ describe('instant validation - level manual-error', () => { ...@@ -139,8 +139,8 @@ describe('instant validation - level manual-error', () => {
], ],
}, },
], ],
"code": "E1220", "code": "E1249",
"description": "Next.js encountered uncached data during the initial render.", "description": "Next.js encountered uncached data during a navigation.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Instant",
"source": "app/explicit-warning/page.tsx (11:19) @ Page "source": "app/explicit-warning/page.tsx (11:19) @ Page
...@@ -180,9 +180,9 @@ describe('instant validation - level manual-error', () => { ...@@ -180,9 +180,9 @@ describe('instant validation - level manual-error', () => {
const result = await prerender('/explicit-error') const result = await prerender('/explicit-error')
expect(extractBuildValidationError(result.cliOutput)) expect(extractBuildValidationError(result.cliOutput))
.toMatchInlineSnapshot(` .toMatchInlineSnapshot(`
"Error: Route "/explicit-error": Next.js encountered uncached data during the initial render. "Error: Route "/explicit-error": Next.js encountered uncached data during the initial render or a navigation.
\`fetch(...)\` or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered, blocking navigation and leading to a slower user experience. \`fetch(...)\` or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered or the navigation from being instant, leading to a slower user experience.
Ways to fix this: Ways to fix this:
- Cache the data access with \`"use cache"\` - Cache the data access with \`"use cache"\`
...@@ -206,9 +206,9 @@ describe('instant validation - level manual-error', () => { ...@@ -206,9 +206,9 @@ describe('instant validation - level manual-error', () => {
const result = await prerender('/explicit-true') const result = await prerender('/explicit-true')
expect(extractBuildValidationError(result.cliOutput)) expect(extractBuildValidationError(result.cliOutput))
.toMatchInlineSnapshot(` .toMatchInlineSnapshot(`
"Error: Route "/explicit-true": Next.js encountered uncached data during the initial render. "Error: Route "/explicit-true": Next.js encountered uncached data during the initial render or a navigation.
\`fetch(...)\` or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered, blocking navigation and leading to a slower user experience. \`fetch(...)\` or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered or the navigation from being instant, leading to a slower user experience.
Ways to fix this: Ways to fix this:
- Cache the data access with \`"use cache"\` - Cache the data access with \`"use cache"\`
......
...@@ -93,8 +93,8 @@ describe('instant validation - level manual-warning', () => { ...@@ -93,8 +93,8 @@ describe('instant validation - level manual-warning', () => {
], ],
}, },
], ],
"code": "E1220", "code": "E1249",
"description": "Next.js encountered uncached data during the initial render.", "description": "Next.js encountered uncached data during a navigation.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Instant",
"source": "app/with-root-suspense/explicit-error/page.tsx (11:19) @ Page "source": "app/with-root-suspense/explicit-error/page.tsx (11:19) @ Page
...@@ -125,8 +125,8 @@ describe('instant validation - level manual-warning', () => { ...@@ -125,8 +125,8 @@ describe('instant validation - level manual-warning', () => {
], ],
}, },
], ],
"code": "E1220", "code": "E1249",
"description": "Next.js encountered uncached data during the initial render.", "description": "Next.js encountered uncached data during a navigation.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Instant",
"source": "app/with-root-suspense/explicit-true/page.tsx (10:19) @ Page "source": "app/with-root-suspense/explicit-true/page.tsx (10:19) @ Page
...@@ -157,8 +157,8 @@ describe('instant validation - level manual-warning', () => { ...@@ -157,8 +157,8 @@ describe('instant validation - level manual-warning', () => {
], ],
}, },
], ],
"code": "E1220", "code": "E1249",
"description": "Next.js encountered uncached data during the initial render.", "description": "Next.js encountered uncached data during a navigation.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Instant",
"source": "app/with-root-suspense/explicit-warning/page.tsx (9:19) @ Page "source": "app/with-root-suspense/explicit-warning/page.tsx (9:19) @ Page
...@@ -192,9 +192,9 @@ describe('instant validation - level manual-warning', () => { ...@@ -192,9 +192,9 @@ describe('instant validation - level manual-warning', () => {
const result = await prerender('/with-root-suspense/explicit-error') const result = await prerender('/with-root-suspense/explicit-error')
expect(extractBuildValidationError(result.cliOutput)) expect(extractBuildValidationError(result.cliOutput))
.toMatchInlineSnapshot(` .toMatchInlineSnapshot(`
"Error: Route "/with-root-suspense/explicit-error": Next.js encountered uncached data during the initial render. "Error: Route "/with-root-suspense/explicit-error": Next.js encountered uncached data during the initial render or a navigation.
\`fetch(...)\` or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered, blocking navigation and leading to a slower user experience. \`fetch(...)\` or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered or the navigation from being instant, leading to a slower user experience.
Ways to fix this: Ways to fix this:
- Cache the data access with \`"use cache"\` - Cache the data access with \`"use cache"\`
......
...@@ -60,8 +60,8 @@ describe('instant validation - level warning', () => { ...@@ -60,8 +60,8 @@ describe('instant validation - level warning', () => {
const browser = await next.browser('/bare') const browser = await next.browser('/bare')
await expect(browser).toDisplayCollapsedRedbox(` await expect(browser).toDisplayCollapsedRedbox(`
{ {
"code": "E1220", "code": "E1249",
"description": "Next.js encountered uncached data during the initial render.", "description": "Next.js encountered uncached data during a navigation.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Instant",
"source": "app/bare/page.tsx (10:19) @ Page "source": "app/bare/page.tsx (10:19) @ Page
...@@ -90,8 +90,8 @@ describe('instant validation - level warning', () => { ...@@ -90,8 +90,8 @@ describe('instant validation - level warning', () => {
], ],
}, },
], ],
"code": "E1220", "code": "E1249",
"description": "Next.js encountered uncached data during the initial render.", "description": "Next.js encountered uncached data during a navigation.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Instant",
"source": "app/explicit-error/page.tsx (10:19) @ Page "source": "app/explicit-error/page.tsx (10:19) @ Page
...@@ -120,8 +120,8 @@ describe('instant validation - level warning', () => { ...@@ -120,8 +120,8 @@ describe('instant validation - level warning', () => {
], ],
}, },
], ],
"code": "E1220", "code": "E1249",
"description": "Next.js encountered uncached data during the initial render.", "description": "Next.js encountered uncached data during a navigation.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Instant",
"source": "app/explicit-true/page.tsx (11:19) @ Page "source": "app/explicit-true/page.tsx (11:19) @ Page
...@@ -150,8 +150,8 @@ describe('instant validation - level warning', () => { ...@@ -150,8 +150,8 @@ describe('instant validation - level warning', () => {
], ],
}, },
], ],
"code": "E1220", "code": "E1249",
"description": "Next.js encountered uncached data during the initial render.", "description": "Next.js encountered uncached data during a navigation.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Instant",
"source": "app/explicit-warning/page.tsx (11:19) @ Page "source": "app/explicit-warning/page.tsx (11:19) @ Page
...@@ -177,8 +177,8 @@ describe('instant validation - level warning', () => { ...@@ -177,8 +177,8 @@ describe('instant validation - level warning', () => {
const browser = await next.browser('/layered') const browser = await next.browser('/layered')
await expect(browser).toDisplayCollapsedRedbox(` await expect(browser).toDisplayCollapsedRedbox(`
{ {
"code": "E1220", "code": "E1249",
"description": "Next.js encountered uncached data during the initial render.", "description": "Next.js encountered uncached data during a navigation.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Instant",
"source": "app/layered/page.tsx (8:19) @ Page "source": "app/layered/page.tsx (8:19) @ Page
...@@ -202,9 +202,9 @@ describe('instant validation - level warning', () => { ...@@ -202,9 +202,9 @@ describe('instant validation - level warning', () => {
const result = await prerender('/explicit-error') const result = await prerender('/explicit-error')
expect(extractBuildValidationError(result.cliOutput)) expect(extractBuildValidationError(result.cliOutput))
.toMatchInlineSnapshot(` .toMatchInlineSnapshot(`
"Error: Route "/explicit-error": Next.js encountered uncached data during the initial render. "Error: Route "/explicit-error": Next.js encountered uncached data during the initial render or a navigation.
\`fetch(...)\` or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered, blocking navigation and leading to a slower user experience. \`fetch(...)\` or \`connection()\` accessed outside of \`<Suspense>\` prevents the route from being prerendered or the navigation from being instant, leading to a slower user experience.
Ways to fix this: Ways to fix this:
- Cache the data access with \`"use cache"\` - Cache the data access with \`"use cache"\`
......
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