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": [],
},
......
......@@ -85,14 +85,14 @@ describe('Error overlay for hydration errors in Pages router', () => {
- "client"",
"description": "Text content did not match. Server: "server" Client: "client"",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": null,
"stack": [],
},
{
"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": [],
},
......@@ -117,7 +117,7 @@ describe('Error overlay for hydration errors in Pages 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": "index.js (5:9) @ Mismatch
> 5 | <main className="child">{isClient ? "client" : "server"}</main>
| ^",
......@@ -191,14 +191,14 @@ describe('Error overlay for hydration errors in Pages router', () => {
> <main>",
"description": "Expected server HTML to contain a matching <main> in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": null,
"stack": [],
},
{
"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": [],
},
......@@ -221,7 +221,7 @@ describe('Error overlay for hydration errors in Pages 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": "index.js (5:20) @ Mismatch
> 5 | {isClient && <main className="only" />}
| ^",
......@@ -282,14 +282,14 @@ describe('Error overlay for hydration errors in Pages router', () => {
> "second"",
"description": "Expected server HTML to contain a matching text node for "second" in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": null,
"stack": [],
},
{
"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": [],
},
......@@ -315,7 +315,7 @@ describe('Error overlay for hydration errors in Pages 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": "index.js (4:5) @ Mismatch
> 4 | <div className="parent">
| ^",
......@@ -357,14 +357,14 @@ describe('Error overlay for hydration errors in Pages router', () => {
> <div>",
"description": "Did not expect server HTML to contain a <main> in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": null,
"stack": [],
},
{
"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": [],
},
......@@ -388,7 +388,7 @@ describe('Error overlay for hydration errors in Pages 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": "index.js (4:5) @ Mismatch
> 4 | <div className="parent">
| ^",
......@@ -428,14 +428,14 @@ describe('Error overlay for hydration errors in Pages router', () => {
> "only"",
"description": "Did not expect server HTML to contain the text node "only" in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": null,
"stack": [],
},
{
"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": [],
},
......@@ -459,7 +459,7 @@ describe('Error overlay for hydration errors in Pages 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": "index.js (3:10) @ Mismatch
> 3 | return <div className="parent">{!isClient && "only"}</div>;
| ^",
......@@ -520,14 +520,14 @@ describe('Error overlay for hydration errors in Pages router', () => {
> <table>",
"description": "Expected server HTML to contain a matching <table> in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": null,
"stack": [],
},
{
"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": [],
},
......@@ -552,7 +552,7 @@ describe('Error overlay for hydration errors in Pages router', () => {
"description": "In HTML, text nodes cannot be a child of <tr>.
This will cause a hydration error.",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": "index.js (3:5) @ Page
> 3 | <table>
| ^",
......@@ -607,14 +607,14 @@ describe('Error overlay for hydration errors in Pages router', () => {
> <table>",
"description": "Expected server HTML to contain a matching <table> in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": null,
"stack": [],
},
{
"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": [],
},
......@@ -640,7 +640,7 @@ describe('Error overlay for hydration errors in Pages router', () => {
"description": "In HTML, text nodes cannot be a child of <table>.
This will cause a hydration error.",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": "index.js (3:5) @ Page
> 3 | <table>
| ^",
......@@ -704,14 +704,14 @@ describe('Error overlay for hydration errors in Pages router', () => {
> <main>",
"description": "Expected server HTML to contain a matching <main> in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": null,
"stack": [],
},
{
"description": "Error: There was an error while hydrating this Suspense boundary. Switched to client rendering.",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": null,
"stack": [],
},
......@@ -736,7 +736,7 @@ describe('Error overlay for hydration errors in Pages 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": "index.js (8:22) @ Mismatch
> 8 | {isClient && <main className="second" />}
| ^",
......@@ -825,14 +825,14 @@ describe('Error overlay for hydration errors in Pages router', () => {
> <p>",
"description": "Expected server HTML to contain a matching <p> in <p>.",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": null,
"stack": [],
},
{
"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": [],
},
......@@ -857,7 +857,7 @@ describe('Error overlay for hydration errors in Pages router', () => {
"description": "In HTML, <p> cannot be a descendant of <p>.
This will cause a hydration error.",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": "index.js (4:7) @ Page
> 4 | <p>Nested p tags</p>
| ^",
......@@ -921,14 +921,14 @@ describe('Error overlay for hydration errors in Pages router', () => {
> <div>",
"description": "Expected server HTML to contain a matching <div> in <p>.",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": null,
"stack": [],
},
{
"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": [],
},
......@@ -953,7 +953,7 @@ describe('Error overlay for hydration errors in Pages router', () => {
"description": "In HTML, <div> cannot be a descendant of <p>.
This will cause a hydration error.",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": "index.js (6:11) @ Page
> 6 | <div>Nested div under p tag</div>
| ^",
......@@ -1005,14 +1005,14 @@ describe('Error overlay for hydration errors in Pages router', () => {
> <tr>",
"description": "Expected server HTML to contain a matching <tr> in <div>.",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": null,
"stack": [],
},
{
"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": [],
},
......@@ -1037,7 +1037,7 @@ describe('Error overlay for hydration errors in Pages router', () => {
"description": "In HTML, <tr> cannot be a child of <div>.
This will cause a hydration error.",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": "index.js (2:15) @ Page
> 2 | return <div><tr></tr></div>
| ^",
......@@ -1099,14 +1099,14 @@ describe('Error overlay for hydration errors in Pages router', () => {
> <p>",
"description": "Expected server HTML to contain a matching <p> in <span>.",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": null,
"stack": [],
},
{
"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": [],
},
......@@ -1135,7 +1135,7 @@ describe('Error overlay for hydration errors in Pages router', () => {
"description": "In HTML, <p> cannot be a descendant of <p>.
This will cause a hydration error.",
"environmentLabel": null,
"label": "Runtime Error",
"label": "Recoverable Error",
"source": "index.js (3:32) @ Page
> 3 | <p><span><span><span><span><p>hello world</p></span></span></span></span></p>
| ^",
......
......@@ -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