Unverified Commit 10725f84 authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

Allow `reset()` from user's global-error (#89684)

User's `global-error.js` is within the router. There's no reason it
shouldn't have access to the options available to the `error.js`
component. It was already available on prod. This PR syncs dev behavior
to prod.

For the follow-up feature, `retry()` will also be available in
`global-error.js`.

---------
Co-authored-by: 's avatarvercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
parent 4de94897
...@@ -5,6 +5,7 @@ import { errorStyles, errorThemeCss, ErrorIcon } from './error-styles' ...@@ -5,6 +5,7 @@ import { errorStyles, errorThemeCss, ErrorIcon } from './error-styles'
export type GlobalErrorComponent = React.ComponentType<{ export type GlobalErrorComponent = React.ComponentType<{
error: any error: any
reset: () => void
}> }>
function DefaultGlobalError({ error }: { error: any }) { function DefaultGlobalError({ error }: { error: any }) {
......
...@@ -12,9 +12,7 @@ const isBotUserAgent = ...@@ -12,9 +12,7 @@ const isBotUserAgent =
export type ErrorComponent = React.ComponentType<{ export type ErrorComponent = React.ComponentType<{
error: Error error: Error
// global-error, there's no `reset` function; reset: () => void
// regular error boundary, there's a `reset` function.
reset?: () => void
}> }>
export interface ErrorBoundaryProps { export interface ErrorBoundaryProps {
......
...@@ -18,9 +18,11 @@ type AppDevOverlayErrorBoundaryState = { ...@@ -18,9 +18,11 @@ type AppDevOverlayErrorBoundaryState = {
function ErroredHtml({ function ErroredHtml({
globalError: [GlobalError, globalErrorStyles], globalError: [GlobalError, globalErrorStyles],
error, error,
reset,
}: { }: {
globalError: GlobalErrorState globalError: GlobalErrorState
error: unknown error: unknown
reset: () => void
}) { }) {
if (!error) { if (!error) {
return ( return (
...@@ -33,7 +35,7 @@ function ErroredHtml({ ...@@ -33,7 +35,7 @@ function ErroredHtml({
return ( return (
<ErrorBoundary errorComponent={DefaultGlobalError}> <ErrorBoundary errorComponent={DefaultGlobalError}>
{globalErrorStyles} {globalErrorStyles}
<GlobalError error={error} /> <GlobalError error={error} reset={reset} />
</ErrorBoundary> </ErrorBoundary>
) )
} }
...@@ -62,12 +64,20 @@ export class AppDevOverlayErrorBoundary extends PureComponent< ...@@ -62,12 +64,20 @@ export class AppDevOverlayErrorBoundary extends PureComponent<
dispatcher.openErrorOverlay() dispatcher.openErrorOverlay()
} }
reset = () => {
this.setState({ reactError: null })
}
render() { render() {
const { children, globalError } = this.props const { children, globalError } = this.props
const { reactError } = this.state const { reactError } = this.state
const fallback = ( const fallback = (
<ErroredHtml globalError={globalError} error={reactError} /> <ErroredHtml
globalError={globalError}
error={reactError}
reset={this.reset}
/>
) )
return reactError !== null ? fallback : children return reactError !== null ? fallback : children
......
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