Unverified Commit c334056e authored by Sebastian "Sebbie" Silbermann's avatar Sebastian "Sebbie" Silbermann Committed by GitHub

[dev-overlay] Add dedicated label for recoverable errors (#78186)

parent 902b58c0
......@@ -2,6 +2,7 @@ export type ErrorType =
| 'Build Error'
| 'Runtime Error'
| 'Console Error'
| 'Recoverable Error'
| 'Missing Required HTML Tag'
type ErrorTypeLabelProps = {
......
......@@ -22,6 +22,7 @@ import {
import type { ReadyRuntimeError } from '../../utils/get-error-by-type'
import type { ErrorBaseProps } from '../components/errors/error-overlay/error-overlay'
import { getSquashedHydrationErrorDetails } from '../../pages/hydration-error-state'
import { isRecoverableError } from '../../../../react-client-callbacks/on-recoverable-error'
export interface ErrorsProps extends ErrorBaseProps {
runtimeErrors: ReadyRuntimeError[]
......@@ -68,6 +69,9 @@ function GenericErrorDescription({ error }: { error: Error }) {
}
function getErrorType(error: Error): ErrorOverlayLayoutProps['errorType'] {
if (isRecoverableError(error)) {
return 'Recoverable Error'
}
if (isConsoleError(error)) {
return 'Console Error'
}
......
......@@ -10,6 +10,12 @@ import {
import isError from '../../lib/is-error'
import { reportGlobalError } from './report-global-error'
const recoverableErrors = new WeakSet<Error>()
export function isRecoverableError(error: Error): boolean {
return recoverableErrors.has(error)
}
export const onRecoverableError: HydrationOptions['onRecoverableError'] = (
error,
errorInfo
......@@ -20,6 +26,7 @@ export const onRecoverableError: HydrationOptions['onRecoverableError'] = (
if (isBailoutToCSRError(cause)) return
const causeError = coerceError(cause)
recoverableErrors.add(causeError)
setOwnerStackIfAvailable(causeError)
if (process.env.NODE_ENV === 'development' && errorInfo.componentStack) {
......
......@@ -92,7 +92,7 @@ describe('Error overlay for hydration errors in App router', () => {
...",
"description": "Hydration failed because the server rendered text didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": "app/page.js (6:7) @ Mismatch
> 6 | <main className="child">{isClient ? "client" : "server"}</main>
| ^",
......@@ -167,7 +167,7 @@ describe('Error overlay for hydration errors in App router', () => {
...",
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": "app/page.js (6:20) @ Mismatch
> 6 | {isClient && <main className="only" />}
| ^",
......@@ -323,7 +323,7 @@ describe('Error overlay for hydration errors in App router', () => {
...",
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": "app/page.js (5:5) @ Mismatch
> 5 | <div className="parent">
| ^",
......@@ -377,7 +377,7 @@ describe('Error overlay for hydration errors in App router', () => {
...",
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": "app/page.js (5:5) @ Mismatch
> 5 | <div className="parent">
| ^",
......@@ -427,7 +427,7 @@ describe('Error overlay for hydration errors in App router', () => {
...",
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": "app/page.js (4:10) @ Mismatch
> 4 | return <div className="parent">{!isClient && "only"}</div>;
| ^",
......@@ -517,7 +517,7 @@ describe('Error overlay for hydration errors in App router', () => {
...",
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": "app/page.js (4:5) @ Page
> 4 | <table>
| ^",
......@@ -635,7 +635,7 @@ describe('Error overlay for hydration errors in App router', () => {
...",
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": "app/page.js (9:22) @ Mismatch
> 9 | {isClient && <main className="second" />}
| ^",
......@@ -738,7 +738,7 @@ describe('Error overlay for hydration errors in App router', () => {
{
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": "app/page.js (6:7) @ Page
> 6 | <p>Nested p tags</p>
| ^",
......@@ -817,7 +817,7 @@ describe('Error overlay for hydration errors in App router', () => {
{
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": "app/page.js (8:11) @ Page
> 8 | <div>Nested div under p tag</div>
| ^",
......@@ -886,7 +886,7 @@ describe('Error overlay for hydration errors in App router', () => {
{
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": "app/page.js (3:15) @ Page
> 3 | return <div><tr></tr></div>
| ^",
......@@ -975,7 +975,7 @@ describe('Error overlay for hydration errors in App router', () => {
{
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": "app/page.js (5:32) @ Page
> 5 | <p><span><span><span><span><p>hello world</p></span></span></span></span></p>
| ^",
......
......@@ -1135,7 +1135,7 @@ describe('ReactRefreshLogBox', () => {
{
"description": "Error: There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": null,
"stack": [],
},
......@@ -1173,7 +1173,7 @@ describe('ReactRefreshLogBox', () => {
{
"description": "Error: There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": null,
"stack": [],
},
......
......@@ -42,7 +42,7 @@ describe('hydration-error-count', () => {
{
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": "app/bad-nesting/page.tsx (6:7) @ Page
> 6 | <p>nest</p>
| ^",
......@@ -79,7 +79,7 @@ describe('hydration-error-count', () => {
...",
"description": "Hydration failed because the server rendered text didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": "app/html-diff/page.tsx (4:10) @ Page
> 4 | return <p>{typeof window === 'undefined' ? 'server' : 'client'}</p>
| ^",
......@@ -146,7 +146,7 @@ describe('hydration-error-count', () => {
...",
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": "app/two-issues/page.tsx (10:7) @ Page
> 10 | <p>nest</p>
| ^",
......@@ -196,7 +196,7 @@ describe('hydration-error-count', () => {
{
"description": "Hydration failed because the server rendered HTML didn't match the client. As a result this tree will be regenerated on the client. This can happen if a SSR-ed Client Component used:",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": "app/hydration-with-runtime-errors/page.tsx (12:14) @ Page
> 12 | sneaky <p>very sneaky</p>
| ^",
......
......@@ -1279,7 +1279,7 @@ describe('Client Navigation', () => {
{
"description": "Error: There was an error while hydrating. Because the error happened outside of a Suspense boundary, the entire root will switch to client rendering.",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": null,
"stack": [],
},
......
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