File size: 29,304 Bytes
b91e262 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 | import React, { useMemo, useRef, Suspense, useCallback } from 'react'
import type { DebugInfo } from '../../shared/types'
import { Overlay, OverlayBackdrop } from '../components/overlay'
import { RuntimeError } from './runtime-error'
import { getErrorSource } from '../../../shared/lib/error-source'
import { HotlinkedText } from '../components/hot-linked-text'
import { PseudoHtmlDiff } from './runtime-error/component-stack-pseudo-html'
import {
ErrorOverlayLayout,
type ErrorOverlayLayoutProps,
} from '../components/errors/error-overlay-layout/error-overlay-layout'
import {
getHydrationErrorStackInfo,
isHydrationError,
NEXTJS_HYDRATION_ERROR_LINK,
} from '../../shared/react-19-hydration-error'
import type { ReadyRuntimeError } from '../utils/get-error-by-type'
import { useFrames } from '../utils/get-error-by-type'
import type { ErrorBaseProps } from '../components/errors/error-overlay/error-overlay'
import type { HydrationErrorState } from '../../shared/hydration-error'
import { useActiveRuntimeError } from '../hooks/use-active-runtime-error'
import { formatCodeFrame } from '../components/code-frame/parse-code-frame'
import stripAnsi from 'next/dist/compiled/strip-ansi'
interface ErrorsProps extends ErrorBaseProps {
getSquashedHydrationErrorDetails: (error: Error) => HydrationErrorState | null
runtimeErrors: ReadyRuntimeError[]
debugInfo: DebugInfo
onClose: () => void
}
function matchLinkType(text: string): string | null {
if (text.startsWith('https://nextjs.org')) {
return 'nextjs-link'
}
if (text.startsWith('https://') || text.startsWith('http://')) {
return 'external-link'
}
return null
}
function HydrationErrorDescription({ message }: { message: string }) {
return <HotlinkedText text={message} matcher={matchLinkType} />
}
function GenericErrorDescription({ error }: { error: Error }) {
const environmentName =
'environmentName' in error ? error.environmentName : ''
const envPrefix = environmentName ? `[ ${environmentName} ] ` : ''
// The environment name will be displayed as a label, so remove it
// from the message (e.g. "[ Server ] hello world" -> "hello world").
let message = error.message
if (message.startsWith(envPrefix)) {
message = message.slice(envPrefix.length)
}
return (
<>
<HotlinkedText text={message} matcher={matchLinkType} />
</>
)
}
function DynamicMetadataErrorDescription({
variant,
}: {
variant: 'navigation' | 'runtime'
}) {
if (variant === 'navigation') {
return (
<div className="nextjs__blocking_page_load_error_description">
<h3 className="nextjs__blocking_page_load_error_description_title">
Data that blocks navigation was accessed inside{' '}
<code>generateMetadata()</code> in an otherwise prerenderable page
</h3>
<p>
When Document metadata is the only part of a page that cannot be
prerendered Next.js expects you to either make it prerenderable or
make some other part of the page non-prerenderable to avoid
unintentional partially dynamic pages. Uncached data such as{' '}
<code>fetch(...)</code>, cached data with a low expire time, or{' '}
<code>connection()</code> are all examples of data that only resolve
on navigation.
</p>
<h4>To fix this:</h4>
<p className="nextjs__blocking_page_load_error_fix_option">
<strong>
Move the asynchronous await into a Cache Component (
<code>"use cache"</code>)
</strong>
. This allows Next.js to statically prerender{' '}
<code>generateMetadata()</code> as part of the HTML document, so it's
instantly visible to the user.
</p>
<h4 className="nextjs__blocking_page_load_error_fix_option_separator">
or
</h4>
<p className="nextjs__blocking_page_load_error_fix_option">
<strong>
add <code>connection()</code> inside a <code>{'<Suspense>'}</code>
</strong>{' '}
somewhere in a Page or Layout. This tells Next.js that the page is
intended to have some non-prerenderable parts.
</p>
<p>
Learn more:{' '}
<a href="https://nextjs.org/docs/messages/next-prerender-dynamic-metadata">
https://nextjs.org/docs/messages/next-prerender-dynamic-metadata
</a>
</p>
</div>
)
} else {
return (
<div className="nextjs__blocking_page_load_error_description">
<h3 className="nextjs__blocking_page_load_error_description_title">
Runtime data was accessed inside <code>generateMetadata()</code> or
file-based metadata
</h3>
<p>
When Document metadata is the only part of a page that cannot be
prerendered Next.js expects you to either make it prerenderable or
make some other part of the page non-prerenderable to avoid
unintentional partially dynamic pages.
</p>
<h4>To fix this:</h4>
<p className="nextjs__blocking_page_load_error_fix_option">
<strong>
Remove the Runtime data access from <code>generateMetadata()</code>
</strong>
. This allows Next.js to statically prerender{' '}
<code>generateMetadata()</code> as part of the HTML document, so it's
instantly visible to the user.
</p>
<h4 className="nextjs__blocking_page_load_error_fix_option_separator">
or
</h4>
<p className="nextjs__blocking_page_load_error_fix_option">
<strong>
add <code>connection()</code> inside a <code>{'<Suspense>'}</code>
</strong>{' '}
somewhere in a Page or Layout. This tells Next.js that the page is
intended to have some non-prerenderable parts.
</p>
<p>
Note that if you are using file-based metadata, such as icons, inside
a route with dynamic params then the only recourse is to make some
other part of the page non-prerenderable.
</p>
<p>
Learn more:{' '}
<a href="https://nextjs.org/docs/messages/next-prerender-dynamic-metadata">
https://nextjs.org/docs/messages/next-prerender-dynamic-metadata
</a>
</p>
</div>
)
}
}
function BlockingPageLoadErrorDescription({
variant,
refinement,
}: {
variant: 'navigation' | 'runtime'
refinement: '' | 'generateViewport' | 'generateMetadata'
}) {
if (refinement === 'generateViewport') {
if (variant === 'navigation') {
return (
<div className="nextjs__blocking_page_load_error_description">
<h3 className="nextjs__blocking_page_load_error_description_title">
Data that blocks navigation was accessed inside{' '}
<code>generateViewport()</code>
</h3>
<p>
Viewport metadata needs to be available on page load so accessing
data that waits for a user navigation while producing it prevents
Next.js from prerendering an initial UI. Uncached data such as{' '}
<code>fetch(...)</code>, cached data with a low expire time, or{' '}
<code>connection()</code> are all examples of data that only resolve
on navigation.
</p>
<h4>To fix this:</h4>
<p className="nextjs__blocking_page_load_error_fix_option">
<strong>
Move the asynchronous await into a Cache Component (
<code>"use cache"</code>)
</strong>
. This allows Next.js to statically prerender{' '}
<code>generateViewport()</code> as part of the HTML document, so
it's instantly visible to the user.
</p>
<h4 className="nextjs__blocking_page_load_error_fix_option_separator">
or
</h4>
<p className="nextjs__blocking_page_load_error_fix_option">
<strong>
Put a <code>{'<Suspense>'}</code> around your document{' '}
<code>{'<body>'}</code>.
</strong>
This indicate to Next.js that you are opting into allowing blocking
navigations for any page.
</p>
<p>
Learn more:{' '}
<a href="https://nextjs.org/docs/messages/next-prerender-dynamic-viewport">
https://nextjs.org/docs/messages/next-prerender-dynamic-viewport
</a>
</p>
</div>
)
} else {
return (
<div className="nextjs__blocking_page_load_error_description">
<h3 className="nextjs__blocking_page_load_error_description_title">
Runtime data was accessed inside <code>generateViewport()</code>
</h3>
<p>
Viewport metadata needs to be available on page load so accessing
data that comes from a user Request while producing it prevents
Next.js from prerendering an initial UI.
<code>cookies()</code>, <code>headers()</code>, and{' '}
<code>searchParams</code>, are examples of Runtime data that can
only come from a user request.
</p>
<h4>To fix this:</h4>
<p className="nextjs__blocking_page_load_error_fix_option">
<strong>Remove the Runtime data requirement</strong> from{' '}
<code>generateViewport</code>. This allows Next.js to statically
prerender <code>generateViewport()</code> as part of the HTML
document, so it's instantly visible to the user.
</p>
<h4 className="nextjs__blocking_page_load_error_fix_option_separator">
or
</h4>
<p className="nextjs__blocking_page_load_error_fix_option">
<strong>
Put a <code>{'<Suspense>'}</code> around your document{' '}
<code>{'<body>'}</code>.
</strong>
This indicate to Next.js that you are opting into allowing blocking
navigations for any page.
</p>
<p>
<code>params</code> are usually considered Runtime data but if all
params are provided a value using <code>generateStaticParams</code>{' '}
they can be statically prerendered.
</p>
<p>
Learn more:{' '}
<a href="https://nextjs.org/docs/messages/next-prerender-dynamic-viewport">
https://nextjs.org/docs/messages/next-prerender-dynamic-viewport
</a>
</p>
</div>
)
}
} else if (refinement === 'generateMetadata') {
if (variant === 'navigation') {
return (
<div className="nextjs__blocking_page_load_error_description">
<h3 className="nextjs__blocking_page_load_error_description_title">
Data that blocks navigation was accessed inside{' '}
<code>generateMetadata()</code> in an otherwise prerenderable page
</h3>
<p>
When Document metadata is the only part of a page that cannot be
prerendered Next.js expects you to either make it prerenderable or
make some other part of the page non-prerenderable to avoid
unintentional partially dynamic pages. Uncached data such as{' '}
<code>fetch(...)</code>, cached data with a low expire time, or{' '}
<code>connection()</code> are all examples of data that only resolve
on navigation.
</p>
<h4>To fix this:</h4>
<p className="nextjs__blocking_page_load_error_fix_option">
<strong>
Move the asynchronous await into a Cache Component (
<code>"use cache"</code>)
</strong>
. This allows Next.js to statically prerender{' '}
<code>generateMetadata()</code> as part of the HTML document, so
it's instantly visible to the user.
</p>
<h4 className="nextjs__blocking_page_load_error_fix_option_separator">
or
</h4>
<p className="nextjs__blocking_page_load_error_fix_option">
<strong>
add <code>connection()</code> inside a <code>{'<Suspense>'}</code>
</strong>{' '}
somewhere in a Page or Layout. This tells Next.js that the page is
intended to have some non-prerenderable parts.
</p>
<p>
Learn more:{' '}
<a href="https://nextjs.org/docs/messages/next-prerender-dynamic-metadata">
https://nextjs.org/docs/messages/next-prerender-dynamic-metadata
</a>
</p>
</div>
)
} else {
return (
<div className="nextjs__blocking_page_load_error_description">
<h3 className="nextjs__blocking_page_load_error_description_title">
Runtime data was accessed inside <code>generateMetadata()</code> or
file-based metadata
</h3>
<p>
When Document metadata is the only part of a page that cannot be
prerendered Next.js expects you to either make it prerenderable or
make some other part of the page non-prerenderable to avoid
unintentional partially dynamic pages.
</p>
<h4>To fix this:</h4>
<p className="nextjs__blocking_page_load_error_fix_option">
<strong>
Remove the Runtime data access from{' '}
<code>generateMetadata()</code>
</strong>
. This allows Next.js to statically prerender{' '}
<code>generateMetadata()</code> as part of the HTML document, so
it's instantly visible to the user.
</p>
<h4 className="nextjs__blocking_page_load_error_fix_option_separator">
or
</h4>
<p className="nextjs__blocking_page_load_error_fix_option">
<strong>
add <code>connection()</code> inside a <code>{'<Suspense>'}</code>
</strong>{' '}
somewhere in a Page or Layout. This tells Next.js that the page is
intended to have some non-prerenderable parts.
</p>
<p>
Note that if you are using file-based metadata, such as icons,
inside a route with dynamic params then the only recourse is to make
some other part of the page non-prerenderable.
</p>
<p>
Learn more:{' '}
<a href="https://nextjs.org/docs/messages/next-prerender-dynamic-metadata">
https://nextjs.org/docs/messages/next-prerender-dynamic-metadata
</a>
</p>
</div>
)
}
}
if (variant === 'runtime') {
return (
<div className="nextjs__blocking_page_load_error_description">
<h3 className="nextjs__blocking_page_load_error_description_title">
Runtime data was accessed outside of {'<Suspense>'}
</h3>
<p>
This delays the entire page from rendering, resulting in a slow user
experience. Next.js uses this error to ensure your app loads instantly
on every navigation. <code>cookies()</code>, <code>headers()</code>,
and <code>searchParams</code>, are examples of Runtime data that can
only come from a user request.
</p>
<h4>To fix this:</h4>
<p className="nextjs__blocking_page_load_error_fix_option">
<strong>Provide a fallback UI using {'<Suspense>'}</strong> around
this component.
</p>
<h4 className="nextjs__blocking_page_load_error_fix_option_separator">
or
</h4>
<p className="nextjs__blocking_page_load_error_fix_option">
<strong>
Move the Runtime data access into a deeper component wrapped in{' '}
{'<Suspense>'}.
</strong>
</p>
<p>
In either case this allows Next.js to stream its contents to the user
when they request the page, while still providing an initial UI that
is prerendered and prefetchable for instant navigations.
</p>
<p>
Learn more:{' '}
<a href="https://nextjs.org/docs/messages/blocking-route">
https://nextjs.org/docs/messages/blocking-route
</a>
</p>
</div>
)
} else {
return (
<div className="nextjs__blocking_page_load_error_description">
<h3 className="nextjs__blocking_page_load_error_description_title">
Data that blocks navigation was accessed outside of {'<Suspense>'}
</h3>
<p>
This delays the entire page from rendering, resulting in a slow user
experience. Next.js uses this error to ensure your app loads instantly
on every navigation. Uncached data such as <code>fetch(...)</code>,
cached data with a low expire time, or <code>connection()</code> are
all examples of data that only resolve on navigation.
</p>
<h4>To fix this, you can either:</h4>
<p className="nextjs__blocking_page_load_error_fix_option">
<strong>Provide a fallback UI using {'<Suspense>'}</strong> around
this component. This allows Next.js to stream its contents to the user
as soon as it's ready, without blocking the rest of the app.
</p>
<h4 className="nextjs__blocking_page_load_error_fix_option_separator">
or
</h4>
<p className="nextjs__blocking_page_load_error_fix_option">
<strong>
Move the asynchronous await into a Cache Component (
<code>"use cache"</code>)
</strong>
. This allows Next.js to statically prerender the component as part of
the HTML document, so it's instantly visible to the user.
</p>
<p>
Learn more:{' '}
<a href="https://nextjs.org/docs/messages/blocking-route">
https://nextjs.org/docs/messages/blocking-route
</a>
</p>
</div>
)
}
}
export function getErrorTypeLabel(
error: Error,
type: ReadyRuntimeError['type'],
errorDetails: ErrorDetails
): ErrorOverlayLayoutProps['errorType'] {
if (errorDetails.type === 'blocking-route') {
return `Blocking Route`
}
if (errorDetails.type === 'dynamic-metadata') {
return `Ambiguous Metadata`
}
if (type === 'recoverable') {
return `Recoverable ${error.name}`
}
if (type === 'console') {
return `Console ${error.name}`
}
return `Runtime ${error.name}`
}
type ErrorDetails =
| NoErrorDetails
| HydrationErrorDetails
| BlockingRouteErrorDetails
| DynamicMetadataErrorDetails
type NoErrorDetails = {
type: 'empty'
}
type HydrationErrorDetails = {
type: 'hydration'
warning: string | null
notes: string | null
reactOutputComponentDiff: string | null
}
type BlockingRouteErrorDetails = {
type: 'blocking-route'
variant: 'navigation' | 'runtime'
refinement: '' | 'generateViewport'
}
type DynamicMetadataErrorDetails = {
type: 'dynamic-metadata'
variant: 'navigation' | 'runtime'
}
const noErrorDetails: ErrorDetails = {
type: 'empty',
}
export function useErrorDetails(
error: Error | undefined,
getSquashedHydrationErrorDetails: (error: Error) => HydrationErrorState | null
): ErrorDetails {
return useMemo(() => {
if (error === undefined) {
return noErrorDetails
}
const hydrationErrorDetails = getHydrationErrorDetails(
error,
getSquashedHydrationErrorDetails
)
if (hydrationErrorDetails) {
return hydrationErrorDetails
}
const blockingRouteErrorDetails = getBlockingRouteErrorDetails(error)
if (blockingRouteErrorDetails) {
return blockingRouteErrorDetails
}
return noErrorDetails
}, [error, getSquashedHydrationErrorDetails])
}
function getHydrationErrorDetails(
error: Error,
getSquashedHydrationErrorDetails: (error: Error) => HydrationErrorState | null
): null | HydrationErrorDetails {
const pagesRouterErrorDetails = getSquashedHydrationErrorDetails(error)
if (pagesRouterErrorDetails !== null) {
return {
type: 'hydration',
warning: pagesRouterErrorDetails.warning ?? null,
notes: null,
reactOutputComponentDiff:
pagesRouterErrorDetails.reactOutputComponentDiff ?? null,
}
}
if (!isHydrationError(error)) {
return null
}
const { message, notes, diff } = getHydrationErrorStackInfo(error)
if (message === null) {
return null
}
return {
type: 'hydration',
warning: message,
notes,
reactOutputComponentDiff: diff,
}
}
function getBlockingRouteErrorDetails(error: Error): null | ErrorDetails {
const isBlockingPageLoadError = error.message.includes('/blocking-route')
if (isBlockingPageLoadError) {
const isRuntimeData = error.message.includes('cookies()')
return {
type: 'blocking-route',
variant: isRuntimeData ? 'runtime' : 'navigation',
refinement: '',
}
}
const isDynamicMetadataError = error.message.includes(
'/next-prerender-dynamic-metadata'
)
if (isDynamicMetadataError) {
const isRuntimeData = error.message.includes('cookies()')
return {
type: 'dynamic-metadata',
variant: isRuntimeData ? 'runtime' : 'navigation',
}
}
const isBlockingViewportError = error.message.includes(
'/next-prerender-dynamic-viewport'
)
if (isBlockingViewportError) {
const isRuntimeData = error.message.includes('cookies()')
return {
type: 'blocking-route',
variant: isRuntimeData ? 'runtime' : 'navigation',
refinement: 'generateViewport',
}
}
return null
}
export function Errors({
getSquashedHydrationErrorDetails,
runtimeErrors,
debugInfo,
onClose,
...props
}: ErrorsProps) {
const dialogResizerRef = useRef<HTMLDivElement | null>(null)
const {
isLoading,
errorCode,
errorType,
activeIdx,
errorDetails,
activeError,
setActiveIndex,
} = useActiveRuntimeError({ runtimeErrors, getSquashedHydrationErrorDetails })
// Get parsed frames data
const frames = useFrames(activeError)
const firstFrame = useMemo(() => {
const firstFirstPartyFrameIndex = frames.findIndex(
(entry) =>
!entry.ignored &&
Boolean(entry.originalCodeFrame) &&
Boolean(entry.originalStackFrame)
)
return frames[firstFirstPartyFrameIndex] ?? null
}, [frames])
const generateErrorInfo = useCallback(() => {
if (!activeError) return ''
const parts: string[] = []
// 1. Error Type
if (errorType) {
parts.push(`## Error Type\n${errorType}`)
}
// 2. Error Message
const error = activeError.error
let message = error.message
if ('environmentName' in error && error.environmentName) {
const envPrefix = `[ ${error.environmentName} ] `
if (message.startsWith(envPrefix)) {
message = message.slice(envPrefix.length)
}
}
if (message) {
parts.push(`## Error Message\n${message}`)
}
// Append call stack
if (frames.length > 0) {
const visibleFrames = frames.filter((frame) => !frame.ignored)
if (visibleFrames.length > 0) {
const stackLines = visibleFrames
.map((frame) => {
if (frame.originalStackFrame) {
const { methodName, file, line1, column1 } =
frame.originalStackFrame
return ` at ${methodName} (${file}:${line1}:${column1})`
} else if (frame.sourceStackFrame) {
const { methodName, file, line1, column1 } =
frame.sourceStackFrame
return ` at ${methodName} (${file}:${line1}:${column1})`
}
return ''
})
.filter(Boolean)
if (stackLines.length > 0) {
parts.push(`\n${stackLines.join('\n')}`)
}
}
}
// 3. Code Frame (decoded)
if (firstFrame?.originalCodeFrame) {
const decodedCodeFrame = stripAnsi(
formatCodeFrame(firstFrame.originalCodeFrame)
)
parts.push(`## Code Frame\n${decodedCodeFrame}`)
}
// Format as markdown error info
const errorInfo = `${parts.join('\n\n')}
Next.js version: ${props.versionInfo.installed} (${process.env.__NEXT_BUNDLER})\n`
return errorInfo
}, [activeError, errorType, firstFrame, frames, props.versionInfo])
if (isLoading) {
// TODO: better loading state
return (
<Overlay>
<OverlayBackdrop />
</Overlay>
)
}
if (!activeError) {
return null
}
const error = activeError.error
const isServerError = ['server', 'edge-server'].includes(
getErrorSource(error) || ''
)
let errorMessage: React.ReactNode
let maybeNotes: React.ReactNode = null
let maybeDiff: React.ReactNode = null
switch (errorDetails.type) {
case 'hydration':
errorMessage = errorDetails.warning ? (
<HydrationErrorDescription message={errorDetails.warning} />
) : (
<GenericErrorDescription error={error} />
)
maybeNotes = (
<div className="error-overlay-notes-container">
{errorDetails.notes ? (
<>
<p
id="nextjs__container_errors__notes"
className="nextjs__container_errors__notes"
>
{errorDetails.notes}
</p>
</>
) : null}
{errorDetails.warning ? (
<p
id="nextjs__container_errors__link"
className="nextjs__container_errors__link"
>
<HotlinkedText
text={`See more info here: ${NEXTJS_HYDRATION_ERROR_LINK}`}
/>
</p>
) : null}
</div>
)
if (errorDetails.reactOutputComponentDiff) {
maybeDiff = (
<PseudoHtmlDiff
reactOutputComponentDiff={
errorDetails.reactOutputComponentDiff || ''
}
/>
)
}
break
case 'blocking-route':
errorMessage = (
<BlockingPageLoadErrorDescription
variant={errorDetails.variant}
refinement={errorDetails.refinement}
/>
)
break
case 'dynamic-metadata':
errorMessage = (
<DynamicMetadataErrorDescription variant={errorDetails.variant} />
)
break
case 'empty':
errorMessage = <GenericErrorDescription error={error} />
break
default:
errorDetails satisfies never
}
return (
<ErrorOverlayLayout
errorCode={errorCode}
errorType={errorType}
errorMessage={errorMessage}
onClose={isServerError ? undefined : onClose}
debugInfo={debugInfo}
error={error}
runtimeErrors={runtimeErrors}
activeIdx={activeIdx}
setActiveIndex={setActiveIndex}
dialogResizerRef={dialogResizerRef}
generateErrorInfo={generateErrorInfo}
{...props}
>
{maybeNotes}
{maybeDiff}
<Suspense fallback={<div data-nextjs-error-suspended />}>
<RuntimeError
key={activeError.id.toString()}
error={activeError}
dialogResizerRef={dialogResizerRef}
/>
</Suspense>
</ErrorOverlayLayout>
)
}
export const styles = `
.nextjs-error-with-static {
bottom: calc(16px * 4.5);
}
p.nextjs__container_errors__link {
font-size: var(--size-14);
}
p.nextjs__container_errors__notes {
color: var(--color-stack-notes);
font-size: var(--size-14);
line-height: 1.5;
}
.nextjs-container-errors-body > h2:not(:first-child) {
margin-top: calc(16px + 8px);
}
.nextjs-container-errors-body > h2 {
color: var(--color-title-color);
margin-bottom: 8px;
font-size: var(--size-20);
}
.nextjs-toast-errors-parent {
cursor: pointer;
transition: transform 0.2s ease;
}
.nextjs-toast-errors-parent:hover {
transform: scale(1.1);
}
.nextjs-toast-errors {
display: flex;
align-items: center;
justify-content: flex-start;
}
.nextjs-toast-errors > svg {
margin-right: 8px;
}
.nextjs-toast-hide-button {
margin-left: 24px;
border: none;
background: none;
color: var(--color-ansi-bright-white);
padding: 0;
transition: opacity 0.25s ease;
opacity: 0.7;
}
.nextjs-toast-hide-button:hover {
opacity: 1;
}
.nextjs__container_errors__error_title {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 14px;
}
.error-overlay-notes-container {
margin: 8px 2px;
}
.error-overlay-notes-container p {
white-space: pre-wrap;
}
.nextjs__blocking_page_load_error_description {
color: var(--color-stack-notes);
}
.nextjs__blocking_page_load_error_description_title {
color: var(--color-title-color);
}
.nextjs__blocking_page_load_error_fix_option {
background-color: var(--color-background-200);
padding: 14px;
border-radius: var(--rounded-md-2);
border: 1px solid var(--color-gray-alpha-400);
}
.external-link, .external-link:hover {
color:inherit;
}
`
|