Unverified Commit 0846789f authored by Aurora Scharff's avatar Aurora Scharff Committed by GitHub

Add Errors/Insights tab split to the instant error overlay (#94073)

### What?

Adds a tab bar to the dev overlay that separates normal errors
("Errors") from instant navigation errors ("Insights"). The indicator
pill also reflects the split.

### Why?

When `unstable_instant` validation produces navigation-phase errors
alongside regular prerender errors, they were mixed into a single list.
Developers had no way to tell which errors were structural
instant-validation issues versus regular runtime/prerender errors.

### Demo

- [Demo 1: prerender
blocking-route](https://error-messages-overhaul-ibsl.labs.vercel.dev/scenario/01-cookies-body)
— `Blocking Route` badge (red), Errors tab.
- [Demo 2: navigation
blocking-route](https://error-messages-overhaul-ibsl.labs.vercel.dev/scenario/42-subnav-fetch)
— `Instant` badge (amber), Insights tab.

### How?

- `Errors` splits `runtimeErrors` into `normalErrors` / `instantErrors`
(using the existing `inNavigation` flag from
`getBlockingRouteErrorDetails`) and defaults to whichever bucket has
errors.
- `ErrorTabBar` renders between the nav and dialog inside
`ErrorOverlayLayout` (new `tabBar` prop). Empty tabs are disabled.
- `ErrorOverlay` passes a `key` derived from the error composition so
tab state resets when the shape changes (e.g. normal errors resolve).
- `RenderErrorContext` gains `instantErrorCount`; the indicator pill
shows "N Issues", "N Insights", or "N Issues · N Insights" accordingly.
- Prerender errors show `Blocking Route` badge (red), navigation errors
show `Instant` badge (amber).

---------
Co-authored-by: 's avatarYavor Punchev <yavor.punchev@gmail.com>
parent 16e862ae
...@@ -20,6 +20,8 @@ interface WithDevOverlayContextsOptions { ...@@ -20,6 +20,8 @@ interface WithDevOverlayContextsOptions {
dispatch?: (action: DispatcherEvent) => void dispatch?: (action: DispatcherEvent) => void
runtimeErrors?: ReadyRuntimeError[] runtimeErrors?: ReadyRuntimeError[]
totalErrorCount?: number totalErrorCount?: number
normalErrorCount?: number
instantErrorCount?: number
panel?: PanelStateKind | null panel?: PanelStateKind | null
setPanel?: Dispatch<SetStateAction<PanelStateKind | null>> setPanel?: Dispatch<SetStateAction<PanelStateKind | null>>
selectedIndex?: number selectedIndex?: number
...@@ -67,6 +69,11 @@ export const withDevOverlayContexts = ...@@ -67,6 +69,11 @@ export const withDevOverlayContexts =
value={{ value={{
runtimeErrors: options?.runtimeErrors ?? [], runtimeErrors: options?.runtimeErrors ?? [],
totalErrorCount: options?.totalErrorCount ?? 0, totalErrorCount: options?.totalErrorCount ?? 0,
normalErrorCount:
options?.normalErrorCount ??
(options?.totalErrorCount ?? 0) -
(options?.instantErrorCount ?? 0),
instantErrorCount: options?.instantErrorCount ?? 0,
}} }}
> >
<PanelRouterContext.Provider <PanelRouterContext.Provider
......
...@@ -648,3 +648,58 @@ export const instantClientMathRandomErrors: ReadyRuntimeError[] = [ ...@@ -648,3 +648,58 @@ export const instantClientMathRandomErrors: ReadyRuntimeError[] = [
type: 'runtime', type: 'runtime',
}, },
] ]
export const mixedIssueAndInsightErrors: ReadyRuntimeError[] = [
runtimeErrors[0],
runtimeErrors[1],
{
id: 120,
runtime: true,
error: Object.assign(
new Error(
'Route "/nav-cookies-under-suspense": 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'
),
{ __NEXT_ERROR_CODE: 'E1247' }
),
frames: createStoryFrames({
reason:
'Route "/nav-cookies-under-suspense": Next.js encountered runtime data during the initial render or a navigation.',
file: 'app/nav-cookies-under-suspense/page.tsx',
methodName: 'Page',
line: 5,
column: 15,
codeFrame: instantCodeFrame({
beforeLine: "import { cookies } from 'next/headers'",
line: 'const c = await cookies()',
markerLine: 5,
pointerColumn: 11,
}),
}),
type: 'runtime',
},
{
id: 121,
runtime: true,
error: Object.assign(
new Error(
'Route "/nav-fetch-under-suspense": 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'
),
{ __NEXT_ERROR_CODE: 'E1246' }
),
frames: createStoryFrames({
reason:
'Route "/nav-fetch-under-suspense": Next.js encountered uncached data during the initial render or a navigation.',
file: 'app/nav-fetch-under-suspense/page.tsx',
methodName: 'Page',
line: 6,
column: 21,
codeFrame: instantCodeFrame({
beforeLine: 'export default async function Page() {',
line: 'const res = await fetch("http://example.com", { cache: "no-store" })',
markerLine: 6,
pointerColumn: 21,
}),
}),
type: 'runtime',
},
]
...@@ -18,6 +18,54 @@ import { StatusIndicator, Status, getCurrentStatus } from './status-indicator' ...@@ -18,6 +18,54 @@ import { StatusIndicator, Status, getCurrentStatus } from './status-indicator'
const SHORT_DURATION_MS = 150 const SHORT_DURATION_MS = 150
function Plural({ count, animate }: { count: number; animate: boolean }) {
if (count <= 1) return null
return (
<span aria-hidden data-issues-count-plural data-animate={animate}>
s
</span>
)
}
function PillLabel({
normalCount,
instantCount,
normalCountAnimating,
instantCountAnimating,
}: {
normalCount: number
instantCount: number
normalCountAnimating: boolean
instantCountAnimating: boolean
}) {
const hasNormal = normalCount > 0
const hasInstant = instantCount > 0
return (
<>
{hasNormal && (
<>
Issue
<Plural
count={normalCount}
animate={normalCountAnimating && normalCount === 2}
/>
</>
)}
{hasNormal && hasInstant && ' · '}
{hasInstant && (
<>
{hasNormal && <>{instantCount} </>}
Insight
<Plural
count={instantCount}
animate={instantCountAnimating && instantCount === 2}
/>
</>
)}
</>
)
}
// Smooth out rapid status transitions driven by bursty HMR events (e.g. // Smooth out rapid status transitions driven by bursty HMR events (e.g.
// Compiling→None→Compiling when consecutive compile episodes are <300ms apart, // Compiling→None→Compiling when consecutive compile episodes are <300ms apart,
// or Compiling→Rendering→Compiling oscillation). The debounce bridges burst // or Compiling→Rendering→Compiling oscillation). The debounce bridges burst
...@@ -29,12 +77,16 @@ export function NextLogo({ ...@@ -29,12 +77,16 @@ export function NextLogo({
...buttonProps ...buttonProps
}: { onTriggerClick: () => void } & React.ComponentProps<'button'>) { }: { onTriggerClick: () => void } & React.ComponentProps<'button'>) {
const { state, dispatch } = useDevOverlayContext() const { state, dispatch } = useDevOverlayContext()
const { totalErrorCount } = useRenderErrorContext() const { totalErrorCount, normalErrorCount, instantErrorCount } =
useRenderErrorContext()
const SIZE = BASE_LOGO_SIZE / state.scale const SIZE = BASE_LOGO_SIZE / state.scale
const { panel, triggerRef, setPanel } = usePanelRouterContext() const { panel, triggerRef, setPanel } = usePanelRouterContext()
const isMenuOpen = panel === 'panel-selector' const isMenuOpen = panel === 'panel-selector'
const hasError = totalErrorCount > 0 const hasError = totalErrorCount > 0
// Only insights remain: use amber styling instead of red.
const insightsOnly =
hasError && normalErrorCount === 0 && instantErrorCount > 0
const [isErrorExpanded, setIsErrorExpanded] = useState(hasError) const [isErrorExpanded, setIsErrorExpanded] = useState(hasError)
const [previousHasError, setPreviousHasError] = useState(hasError) const [previousHasError, setPreviousHasError] = useState(hasError)
if (previousHasError !== hasError) { if (previousHasError !== hasError) {
...@@ -43,10 +95,19 @@ export function NextLogo({ ...@@ -43,10 +95,19 @@ export function NextLogo({
setIsErrorExpanded(hasError) setIsErrorExpanded(hasError)
} }
const [dismissed, setDismissed] = useState(false) const [dismissed, setDismissed] = useState(false)
const newErrorDetected = useUpdateAnimation( const normalErrorAnimating = useUpdateAnimation(
totalErrorCount, normalErrorCount,
SHORT_DURATION_MS SHORT_DURATION_MS
) )
const instantErrorAnimating = useUpdateAnimation(
instantErrorCount,
SHORT_DURATION_MS
)
const newErrorDetected = normalErrorAnimating || instantErrorAnimating
const leadingCount =
normalErrorCount > 0 ? normalErrorCount : instantErrorCount
const leadingCountAnimating =
normalErrorCount > 0 ? normalErrorAnimating : instantErrorAnimating
// Cache indicator state management // Cache indicator state management
const isCacheBypassing = state.cacheIndicator === 'bypass' const isCacheBypassing = state.cacheIndicator === 'bypass'
...@@ -202,6 +263,15 @@ export function NextLogo({ ...@@ -202,6 +263,15 @@ export function NextLogo({
} }
} }
&[data-insights-only='true']:not([data-error='true']) {
background: rgba(217, 119, 6, 0.95);
--color-inner-border: rgba(245, 158, 11, 0.9);
[data-issues-open] {
color: white;
}
}
&[data-error-expanded='false'][data-error='true'] ~ [data-dot] { &[data-error-expanded='false'][data-error='true'] ~ [data-dot] {
scale: 1; scale: 1;
} }
...@@ -393,7 +463,8 @@ export function NextLogo({ ...@@ -393,7 +463,8 @@ export function NextLogo({
</style> </style>
<div <div
data-next-badge data-next-badge
data-error={hasError} data-error={hasError && !insightsOnly}
data-insights-only={insightsOnly}
data-error-expanded={isExpanded} data-error-expanded={isExpanded}
data-status={hasError || isCacheBypassing ? Status.None : currentStatus} data-status={hasError || isCacheBypassing ? Status.None : currentStatus}
data-cache-bypassing={isCacheBypassing} data-cache-bypassing={isCacheBypassing}
...@@ -451,27 +522,19 @@ export function NextLogo({ ...@@ -451,27 +522,19 @@ export function NextLogo({
)} )}
<AnimateCount <AnimateCount
// Used the key to force a re-render when the count changes. // Used the key to force a re-render when the count changes.
key={totalErrorCount} key={leadingCount}
animate={newErrorDetected} animate={leadingCountAnimating}
data-issues-count-animation data-issues-count-animation
> >
{totalErrorCount} {leadingCount}
</AnimateCount>{' '} </AnimateCount>{' '}
<div> <div>
Issue <PillLabel
{totalErrorCount > 1 && ( normalCount={normalErrorCount}
<span instantCount={instantErrorCount}
aria-hidden normalCountAnimating={normalErrorAnimating}
data-issues-count-plural instantCountAnimating={instantErrorAnimating}
// This only needs to animate once the count changes from 1 -> 2, />
// otherwise it should stay static between re-renders.
data-animate={
newErrorDetected && totalErrorCount === 2
}
>
s
</span>
)}
</div> </div>
</button> </button>
{!state.buildError && ( {!state.buildError && (
......
...@@ -14,6 +14,7 @@ const CSS_SELECTORS_TO_EXCLUDE_ON_CLICK_OUTSIDE = [ ...@@ -14,6 +14,7 @@ const CSS_SELECTORS_TO_EXCLUDE_ON_CLICK_OUTSIDE = [
'[data-issues-open]', '[data-issues-open]',
'#nextjs-dev-tools-menu', '#nextjs-dev-tools-menu',
'[data-nextjs-error-overlay-nav]', '[data-nextjs-error-overlay-nav]',
'[data-nextjs-error-overlay-tab-bar]',
'[data-info-popover]', '[data-info-popover]',
'[data-nextjs-devtools-panel-overlay]', '[data-nextjs-devtools-panel-overlay]',
'[data-nextjs-devtools-panel-footer]', '[data-nextjs-devtools-panel-footer]',
......
...@@ -26,7 +26,8 @@ export function ErrorMessage({ errorMessage, errorType }: ErrorMessageProps) { ...@@ -26,7 +26,8 @@ export function ErrorMessage({ errorMessage, errorType }: ErrorMessageProps) {
// Instant errors are formatted specifically for the overlay rather than // Instant errors are formatted specifically for the overlay rather than
// passed through from the console, so we don't truncate them — they rely // passed through from the console, so we don't truncate them — they rely
// on scroll overflow instead. // on scroll overflow instead.
const shouldTruncate = isTooTall && errorType !== 'Instant' const shouldTruncate =
isTooTall && errorType !== 'Instant' && errorType !== 'Blocking Route'
return ( return (
<> <>
...@@ -34,7 +35,7 @@ export function ErrorMessage({ errorMessage, errorType }: ErrorMessageProps) { ...@@ -34,7 +35,7 @@ export function ErrorMessage({ errorMessage, errorType }: ErrorMessageProps) {
<div <div
ref={messageRef} ref={messageRef}
id="nextjs__container_errors_desc" id="nextjs__container_errors_desc"
className={`nextjs__container_errors_desc ${shouldTruncate && !isExpanded ? 'truncated' : ''} ${errorType === 'Instant' ? 'nextjs__container_errors_desc_instant' : ''}`} className={`nextjs__container_errors_desc ${shouldTruncate && !isExpanded ? 'truncated' : ''} ${errorType === 'Instant' || errorType === 'Blocking Route' ? 'nextjs__container_errors_desc_instant' : ''}`}
> >
{errorMessage} {errorMessage}
</div> </div>
......
...@@ -18,6 +18,7 @@ import { ...@@ -18,6 +18,7 @@ import {
ErrorOverlayNav, ErrorOverlayNav,
styles as floatingHeaderStyles, styles as floatingHeaderStyles,
} from '../error-overlay-nav/error-overlay-nav' } from '../error-overlay-nav/error-overlay-nav'
import type { ErrorOverlayTabBarRenderer } from '../error-overlay-pagination/error-overlay-pagination'
import { ErrorOverlayDialog, DIALOG_STYLES } from '../dialog/dialog' import { ErrorOverlayDialog, DIALOG_STYLES } from '../dialog/dialog'
import { import {
...@@ -38,6 +39,11 @@ export interface ErrorOverlayLayoutProps extends ErrorBaseProps { ...@@ -38,6 +39,11 @@ export interface ErrorOverlayLayoutProps extends ErrorBaseProps {
errorType: ErrorType errorType: ErrorType
children?: React.ReactNode children?: React.ReactNode
headerChildren?: React.ReactNode headerChildren?: React.ReactNode
renderTabBar?: ErrorOverlayTabBarRenderer
canGoPrevious?: boolean
canGoNext?: boolean
onPrevious?: () => void
onNext?: () => void
errorCode?: string errorCode?: string
error: ReadyRuntimeError['error'] error: ReadyRuntimeError['error']
debugInfo?: DebugInfo debugInfo?: DebugInfo
...@@ -56,6 +62,11 @@ export function ErrorOverlayLayout({ ...@@ -56,6 +62,11 @@ export function ErrorOverlayLayout({
errorType, errorType,
children, children,
headerChildren, headerChildren,
renderTabBar,
canGoPrevious,
canGoNext,
onPrevious,
onNext,
errorCode, errorCode,
errorCount: _errorCount, errorCount: _errorCount,
error, error,
...@@ -111,10 +122,15 @@ export function ErrorOverlayLayout({ ...@@ -111,10 +122,15 @@ export function ErrorOverlayLayout({
runtimeErrors={runtimeErrors} runtimeErrors={runtimeErrors}
activeIdx={activeIdx} activeIdx={activeIdx}
setActiveIndex={setActiveIndex} setActiveIndex={setActiveIndex}
canGoPrevious={canGoPrevious}
canGoNext={canGoNext}
onPrevious={onPrevious}
onNext={onNext}
versionInfo={versionInfo} versionInfo={versionInfo}
error={error} error={error}
debugInfo={debugInfo} debugInfo={debugInfo}
generateErrorInfo={generateErrorInfo} generateErrorInfo={generateErrorInfo}
renderTabBar={renderTabBar}
/> />
<ErrorOverlayDialog onClose={onClose} data-has-footer={hasFooter}> <ErrorOverlayDialog onClose={onClose} data-has-footer={hasFooter}>
<Resizer <Resizer
......
import type { DebugInfo } from '../../../../shared/types' import type { DebugInfo } from '../../../../shared/types'
import type { VersionInfo } from '../../../../../server/dev/parse-version-info' import type { VersionInfo } from '../../../../../server/dev/parse-version-info'
import { ErrorOverlayPagination } from '../error-overlay-pagination/error-overlay-pagination' import {
ErrorOverlayPagination,
type ErrorOverlayTabBarRenderer,
} from '../error-overlay-pagination/error-overlay-pagination'
import { ErrorOverlayToolbar } from '../error-overlay-toolbar/error-overlay-toolbar' import { ErrorOverlayToolbar } from '../error-overlay-toolbar/error-overlay-toolbar'
import type { ReadyRuntimeError } from '../../../utils/get-error-by-type' import type { ReadyRuntimeError } from '../../../utils/get-error-by-type'
...@@ -9,20 +12,30 @@ type ErrorOverlayNavProps = { ...@@ -9,20 +12,30 @@ type ErrorOverlayNavProps = {
runtimeErrors?: ReadyRuntimeError[] runtimeErrors?: ReadyRuntimeError[]
activeIdx?: number activeIdx?: number
setActiveIndex?: (index: number) => void setActiveIndex?: (index: number) => void
canGoPrevious?: boolean
canGoNext?: boolean
onPrevious?: () => void
onNext?: () => void
versionInfo?: VersionInfo versionInfo?: VersionInfo
error: ReadyRuntimeError['error'] error: ReadyRuntimeError['error']
debugInfo?: DebugInfo debugInfo?: DebugInfo
generateErrorInfo: () => Promise<string> generateErrorInfo: () => Promise<string>
renderTabBar?: ErrorOverlayTabBarRenderer
} }
export function ErrorOverlayNav({ export function ErrorOverlayNav({
runtimeErrors, runtimeErrors,
activeIdx, activeIdx,
setActiveIndex, setActiveIndex,
canGoPrevious,
canGoNext,
onPrevious,
onNext,
versionInfo, versionInfo,
error, error,
debugInfo, debugInfo,
generateErrorInfo, generateErrorInfo,
renderTabBar,
}: ErrorOverlayNavProps) { }: ErrorOverlayNavProps) {
const bundlerName = (process.env.__NEXT_BUNDLER || 'Turbopack') as const bundlerName = (process.env.__NEXT_BUNDLER || 'Turbopack') as
| 'Turbopack' | 'Turbopack'
...@@ -36,6 +49,11 @@ export function ErrorOverlayNav({ ...@@ -36,6 +49,11 @@ export function ErrorOverlayNav({
runtimeErrors={runtimeErrors ?? []} runtimeErrors={runtimeErrors ?? []}
activeIdx={activeIdx ?? 0} activeIdx={activeIdx ?? 0}
onActiveIndexChange={setActiveIndex ?? (() => {})} onActiveIndexChange={setActiveIndex ?? (() => {})}
canGoPrevious={canGoPrevious}
canGoNext={canGoNext}
onPrevious={onPrevious}
onNext={onNext}
renderTabBar={renderTabBar}
/> />
</NavItem> </NavItem>
<NavItem side="right"> <NavItem side="right">
...@@ -58,6 +76,7 @@ export const styles = ` ...@@ -58,6 +76,7 @@ export const styles = `
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center; align-items: center;
gap: 8px;
flex-shrink: 0; flex-shrink: 0;
width: 100%; width: 100%;
...@@ -84,6 +103,19 @@ export const styles = ` ...@@ -84,6 +103,19 @@ export const styles = `
} }
} }
@media (max-width: 767px) {
[data-nextjs-error-overlay-nav] {
overflow-x: auto;
overflow-y: hidden;
scrollbar-width: none;
-ms-overflow-style: none;
&::-webkit-scrollbar {
display: none;
}
}
}
` `
function NavItem({ function NavItem({
......
...@@ -9,18 +9,42 @@ import { LeftArrow } from '../../../icons/left-arrow' ...@@ -9,18 +9,42 @@ import { LeftArrow } from '../../../icons/left-arrow'
import { RightArrow } from '../../../icons/right-arrow' import { RightArrow } from '../../../icons/right-arrow'
import type { ReadyRuntimeError } from '../../../utils/get-error-by-type' import type { ReadyRuntimeError } from '../../../utils/get-error-by-type'
export type ErrorOverlayPaginationControls = {
previousButton: React.ReactNode
nextButton: React.ReactNode
createCount: (
activeIdx: number,
total: number,
isActive?: boolean
) => React.ReactNode
}
export type ErrorOverlayTabBarRenderer = (
controls: ErrorOverlayPaginationControls
) => React.ReactNode
type ErrorPaginationProps = { type ErrorPaginationProps = {
runtimeErrors: ReadyRuntimeError[] runtimeErrors: ReadyRuntimeError[]
activeIdx: number activeIdx: number
onActiveIndexChange: (index: number) => void onActiveIndexChange: (index: number) => void
canGoPrevious?: boolean
canGoNext?: boolean
onPrevious?: () => void
onNext?: () => void
renderTabBar?: ErrorOverlayTabBarRenderer
} }
export function ErrorOverlayPagination({ export function ErrorOverlayPagination({
runtimeErrors, runtimeErrors,
activeIdx, activeIdx,
onActiveIndexChange, onActiveIndexChange,
canGoPrevious,
canGoNext,
onPrevious,
onNext,
renderTabBar,
}: ErrorPaginationProps) { }: ErrorPaginationProps) {
const handlePrevious = useCallback( const handlePreviousWithinGroup = useCallback(
() => () =>
startTransition(() => { startTransition(() => {
if (activeIdx > 0) { if (activeIdx > 0) {
...@@ -30,7 +54,7 @@ export function ErrorOverlayPagination({ ...@@ -30,7 +54,7 @@ export function ErrorOverlayPagination({
[activeIdx, onActiveIndexChange] [activeIdx, onActiveIndexChange]
) )
const handleNext = useCallback( const handleNextWithinGroup = useCallback(
() => () =>
startTransition(() => { startTransition(() => {
if (activeIdx < runtimeErrors.length - 1) { if (activeIdx < runtimeErrors.length - 1) {
...@@ -42,6 +66,12 @@ export function ErrorOverlayPagination({ ...@@ -42,6 +66,12 @@ export function ErrorOverlayPagination({
[activeIdx, runtimeErrors.length, onActiveIndexChange] [activeIdx, runtimeErrors.length, onActiveIndexChange]
) )
const canNavigatePrevious = canGoPrevious ?? activeIdx > 0
const canNavigateNext = canGoNext ?? activeIdx < runtimeErrors.length - 1
const handlePrevious = onPrevious ?? handlePreviousWithinGroup
const handleNext = onNext ?? handleNextWithinGroup
const buttonLeft = useRef<HTMLButtonElement | null>(null) const buttonLeft = useRef<HTMLButtonElement | null>(null)
const buttonRight = useRef<HTMLButtonElement | null>(null) const buttonRight = useRef<HTMLButtonElement | null>(null)
...@@ -94,59 +124,87 @@ export function ErrorOverlayPagination({ ...@@ -94,59 +124,87 @@ export function ErrorOverlayPagination({
if (root instanceof ShadowRoot) { if (root instanceof ShadowRoot) {
const a = root.activeElement const a = root.activeElement
if (activeIdx === 0) { if (!canNavigatePrevious) {
if (buttonLeft.current && a === buttonLeft.current) { if (buttonLeft.current && a === buttonLeft.current) {
buttonLeft.current.blur() buttonLeft.current.blur()
} }
} else if (activeIdx === runtimeErrors.length - 1) { } else if (!canNavigateNext) {
if (buttonRight.current && a === buttonRight.current) { if (buttonRight.current && a === buttonRight.current) {
buttonRight.current.blur() buttonRight.current.blur()
} }
} }
} }
}, [nav, activeIdx, runtimeErrors.length]) }, [nav, canNavigateNext, canNavigatePrevious])
const previousButton = (
<button
ref={buttonLeft}
type="button"
disabled={!canNavigatePrevious}
aria-disabled={!canNavigatePrevious}
onClick={handlePrevious}
data-nextjs-dialog-error-previous
className="error-overlay-pagination-button"
>
<LeftArrow
title="previous"
className="error-overlay-pagination-button-icon"
/>
</button>
)
const createCount = (
currentActiveIdx: number,
total: number,
isActive: boolean = true
) => (
<div className="error-overlay-pagination-count">
<span
{...(isActive
? { 'data-nextjs-dialog-error-index': currentActiveIdx }
: {})}
>
{total === 0 ? 0 : currentActiveIdx + 1}/
</span>
<span
{...(isActive ? { 'data-nextjs-dialog-header-total-count': '' } : {})}
>
{total}
</span>
</div>
)
const nextButton = (
<button
ref={buttonRight}
type="button"
disabled={!canNavigateNext}
aria-disabled={!canNavigateNext}
onClick={handleNext}
data-nextjs-dialog-error-next
className="error-overlay-pagination-button"
>
<RightArrow
title="next"
className="error-overlay-pagination-button-icon"
/>
</button>
)
return ( return (
<nav <nav
className="error-overlay-pagination dialog-exclude-closing-from-outside-click" className="error-overlay-pagination dialog-exclude-closing-from-outside-click"
ref={onNav} ref={onNav}
> >
<button {renderTabBar ? (
ref={buttonLeft} renderTabBar({ previousButton, createCount, nextButton })
type="button" ) : (
disabled={activeIdx === 0} <>
aria-disabled={activeIdx === 0} {previousButton}
onClick={handlePrevious} {createCount(activeIdx, runtimeErrors.length || 1)}
data-nextjs-dialog-error-previous {nextButton}
className="error-overlay-pagination-button" </>
> )}
<LeftArrow
title="previous"
className="error-overlay-pagination-button-icon"
/>
</button>
<div className="error-overlay-pagination-count">
<span data-nextjs-dialog-error-index={activeIdx}>{activeIdx + 1}/</span>
<span data-nextjs-dialog-header-total-count>
{/* Display 1 out of 1 if there are no errors (e.g. for build errors). */}
{runtimeErrors.length || 1}
</span>
</div>
<button
ref={buttonRight}
type="button"
// If no errors or the last error is active, disable the button.
disabled={activeIdx >= runtimeErrors.length - 1}
aria-disabled={activeIdx >= runtimeErrors.length - 1}
onClick={handleNext}
data-nextjs-dialog-error-next
className="error-overlay-pagination-button"
>
<RightArrow
title="next"
className="error-overlay-pagination-button-icon"
/>
</button>
</nav> </nav>
) )
} }
...@@ -168,9 +226,11 @@ export const styles = ` ...@@ -168,9 +226,11 @@ export const styles = `
} }
.error-overlay-pagination-count { .error-overlay-pagination-count {
color: var(--color-gray-900); display: flex;
align-items: center;
color: inherit;
text-align: center; text-align: center;
font-size: var(--size-14); font-size: var(--size-13);
font-family: var(--font-mono); font-family: var(--font-mono);
line-height: var(--size-16); line-height: var(--size-16);
font-variant-numeric: tabular-nums; font-variant-numeric: tabular-nums;
......
...@@ -6,7 +6,7 @@ import { ...@@ -6,7 +6,7 @@ import {
import { Activity } from 'react' import { Activity } from 'react'
import { BuildError } from '../../../container/build-error' import { BuildError } from '../../../container/build-error'
import { Errors } from '../../../container/errors' import { Errors, isInstantNavigationError } from '../../../container/errors'
import { useDelayedRender } from '../../../hooks/use-delayed-render' import { useDelayedRender } from '../../../hooks/use-delayed-render'
import type { ReadyRuntimeError } from '../../../utils/get-error-by-type' import type { ReadyRuntimeError } from '../../../utils/get-error-by-type'
import type { HydrationErrorState } from '../../../../shared/hydration-error' import type { HydrationErrorState } from '../../../../shared/hydration-error'
...@@ -65,9 +65,20 @@ export function ErrorOverlay({ ...@@ -65,9 +65,20 @@ export function ErrorOverlay({
return null return null
} }
// Compute a key that resets tab state when the error composition changes
// (e.g., normal errors resolve leaving only instant errors).
const hasNormal = runtimeErrors.some(
(e) => !isInstantNavigationError(e.error)
)
const hasInstant = runtimeErrors.some((e) =>
isInstantNavigationError(e.error)
)
const tabKey = `${hasNormal ? 'n' : ''}${hasInstant ? 'i' : ''}`
return ( return (
<Activity mode={mounted ? 'visible' : 'hidden'}> <Activity mode={mounted ? 'visible' : 'hidden'}>
<Errors <Errors
key={tabKey}
{...commonProps} {...commonProps}
debugInfo={state.debugInfo} debugInfo={state.debugInfo}
getSquashedHydrationErrorDetails={getSquashedHydrationErrorDetails} getSquashedHydrationErrorDetails={getSquashedHydrationErrorDetails}
......
...@@ -15,7 +15,7 @@ export function ErrorTypeLabel({ errorType }: ErrorTypeLabelProps) { ...@@ -15,7 +15,7 @@ export function ErrorTypeLabel({ errorType }: ErrorTypeLabelProps) {
return ( return (
<span <span
id="nextjs__container_errors_label" id="nextjs__container_errors_label"
className={`nextjs__container_errors_label ${errorType === 'Blocking Route' || errorType === 'Ambiguous Metadata' ? 'nextjs__container_errors_label_blocking_page' : ''} ${errorType === 'Instant' ? 'nextjs__container_errors_label_instant' : ''}`} className={`nextjs__container_errors_label ${errorType === 'Ambiguous Metadata' ? 'nextjs__container_errors_label_blocking_page' : ''} ${errorType === 'Instant' ? 'nextjs__container_errors_label_instant' : ''}`}
> >
{errorType} {errorType}
</span> </span>
...@@ -43,7 +43,5 @@ export const styles = ` ...@@ -43,7 +43,5 @@ export const styles = `
.nextjs__container_errors_label_instant { .nextjs__container_errors_label_instant {
background: var(--color-amber-200); background: var(--color-amber-200);
color: var(--color-amber-900); color: var(--color-amber-900);
font-family: var(--font-stack-sans);
font-weight: 500;
} }
` `
...@@ -23,7 +23,7 @@ export const Resizer = forwardRef(function Resizer( ...@@ -23,7 +23,7 @@ export const Resizer = forwardRef(function Resizer(
// [x] Responds to content growth // [x] Responds to content growth
style={{ style={{
height: measuring ? 'auto' : height, height: measuring ? 'auto' : height,
transition: 'height 250ms var(--timing-swift)', transition: measuring ? 'none' : 'height 250ms var(--timing-swift)',
}} }}
> >
<div ref={setElement}>{children}</div> <div ref={setElement}>{children}</div>
......
...@@ -56,6 +56,8 @@ export const styles = ` ...@@ -56,6 +56,8 @@ export const styles = `
justify-content: center; justify-content: center;
align-items: center; align-items: center;
gap: 4px; gap: 4px;
white-space: nowrap;
flex-shrink: 0;
height: var(--size-24); height: var(--size-24);
padding: 6px 8px 6px 6px; padding: 6px 8px 6px 6px;
......
...@@ -14,6 +14,7 @@ import { ...@@ -14,6 +14,7 @@ import {
instantUncachedDataErrors, instantUncachedDataErrors,
instantViewportErrors, instantViewportErrors,
instantViewportUncachedErrors, instantViewportUncachedErrors,
mixedIssueAndInsightErrors,
runtimeErrors, runtimeErrors,
} from '../../../../.storybook/fixtures/errors' } from '../../../../.storybook/fixtures/errors'
...@@ -62,6 +63,13 @@ export const VeryLongErrorMessage: Story = { ...@@ -62,6 +63,13 @@ export const VeryLongErrorMessage: Story = {
}, },
} }
export const MixedIssuesAndInsights: Story = {
args: {
...Default.args,
runtimeErrors: mixedIssueAndInsightErrors,
},
}
export const WithHydrationWarning: Story = { export const WithHydrationWarning: Story = {
args: { args: {
...Default.args, ...Default.args,
......
...@@ -19,6 +19,7 @@ import { ...@@ -19,6 +19,7 @@ import {
} from '../../../server/app-render/sync-io-messages' } from '../../../server/app-render/sync-io-messages'
import { import {
getBlockingRouteErrorDetails, getBlockingRouteErrorDetails,
isInstantNavigationError,
isRuntimeVariant, isRuntimeVariant,
isSyncIOClientError, isSyncIOClientError,
isSyncIOError, isSyncIOError,
...@@ -253,3 +254,37 @@ describe('getBlockingRouteErrorDetails', () => { ...@@ -253,3 +254,37 @@ describe('getBlockingRouteErrorDetails', () => {
expect(getBlockingRouteErrorDetails(new Error('regular bug'))).toBe(null) expect(getBlockingRouteErrorDetails(new Error('regular bug'))).toBe(null)
}) })
}) })
describe('isInstantNavigationError', () => {
it('returns true for navigation-phase blocking-route errors', () => {
expect(
isInstantNavigationError(createRuntimeBodyErrorInNavigation(ROUTE))
).toBe(true)
expect(
isInstantNavigationError(createDynamicBodyErrorInNavigation(ROUTE))
).toBe(true)
})
it('returns false for prerender-phase blocking-route errors', () => {
expect(isInstantNavigationError(createRuntimeBodyError(ROUTE))).toBe(false)
expect(isInstantNavigationError(createDynamicBodyError(ROUTE))).toBe(false)
})
it('returns false for metadata/viewport/sync-io errors', () => {
expect(isInstantNavigationError(createDynamicMetadataError(ROUTE))).toBe(
false
)
expect(isInstantNavigationError(createRuntimeViewportError(ROUTE))).toBe(
false
)
expect(
isInstantNavigationError(
createSyncIOError(ROUTE, 'Math.random()', 'random')
)
).toBe(false)
})
it('returns false for unrelated errors', () => {
expect(isInstantNavigationError(new Error('regular bug'))).toBe(false)
})
})
...@@ -6,6 +6,7 @@ import { ...@@ -6,6 +6,7 @@ import {
getErrorByType, getErrorByType,
type ReadyRuntimeError, type ReadyRuntimeError,
} from '../../utils/get-error-by-type' } from '../../utils/get-error-by-type'
import { isInstantNavigationError } from '../errors'
export type SupportedErrorEvent = { export type SupportedErrorEvent = {
id: number id: number
...@@ -18,6 +19,8 @@ type Props = { ...@@ -18,6 +19,8 @@ type Props = {
children: (params: { children: (params: {
runtimeErrors: ReadyRuntimeError[] runtimeErrors: ReadyRuntimeError[]
totalErrorCount: number totalErrorCount: number
normalErrorCount: number
instantErrorCount: number
}) => React.ReactNode }) => React.ReactNode
state: OverlayState state: OverlayState
isAppDir: boolean isAppDir: boolean
...@@ -74,8 +77,18 @@ const RenderRuntimeError = ({ children, state, isAppDir }: Props) => { ...@@ -74,8 +77,18 @@ const RenderRuntimeError = ({ children, state, isAppDir }: Props) => {
}, [nextError, isAppDir]) }, [nextError, isAppDir])
const totalErrorCount = errors.length const totalErrorCount = errors.length
const instantErrorCount = useMemo(
() => runtimeErrors.filter((e) => isInstantNavigationError(e.error)).length,
[runtimeErrors]
)
const normalErrorCount = runtimeErrors.length - instantErrorCount
return children({ runtimeErrors, totalErrorCount }) return children({
runtimeErrors,
totalErrorCount,
normalErrorCount,
instantErrorCount,
})
} }
const RenderBuildError = ({ children }: Props) => { const RenderBuildError = ({ children }: Props) => {
...@@ -84,5 +97,7 @@ const RenderBuildError = ({ children }: Props) => { ...@@ -84,5 +97,7 @@ const RenderBuildError = ({ children }: Props) => {
// Build errors and missing root layout tags persist until fixed, // Build errors and missing root layout tags persist until fixed,
// so we can set a fixed error count of 1 // so we can set a fixed error count of 1
totalErrorCount: 1, totalErrorCount: 1,
normalErrorCount: 1,
instantErrorCount: 0,
}) })
} }
...@@ -14,6 +14,8 @@ import { ACTION_INSTANT_ERRORS_CLEAR, type DispatcherEvent } from './shared' ...@@ -14,6 +14,8 @@ import { ACTION_INSTANT_ERRORS_CLEAR, type DispatcherEvent } from './shared'
export const RenderErrorContext = createContext<{ export const RenderErrorContext = createContext<{
runtimeErrors: ReadyRuntimeError[] runtimeErrors: ReadyRuntimeError[]
totalErrorCount: number totalErrorCount: number
normalErrorCount: number
instantErrorCount: number
}>(null!) }>(null!)
export const useRenderErrorContext = () => useContext(RenderErrorContext) export const useRenderErrorContext = () => useContext(RenderErrorContext)
...@@ -55,13 +57,23 @@ export function DevOverlay() { ...@@ -55,13 +57,23 @@ export function DevOverlay() {
<ComponentStyles /> <ComponentStyles />
<RenderError state={state} isAppDir={true}> <RenderError state={state} isAppDir={true}>
{({ runtimeErrors, totalErrorCount }) => { {({
runtimeErrors,
totalErrorCount,
normalErrorCount,
instantErrorCount,
}) => {
return ( return (
<> <>
{state.showIndicator ? ( {state.showIndicator ? (
<> <>
<RenderErrorContext <RenderErrorContext
value={{ runtimeErrors, totalErrorCount }} value={{
runtimeErrors,
totalErrorCount,
normalErrorCount,
instantErrorCount,
}}
> >
<PanelRouterContext <PanelRouterContext
value={{ value={{
......
...@@ -8,11 +8,18 @@ import { extractNextErrorCode } from '../../../lib/error-telemetry-utils' ...@@ -8,11 +8,18 @@ import { extractNextErrorCode } from '../../../lib/error-telemetry-utils'
export function useActiveRuntimeError({ export function useActiveRuntimeError({
runtimeErrors, runtimeErrors,
getSquashedHydrationErrorDetails, getSquashedHydrationErrorDetails,
activeIdx: controlledActiveIdx,
setActiveIndex: controlledSetActiveIndex,
}: { }: {
runtimeErrors: ReadyRuntimeError[] runtimeErrors: ReadyRuntimeError[]
getSquashedHydrationErrorDetails: (error: Error) => HydrationErrorState | null getSquashedHydrationErrorDetails: (error: Error) => HydrationErrorState | null
activeIdx?: number
setActiveIndex?: (index: number) => void
}) { }) {
const [activeIdx, setActiveIndex] = useState<number>(0) const [uncontrolledActiveIdx, setUncontrolledActiveIndex] =
useState<number>(0)
const activeIdx = controlledActiveIdx ?? uncontrolledActiveIdx
const setActiveIndex = controlledSetActiveIndex ?? setUncontrolledActiveIndex
const isLoading = useMemo<boolean>(() => { const isLoading = useMemo<boolean>(() => {
return runtimeErrors.length === 0 return runtimeErrors.length === 0
......
...@@ -24,7 +24,7 @@ describe('Cache Components Dev Errors', () => { ...@@ -24,7 +24,7 @@ describe('Cache Components Dev Errors', () => {
"code": "E1261", "code": "E1261",
"description": "Next.js encountered the unstable value Math.random() while prerendering.", "description": "Next.js encountered the unstable value Math.random() while prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/error/page.tsx (2:23) @ Page "source": "app/error/page.tsx (2:23) @ Page
> 2 | const random = Math.random() > 2 | const random = Math.random()
| ^", | ^",
...@@ -54,7 +54,7 @@ describe('Cache Components Dev Errors', () => { ...@@ -54,7 +54,7 @@ describe('Cache Components Dev Errors', () => {
"code": "E1261", "code": "E1261",
"description": "Next.js encountered the unstable value Math.random() while prerendering.", "description": "Next.js encountered the unstable value Math.random() while prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/error/page.tsx (2:23) @ Page "source": "app/error/page.tsx (2:23) @ Page
> 2 | const random = Math.random() > 2 | const random = Math.random()
| ^", | ^",
...@@ -101,7 +101,7 @@ describe('Cache Components Dev Errors', () => { ...@@ -101,7 +101,7 @@ describe('Cache Components Dev Errors', () => {
"code": "E1265", "code": "E1265",
"description": "Next.js encountered uncached data during prerendering.", "description": "Next.js encountered uncached data during prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/no-accessed-data/page.js (2:9) @ Page "source": "app/no-accessed-data/page.js (2:9) @ Page
> 2 | await new Promise((r) => setTimeout(r, 200)) > 2 | await new Promise((r) => setTimeout(r, 200))
| ^", | ^",
......
...@@ -55,7 +55,7 @@ describe('Cache Components Fallback Validation', () => { ...@@ -55,7 +55,7 @@ describe('Cache Components Fallback Validation', () => {
"code": "E1272", "code": "E1272",
"description": "Next.js encountered runtime data during prerendering.", "description": "Next.js encountered runtime data during prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/partial/[top]/unwrapped/[bottom]/page.tsx (6:26) @ Page "source": "app/partial/[top]/unwrapped/[bottom]/page.tsx (6:26) @ Page
> 6 | Top: {(await props.params).top}, Bottom: {(await props.params).bottom} > 6 | Top: {(await props.params).top}, Bottom: {(await props.params).bottom}
| ^", | ^",
...@@ -70,7 +70,7 @@ describe('Cache Components Fallback Validation', () => { ...@@ -70,7 +70,7 @@ describe('Cache Components Fallback Validation', () => {
"code": "E1272", "code": "E1272",
"description": "Next.js encountered runtime data during prerendering.", "description": "Next.js encountered runtime data during prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/partial/[top]/unwrapped/[bottom]/page.tsx (6:26) @ Page "source": "app/partial/[top]/unwrapped/[bottom]/page.tsx (6:26) @ Page
> 6 | Top: {(await props.params).top}, Bottom: {(await props.params).bottom} > 6 | Top: {(await props.params).top}, Bottom: {(await props.params).bottom}
| ^", | ^",
...@@ -88,7 +88,7 @@ describe('Cache Components Fallback Validation', () => { ...@@ -88,7 +88,7 @@ describe('Cache Components Fallback Validation', () => {
"code": "E1272", "code": "E1272",
"description": "Next.js encountered runtime data during prerendering.", "description": "Next.js encountered runtime data during prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/partial/[top]/unwrapped/[bottom]/page.tsx (6:26) @ Page "source": "app/partial/[top]/unwrapped/[bottom]/page.tsx (6:26) @ Page
> 6 | Top: {(await props.params).top}, Bottom: {(await props.params).bottom} > 6 | Top: {(await props.params).top}, Bottom: {(await props.params).bottom}
| ^", | ^",
...@@ -103,7 +103,7 @@ describe('Cache Components Fallback Validation', () => { ...@@ -103,7 +103,7 @@ describe('Cache Components Fallback Validation', () => {
"code": "E1272", "code": "E1272",
"description": "Next.js encountered runtime data during prerendering.", "description": "Next.js encountered runtime data during prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/partial/[top]/unwrapped/[bottom]/page.tsx (6:26) @ Page "source": "app/partial/[top]/unwrapped/[bottom]/page.tsx (6:26) @ Page
> 6 | Top: {(await props.params).top}, Bottom: {(await props.params).bottom} > 6 | Top: {(await props.params).top}, Bottom: {(await props.params).bottom}
| ^", | ^",
...@@ -121,7 +121,7 @@ describe('Cache Components Fallback Validation', () => { ...@@ -121,7 +121,7 @@ describe('Cache Components Fallback Validation', () => {
"code": "E1272", "code": "E1272",
"description": "Next.js encountered runtime data during prerendering.", "description": "Next.js encountered runtime data during prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/partial/[top]/unwrapped/[bottom]/page.tsx (6:26) @ Page "source": "app/partial/[top]/unwrapped/[bottom]/page.tsx (6:26) @ Page
> 6 | Top: {(await props.params).top}, Bottom: {(await props.params).bottom} > 6 | Top: {(await props.params).top}, Bottom: {(await props.params).bottom}
| ^", | ^",
...@@ -136,7 +136,7 @@ describe('Cache Components Fallback Validation', () => { ...@@ -136,7 +136,7 @@ describe('Cache Components Fallback Validation', () => {
"code": "E1272", "code": "E1272",
"description": "Next.js encountered runtime data during prerendering.", "description": "Next.js encountered runtime data during prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/partial/[top]/unwrapped/[bottom]/page.tsx (6:26) @ Page "source": "app/partial/[top]/unwrapped/[bottom]/page.tsx (6:26) @ Page
> 6 | Top: {(await props.params).top}, Bottom: {(await props.params).bottom} > 6 | Top: {(await props.params).top}, Bottom: {(await props.params).bottom}
| ^", | ^",
...@@ -158,7 +158,7 @@ describe('Cache Components Fallback Validation', () => { ...@@ -158,7 +158,7 @@ describe('Cache Components Fallback Validation', () => {
"code": "E1272", "code": "E1272",
"description": "Next.js encountered runtime data during prerendering.", "description": "Next.js encountered runtime data during prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/none/[top]/wrapped/layout.tsx (10:3) @ Layout "source": "app/none/[top]/wrapped/layout.tsx (10:3) @ Layout
> 10 | await params > 10 | await params
| ^", | ^",
...@@ -173,7 +173,7 @@ describe('Cache Components Fallback Validation', () => { ...@@ -173,7 +173,7 @@ describe('Cache Components Fallback Validation', () => {
"code": "E1272", "code": "E1272",
"description": "Next.js encountered runtime data during prerendering.", "description": "Next.js encountered runtime data during prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/none/[top]/wrapped/layout.tsx (10:3) @ Layout "source": "app/none/[top]/wrapped/layout.tsx (10:3) @ Layout
> 10 | await params > 10 | await params
| ^", | ^",
...@@ -191,7 +191,7 @@ describe('Cache Components Fallback Validation', () => { ...@@ -191,7 +191,7 @@ describe('Cache Components Fallback Validation', () => {
"code": "E1272", "code": "E1272",
"description": "Next.js encountered runtime data during prerendering.", "description": "Next.js encountered runtime data during prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/none/[top]/wrapped/layout.tsx (10:3) @ Layout "source": "app/none/[top]/wrapped/layout.tsx (10:3) @ Layout
> 10 | await params > 10 | await params
| ^", | ^",
...@@ -206,7 +206,7 @@ describe('Cache Components Fallback Validation', () => { ...@@ -206,7 +206,7 @@ describe('Cache Components Fallback Validation', () => {
"code": "E1272", "code": "E1272",
"description": "Next.js encountered runtime data during prerendering.", "description": "Next.js encountered runtime data during prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/none/[top]/wrapped/layout.tsx (10:3) @ Layout "source": "app/none/[top]/wrapped/layout.tsx (10:3) @ Layout
> 10 | await params > 10 | await params
| ^", | ^",
...@@ -224,7 +224,7 @@ describe('Cache Components Fallback Validation', () => { ...@@ -224,7 +224,7 @@ describe('Cache Components Fallback Validation', () => {
"code": "E1272", "code": "E1272",
"description": "Next.js encountered runtime data during prerendering.", "description": "Next.js encountered runtime data during prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/none/[top]/wrapped/layout.tsx (10:3) @ Layout "source": "app/none/[top]/wrapped/layout.tsx (10:3) @ Layout
> 10 | await params > 10 | await params
| ^", | ^",
...@@ -239,7 +239,7 @@ describe('Cache Components Fallback Validation', () => { ...@@ -239,7 +239,7 @@ describe('Cache Components Fallback Validation', () => {
"code": "E1272", "code": "E1272",
"description": "Next.js encountered runtime data during prerendering.", "description": "Next.js encountered runtime data during prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/none/[top]/wrapped/layout.tsx (10:3) @ Layout "source": "app/none/[top]/wrapped/layout.tsx (10:3) @ Layout
> 10 | await params > 10 | await params
| ^", | ^",
...@@ -257,7 +257,7 @@ describe('Cache Components Fallback Validation', () => { ...@@ -257,7 +257,7 @@ describe('Cache Components Fallback Validation', () => {
"code": "E1272", "code": "E1272",
"description": "Next.js encountered runtime data during prerendering.", "description": "Next.js encountered runtime data during prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/none/[top]/unwrapped/layout.tsx (8:3) @ Layout "source": "app/none/[top]/unwrapped/layout.tsx (8:3) @ Layout
> 8 | await params > 8 | await params
| ^", | ^",
...@@ -272,7 +272,7 @@ describe('Cache Components Fallback Validation', () => { ...@@ -272,7 +272,7 @@ describe('Cache Components Fallback Validation', () => {
"code": "E1272", "code": "E1272",
"description": "Next.js encountered runtime data during prerendering.", "description": "Next.js encountered runtime data during prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/none/[top]/unwrapped/layout.tsx (8:3) @ Layout "source": "app/none/[top]/unwrapped/layout.tsx (8:3) @ Layout
> 8 | await params > 8 | await params
| ^", | ^",
...@@ -290,7 +290,7 @@ describe('Cache Components Fallback Validation', () => { ...@@ -290,7 +290,7 @@ describe('Cache Components Fallback Validation', () => {
"code": "E1272", "code": "E1272",
"description": "Next.js encountered runtime data during prerendering.", "description": "Next.js encountered runtime data during prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/none/[top]/unwrapped/layout.tsx (8:3) @ Layout "source": "app/none/[top]/unwrapped/layout.tsx (8:3) @ Layout
> 8 | await params > 8 | await params
| ^", | ^",
...@@ -305,7 +305,7 @@ describe('Cache Components Fallback Validation', () => { ...@@ -305,7 +305,7 @@ describe('Cache Components Fallback Validation', () => {
"code": "E1272", "code": "E1272",
"description": "Next.js encountered runtime data during prerendering.", "description": "Next.js encountered runtime data during prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/none/[top]/unwrapped/layout.tsx (8:3) @ Layout "source": "app/none/[top]/unwrapped/layout.tsx (8:3) @ Layout
> 8 | await params > 8 | await params
| ^", | ^",
...@@ -323,7 +323,7 @@ describe('Cache Components Fallback Validation', () => { ...@@ -323,7 +323,7 @@ describe('Cache Components Fallback Validation', () => {
"code": "E1272", "code": "E1272",
"description": "Next.js encountered runtime data during prerendering.", "description": "Next.js encountered runtime data during prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/none/[top]/unwrapped/layout.tsx (8:3) @ Layout "source": "app/none/[top]/unwrapped/layout.tsx (8:3) @ Layout
> 8 | await params > 8 | await params
| ^", | ^",
...@@ -338,7 +338,7 @@ describe('Cache Components Fallback Validation', () => { ...@@ -338,7 +338,7 @@ describe('Cache Components Fallback Validation', () => {
"code": "E1272", "code": "E1272",
"description": "Next.js encountered runtime data during prerendering.", "description": "Next.js encountered runtime data during prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/none/[top]/unwrapped/layout.tsx (8:3) @ Layout "source": "app/none/[top]/unwrapped/layout.tsx (8:3) @ Layout
> 8 | await params > 8 | await params
| ^", | ^",
......
import { Suspense } from 'react'
export default function Layout({ children }: { children: React.ReactNode }) {
return <Suspense fallback={<p>Loading...</p>}>{children}</Suspense>
}
export default async function Page() {
const res = await fetch('http://example.com', { cache: 'no-store' })
return <p>Status: {res.status}</p>
}
export default async function Page() {
const now = Date.now()
return <p>Now: {now}</p>
}
export default function Root({ children }: { children: React.ReactNode }) {
return (
<html>
<body>
<main>{children}</main>
</body>
</html>
)
}
import Link from 'next/link'
export default function HomePage() {
return (
<ul>
<li>
<Link href="/issue-only">issue-only</Link>
</li>
<li>
<Link href="/insight-only">insight-only</Link>
</li>
</ul>
)
}
import { nextTestSetup, type Playwright } from 'e2e-utils'
import { retry } from 'next-test-utils'
describe('instant insights tab overlay', () => {
const { next } = nextTestSetup({
files: __dirname,
})
// The dev overlay UI lives inside <nextjs-portal>'s shadow DOM, so we
// can't use Playwright's regular selectors.
function evalInPortal<T>(browser: Playwright, fn: (root: any) => T) {
return browser.eval(`(() => {
const portal = document.querySelector('nextjs-portal');
const root = portal && portal.shadowRoot;
if (!root) return null;
return (${fn.toString()})(root);
})()`) as Promise<T>
}
function getIndicatorPillState(browser: Playwright) {
return evalInPortal(browser, (root) => {
const badge = root.querySelector('[data-next-badge]')
if (!badge) return null
return {
hasError: badge.getAttribute('data-error') === 'true',
insightsOnly: badge.getAttribute('data-insights-only') === 'true',
text: badge.textContent?.trim() ?? '',
}
})
}
function hasErrorOverlayTabBar(browser: Playwright) {
return evalInPortal(browser, (root) => {
return !!root.querySelector('[data-nextjs-error-overlay-tab-bar]')
})
}
function getErrorOverlayTabCounts(browser: Playwright) {
return evalInPortal(browser, (root) => {
const bar = root.querySelector('[data-nextjs-error-overlay-tab-bar]')
if (!bar) return null
const tabs = bar.querySelectorAll('.error-overlay-tab')
const parseTotal = (tab: Element | undefined) => {
const totalEl = tab?.querySelector(
'.error-overlay-pagination-count > span:last-child'
)
return parseInt(totalEl?.textContent || '0', 10)
}
return {
errors: parseTotal(tabs[0]),
instant: parseTotal(tabs[1]),
}
})
}
function getActiveErrorOverlayTab(browser: Playwright) {
return evalInPortal(browser, (root) => {
const bar = root.querySelector('[data-nextjs-error-overlay-tab-bar]')
if (!bar) return null
const tabs = [...bar.querySelectorAll('.error-overlay-tab')]
const activeIndex = tabs.findIndex(
(tab) => tab.getAttribute('data-active') === 'true'
)
if (activeIndex === -1) return null
return activeIndex === 0 ? 'errors' : 'instant'
})
}
function getErrorOverlayTabs(browser: Playwright) {
return evalInPortal(browser, (root) => {
const bar = root.querySelector('[data-nextjs-error-overlay-tab-bar]')
if (!bar) return null
const variants = ['errors', 'instant'] as const
return [...bar.querySelectorAll('.error-overlay-tab')].map(
(tab: any, index: number) => ({
variant: variants[index],
disabled: tab.disabled === true,
active: tab.getAttribute('data-active') === 'true',
})
)
})
}
function clickIssuesTab(browser: Playwright) {
return browser.eval(`(() => {
const portal = document.querySelector('nextjs-portal');
const root = portal && portal.shadowRoot;
if (!root) return;
const tabs = root.querySelectorAll(
'[data-nextjs-error-overlay-tab-bar] .error-overlay-tab'
);
tabs[0] && tabs[0].click();
})()`)
}
function clickInsightsTab(browser: Playwright) {
return browser.eval(`(() => {
const portal = document.querySelector('nextjs-portal');
const root = portal && portal.shadowRoot;
if (!root) return;
const tabs = root.querySelectorAll(
'[data-nextjs-error-overlay-tab-bar] .error-overlay-tab'
);
tabs[1] && tabs[1].click();
})()`)
}
it('should show a red pill and no tab bar when only an Issue is present', async () => {
const browser = await next.browser('/issue-only')
await retry(async () => {
const state = await getIndicatorPillState(browser)
expect(state).not.toBeNull()
expect(state!.hasError).toBe(true)
expect(state!.insightsOnly).toBe(false)
expect(state!.text).toMatch(/1\s*Issue/i)
})
expect(await hasErrorOverlayTabBar(browser)).toBe(false)
})
it('should show an amber pill when only an Insight is present', async () => {
const browser = await next.browser('/')
await browser.elementByCss('a[href="/insight-only"]').click()
await retry(async () => {
const state = await getIndicatorPillState(browser)
expect(state).not.toBeNull()
expect(state!.hasError).toBe(false)
expect(state!.insightsOnly).toBe(true)
expect(state!.text).toMatch(/1\s*Insight/i)
})
expect(await hasErrorOverlayTabBar(browser)).toBe(true)
expect(await getActiveErrorOverlayTab(browser)).toBe('instant')
expect(await getErrorOverlayTabs(browser)).toEqual([
{ variant: 'errors', disabled: true, active: false },
{ variant: 'instant', disabled: false, active: true },
])
expect(await getErrorOverlayTabCounts(browser)).toEqual({
errors: 0,
instant: 1,
})
})
it('should not switch tabs when clicking a disabled tab', async () => {
const browser = await next.browser('/')
await browser.elementByCss('a[href="/insight-only"]').click()
await retry(async () => {
expect(await getActiveErrorOverlayTab(browser)).toBe('instant')
})
await clickIssuesTab(browser)
expect(await getActiveErrorOverlayTab(browser)).toBe('instant')
})
it('should show both tabs when an Issue and an Insight coexist', async () => {
const browser = await next.browser('/')
await browser.elementByCss('a[href="/issue-only"]').click()
await retry(async () => {
const state = await getIndicatorPillState(browser)
expect(state?.text).toMatch(/1\s*Issue/i)
})
await browser.eval('history.back()')
await browser.waitForElementByCss('a[href="/insight-only"]')
await browser.elementByCss('a[href="/insight-only"]').click()
await retry(async () => {
const counts = await getErrorOverlayTabCounts(browser)
expect(counts).toEqual({ errors: 1, instant: 1 })
})
const pill = await getIndicatorPillState(browser)
expect(pill?.hasError).toBe(true)
expect(pill?.insightsOnly).toBe(false)
expect(pill?.text).toMatch(/1\s*Issue\s*·\s*1\s*Insight/i)
expect(await getErrorOverlayTabs(browser)).toEqual([
{ variant: 'errors', disabled: false, active: true },
{ variant: 'instant', disabled: false, active: false },
])
await clickInsightsTab(browser)
await retry(async () => {
expect(await getActiveErrorOverlayTab(browser)).toBe('instant')
})
})
it('should clear the Insight when navigating away from the offending route', async () => {
const browser = await next.browser('/')
await browser.elementByCss('a[href="/insight-only"]').click()
await retry(async () => {
const state = await getIndicatorPillState(browser)
expect(state?.text).toMatch(/1\s*Insight/i)
})
await browser.eval('history.back()')
await browser.waitForElementByCss('a[href="/insight-only"]')
await retry(async () => {
const state = await getIndicatorPillState(browser)
expect(state).not.toBeNull()
expect(state!.hasError).toBe(false)
expect(state!.insightsOnly).toBe(false)
})
})
})
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
cacheComponents: true,
experimental: {
instantInsights: { validationLevel: 'experimental-error' },
},
}
module.exports = nextConfig
...@@ -232,7 +232,7 @@ describe('instant validation - level manual-warning', () => { ...@@ -232,7 +232,7 @@ describe('instant validation - level manual-warning', () => {
"code": "E1265", "code": "E1265",
"description": "Next.js encountered uncached data during prerendering.", "description": "Next.js encountered uncached data during prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/without-root-suspense/bare/page.tsx (10:19) @ Page "source": "app/without-root-suspense/bare/page.tsx (10:19) @ Page
> 10 | await connection() > 10 | await connection()
| ^", | ^",
...@@ -252,7 +252,7 @@ describe('instant validation - level manual-warning', () => { ...@@ -252,7 +252,7 @@ describe('instant validation - level manual-warning', () => {
"code": "E1265", "code": "E1265",
"description": "Next.js encountered uncached data during prerendering.", "description": "Next.js encountered uncached data during prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/without-root-suspense/explicit-error/page.tsx (11:19) @ Page "source": "app/without-root-suspense/explicit-error/page.tsx (11:19) @ Page
> 11 | await connection() > 11 | await connection()
| ^", | ^",
...@@ -272,7 +272,7 @@ describe('instant validation - level manual-warning', () => { ...@@ -272,7 +272,7 @@ describe('instant validation - level manual-warning', () => {
"code": "E1265", "code": "E1265",
"description": "Next.js encountered uncached data during prerendering.", "description": "Next.js encountered uncached data during prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/without-root-suspense/explicit-true/page.tsx (11:19) @ Page "source": "app/without-root-suspense/explicit-true/page.tsx (11:19) @ Page
> 11 | await connection() > 11 | await connection()
| ^", | ^",
...@@ -292,7 +292,7 @@ describe('instant validation - level manual-warning', () => { ...@@ -292,7 +292,7 @@ describe('instant validation - level manual-warning', () => {
"code": "E1265", "code": "E1265",
"description": "Next.js encountered uncached data during prerendering.", "description": "Next.js encountered uncached data during prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/without-root-suspense/explicit-warning/page.tsx (10:19) @ Page "source": "app/without-root-suspense/explicit-warning/page.tsx (10:19) @ Page
> 10 | await connection() > 10 | await connection()
| ^", | ^",
......
...@@ -48,7 +48,7 @@ describe('instant validation', () => { ...@@ -48,7 +48,7 @@ describe('instant validation', () => {
"code": "E1265", "code": "E1265",
"description": "Next.js encountered uncached data during prerendering.", "description": "Next.js encountered uncached data during prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/blocking-page-below-static/page.tsx (6:19) @ Page "source": "app/blocking-page-below-static/page.tsx (6:19) @ Page
> 6 | await connection() > 6 | await connection()
| ^", | ^",
......
...@@ -747,7 +747,7 @@ describe('instant validation', () => { ...@@ -747,7 +747,7 @@ describe('instant validation', () => {
"code": "E1261", "code": "E1261",
"description": "Next.js encountered the unstable value Date.now() while prerendering.", "description": "Next.js encountered the unstable value Date.now() while prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/suspense-in-root/runtime/invalid-sync-io/page.tsx (8:20) @ Page "source": "app/suspense-in-root/runtime/invalid-sync-io/page.tsx (8:20) @ Page
> 8 | const now = Date.now() > 8 | const now = Date.now()
| ^", | ^",
...@@ -825,7 +825,7 @@ describe('instant validation', () => { ...@@ -825,7 +825,7 @@ describe('instant validation', () => {
"code": "E1261", "code": "E1261",
"description": "Next.js encountered the unstable value Date.now() while prerendering.", "description": "Next.js encountered the unstable value Date.now() while prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/suspense-in-root/runtime/invalid-sync-io-in-runtime-with-valid-static-parent/page.tsx (12:20) @ Page "source": "app/suspense-in-root/runtime/invalid-sync-io-in-runtime-with-valid-static-parent/page.tsx (12:20) @ Page
> 12 | const now = Date.now() > 12 | const now = Date.now()
| ^", | ^",
...@@ -928,7 +928,7 @@ describe('instant validation', () => { ...@@ -928,7 +928,7 @@ describe('instant validation', () => {
"code": "E1261", "code": "E1261",
"description": "Next.js encountered the unstable value Date.now() while prerendering.", "description": "Next.js encountered the unstable value Date.now() while prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/suspense-in-root/runtime/invalid-sync-io-after-cache-with-cookie-input/page.tsx (28:20) @ Page "source": "app/suspense-in-root/runtime/invalid-sync-io-after-cache-with-cookie-input/page.tsx (28:20) @ Page
> 28 | const now = Date.now() > 28 | const now = Date.now()
| ^", | ^",
...@@ -1017,7 +1017,7 @@ describe('instant validation', () => { ...@@ -1017,7 +1017,7 @@ describe('instant validation', () => {
"code": "E1261", "code": "E1261",
"description": "Next.js encountered the unstable value Date.now() while prerendering.", "description": "Next.js encountered the unstable value Date.now() while prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/suspense-in-root/runtime/invalid-sync-io-in-generate-metadata/page.tsx (9:20) @ Module.generateMetadata "source": "app/suspense-in-root/runtime/invalid-sync-io-in-generate-metadata/page.tsx (9:20) @ Module.generateMetadata
> 9 | const now = Date.now() > 9 | const now = Date.now()
| ^", | ^",
...@@ -1113,7 +1113,7 @@ describe('instant validation', () => { ...@@ -1113,7 +1113,7 @@ describe('instant validation', () => {
"code": "E1261", "code": "E1261",
"description": "Next.js encountered the unstable value Date.now() while prerendering.", "description": "Next.js encountered the unstable value Date.now() while prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/suspense-in-root/runtime/invalid-sync-io-in-layout-generate-metadata/layout.tsx (11:20) @ Module.generateMetadata "source": "app/suspense-in-root/runtime/invalid-sync-io-in-layout-generate-metadata/layout.tsx (11:20) @ Module.generateMetadata
> 11 | const now = Date.now() > 11 | const now = Date.now()
| ^", | ^",
...@@ -2386,7 +2386,7 @@ describe('instant validation', () => { ...@@ -2386,7 +2386,7 @@ describe('instant validation', () => {
"code": "E1252", "code": "E1252",
"description": "Next.js encountered runtime data in generateViewport().", "description": "Next.js encountered runtime data in generateViewport().",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/suspense-in-root/head/invalid-runtime-viewport-in-static/page.tsx (11:16) @ Module.generateViewport "source": "app/suspense-in-root/head/invalid-runtime-viewport-in-static/page.tsx (11:16) @ Module.generateViewport
> 11 | await cookies() > 11 | await cookies()
| ^", | ^",
...@@ -2445,7 +2445,7 @@ describe('instant validation', () => { ...@@ -2445,7 +2445,7 @@ describe('instant validation', () => {
"code": "E1255", "code": "E1255",
"description": "Next.js encountered uncached data in generateViewport().", "description": "Next.js encountered uncached data in generateViewport().",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/suspense-in-root/head/invalid-dynamic-viewport-in-runtime/page.tsx (11:19) @ Module.generateViewport "source": "app/suspense-in-root/head/invalid-dynamic-viewport-in-runtime/page.tsx (11:19) @ Module.generateViewport
> 11 | await connection() > 11 | await connection()
| ^", | ^",
...@@ -2542,7 +2542,7 @@ describe('instant validation', () => { ...@@ -2542,7 +2542,7 @@ describe('instant validation', () => {
"code": "E1255", "code": "E1255",
"description": "Next.js encountered uncached data in generateViewport().", "description": "Next.js encountered uncached data in generateViewport().",
"environmentLabel": "Server", "environmentLabel": "Server",
"label": "Instant", "label": "Blocking Route",
"source": "app/suspense-in-root/head/invalid-dynamic-viewport-in-blocking-inside-static/page.tsx (6:23) @ Module.generateViewport "source": "app/suspense-in-root/head/invalid-dynamic-viewport-in-blocking-inside-static/page.tsx (6:23) @ Module.generateViewport
> 6 | export async function generateViewport(): Promise<Viewport> { > 6 | export async function generateViewport(): Promise<Viewport> {
| ^", | ^",
......
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