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

[dev-overlay] Isolate overlay from user space Components (#76277)

parent 22c8bd1a
...@@ -5,7 +5,6 @@ import { RuntimeErrorHandler } from '../../errors/runtime-error-handler' ...@@ -5,7 +5,6 @@ import { RuntimeErrorHandler } from '../../errors/runtime-error-handler'
type AppDevOverlayErrorBoundaryProps = { type AppDevOverlayErrorBoundaryProps = {
children: React.ReactNode children: React.ReactNode
devOverlay: React.ReactNode
globalError: [GlobalErrorComponent, React.ReactNode] globalError: [GlobalErrorComponent, React.ReactNode]
onError: (value: boolean) => void onError: (value: boolean) => void
} }
...@@ -62,18 +61,13 @@ export class AppDevOverlayErrorBoundary extends PureComponent< ...@@ -62,18 +61,13 @@ export class AppDevOverlayErrorBoundary extends PureComponent<
} }
render() { render() {
const { children, globalError, devOverlay } = this.props const { children, globalError } = this.props
const { isReactError, reactError } = this.state const { isReactError, reactError } = this.state
const fallback = ( const fallback = (
<ErroredHtml globalError={globalError} error={reactError} /> <ErroredHtml globalError={globalError} error={reactError} />
) )
return ( return isReactError ? fallback : children
<>
{isReactError ? fallback : children}
{devOverlay}
</>
)
} }
} }
...@@ -16,8 +16,16 @@ export function AppDevOverlay({ ...@@ -16,8 +16,16 @@ export function AppDevOverlay({
children: React.ReactNode children: React.ReactNode
}) { }) {
const [isErrorOverlayOpen, setIsErrorOverlayOpen] = useState(false) const [isErrorOverlayOpen, setIsErrorOverlayOpen] = useState(false)
const devOverlay = (
return (
<> <>
<AppDevOverlayErrorBoundary
globalError={globalError}
onError={setIsErrorOverlayOpen}
>
{children}
</AppDevOverlayErrorBoundary>
{/* Fonts can only be loaded outside the Shadow DOM. */} {/* Fonts can only be loaded outside the Shadow DOM. */}
<FontStyles /> <FontStyles />
<DevOverlay <DevOverlay
...@@ -27,14 +35,4 @@ export function AppDevOverlay({ ...@@ -27,14 +35,4 @@ export function AppDevOverlay({
/> />
</> </>
) )
return (
<AppDevOverlayErrorBoundary
devOverlay={devOverlay}
globalError={globalError}
onError={setIsErrorOverlayOpen}
>
{children}
</AppDevOverlayErrorBoundary>
)
} }
import type { OverlayState } from '../../../../shared' import type { OverlayState } from '../../../../shared'
import { Suspense } from 'react'
import { BuildError } from '../../../container/build-error' import { BuildError } from '../../../container/build-error'
import { Errors } from '../../../container/errors' import { Errors } from '../../../container/errors'
import { RootLayoutMissingTagsError } from '../../../container/root-layout-missing-tags-error' import { RootLayoutMissingTagsError } from '../../../container/root-layout-missing-tags-error'
...@@ -64,11 +65,15 @@ export function ErrorOverlay({ ...@@ -64,11 +65,15 @@ export function ErrorOverlay({
// No Runtime Errors. // No Runtime Errors.
if (!runtimeErrors.length) { if (!runtimeErrors.length) {
return null // Workaround React quirk that triggers "Switch to client-side rendering" if
// we return no Suspense boundary here.
return <Suspense />
} }
if (!mounted) { if (!mounted) {
return null // Workaround React quirk that triggers "Switch to client-side rendering" if
// we return no Suspense boundary here.
return <Suspense />
} }
return ( return (
......
...@@ -216,7 +216,7 @@ describe('Error overlay for hydration errors in App router', () => { ...@@ -216,7 +216,7 @@ describe('Error overlay for hydration errors in App router', () => {
"... "...
<HotReload assetPrefix="" globalError={[...]}> <HotReload assetPrefix="" globalError={[...]}>
<AppDevOverlay state={{nextId:1, ...}} globalError={[...]}> <AppDevOverlay state={{nextId:1, ...}} globalError={[...]}>
<AppDevOverlayErrorBoundary devOverlay={<Fragment>} globalError={[...]} onError={function bound dispatchSetState}> <AppDevOverlayErrorBoundary globalError={[...]} onError={function bound dispatchSetState}>
<DevRootHTTPAccessFallbackBoundary> <DevRootHTTPAccessFallbackBoundary>
<HTTPAccessFallbackBoundary notFound={<NotAllowedRootHTTPFallbackError>}> <HTTPAccessFallbackBoundary notFound={<NotAllowedRootHTTPFallbackError>}>
<HTTPAccessFallbackErrorBoundary pathname="/" notFound={<NotAllowedRootHTTPFallbackError>} ...> <HTTPAccessFallbackErrorBoundary pathname="/" notFound={<NotAllowedRootHTTPFallbackError>} ...>
...@@ -239,7 +239,7 @@ describe('Error overlay for hydration errors in App router', () => { ...@@ -239,7 +239,7 @@ describe('Error overlay for hydration errors in App router', () => {
"... "...
<HotReload assetPrefix="" globalError={[...]}> <HotReload assetPrefix="" globalError={[...]}>
<AppDevOverlay state={{nextId:1, ...}} globalError={[...]}> <AppDevOverlay state={{nextId:1, ...}} globalError={[...]}>
<AppDevOverlayErrorBoundary devOverlay={<Fragment>} globalError={[...]} onError={function bound dispatchSetState}> <AppDevOverlayErrorBoundary globalError={[...]} onError={function bound dispatchSetState}>
<DevRootHTTPAccessFallbackBoundary> <DevRootHTTPAccessFallbackBoundary>
<HTTPAccessFallbackBoundary notFound={<NotAllowedRootHTTPFallbackError>}> <HTTPAccessFallbackBoundary notFound={<NotAllowedRootHTTPFallbackError>}>
<HTTPAccessFallbackErrorBoundary pathname="/" notFound={<NotAllowedRootHTTPFallbackError>} ...> <HTTPAccessFallbackErrorBoundary pathname="/" notFound={<NotAllowedRootHTTPFallbackError>} ...>
......
...@@ -216,10 +216,9 @@ describe('app-dir - server source maps', () => { ...@@ -216,10 +216,9 @@ describe('app-dir - server source maps', () => {
) )
expect(cliOutput).toMatch(/digest: '\d+'/) expect(cliOutput).toMatch(/digest: '\d+'/)
// TODO(veil): Should be a single error
await expect(browser).toDisplayRedbox(` await expect(browser).toDisplayRedbox(`
{ {
"count": 2, "count": 1,
"description": "Error: Boom", "description": "Error: Boom",
"environmentLabel": null, "environmentLabel": null,
"label": "Unhandled Runtime Error", "label": "Unhandled Runtime Error",
......
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