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