Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor error overlay for new router (#41343)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
e0bb258
commit bf630e8
Showing
50 changed files
with
330 additions
and
394 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
packages/next/client/components/react-dev-overlay/client.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { Dispatch, ReducerAction } from 'react' | ||
import type { errorOverlayReducer } from './internal/error-overlay-reducer' | ||
import { | ||
ACTION_BUILD_OK, | ||
ACTION_BUILD_ERROR, | ||
ACTION_REFRESH, | ||
ACTION_UNHANDLED_ERROR, | ||
ACTION_UNHANDLED_REJECTION, | ||
} from './internal/error-overlay-reducer' | ||
import { parseStack } from './internal/helpers/parseStack' | ||
|
||
export type DispatchFn = Dispatch<ReducerAction<typeof errorOverlayReducer>> | ||
|
||
export function onUnhandledError(dispatch: DispatchFn, ev: ErrorEvent) { | ||
const error = ev?.error | ||
if (!error || !(error instanceof Error) || typeof error.stack !== 'string') { | ||
// A non-error was thrown, we don't have anything to show. :-( | ||
return | ||
} | ||
|
||
if ( | ||
error.message.match(/(hydration|content does not match|did not match)/i) | ||
) { | ||
error.message += `\n\nSee more info here: https://nextjs.org/docs/messages/react-hydration-error` | ||
} | ||
|
||
const e = error | ||
dispatch({ | ||
type: ACTION_UNHANDLED_ERROR, | ||
reason: error, | ||
frames: parseStack(e.stack!), | ||
}) | ||
} | ||
|
||
export function onUnhandledRejection( | ||
dispatch: DispatchFn, | ||
ev: PromiseRejectionEvent | ||
) { | ||
const reason = ev?.reason | ||
if ( | ||
!reason || | ||
!(reason instanceof Error) || | ||
typeof reason.stack !== 'string' | ||
) { | ||
// A non-error was thrown, we don't have anything to show. :-( | ||
return | ||
} | ||
|
||
const e = reason | ||
dispatch({ | ||
type: ACTION_UNHANDLED_REJECTION, | ||
reason: reason, | ||
frames: parseStack(e.stack!), | ||
}) | ||
} | ||
|
||
export function onBuildOk(dispatch: DispatchFn) { | ||
dispatch({ type: ACTION_BUILD_OK }) | ||
} | ||
|
||
export function onBuildError(dispatch: DispatchFn, message: string) { | ||
dispatch({ type: ACTION_BUILD_ERROR, message }) | ||
} | ||
|
||
export function onRefresh(dispatch: DispatchFn) { | ||
dispatch({ type: ACTION_REFRESH }) | ||
} | ||
|
||
export { getErrorByType } from './internal/helpers/getErrorByType' | ||
export { getServerError } from './internal/helpers/nodeStackFrames' | ||
export { default as ReactDevOverlay } from './internal/ReactDevOverlay' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.