-
Notifications
You must be signed in to change notification settings - Fork 27.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
29 additions
and
35 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
packages/next/src/client/components/globals/intercept-console-error.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,28 @@ | ||
import { isNextRouterError } from '../is-next-router-error' | ||
import { handleClientError } from '../react-dev-overlay/internal/helpers/use-error-handler' | ||
|
||
// Patch console.error to collect information about hydration errors | ||
export function patchConsoleError() { | ||
// Ensure it's only patched once | ||
if (typeof window === 'undefined') { | ||
return | ||
} | ||
|
||
const originConsoleError = window.console.error | ||
window.console.error = (...args) => { | ||
// See https://github.com/facebook/react/blob/d50323eb845c5fde0d720cae888bf35dedd05506/packages/react-reconciler/src/ReactFiberErrorLogger.js#L78 | ||
const error = process.env.NODE_ENV !== 'production' ? args[1] : args[0] | ||
|
||
if (!isNextRouterError(error)) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
const { storeHydrationErrorStateFromConsoleArgs } = | ||
require('../react-dev-overlay/internal/helpers/hydration-error-info') as typeof import('../react-dev-overlay/internal/helpers/hydration-error-info') | ||
|
||
storeHydrationErrorStateFromConsoleArgs(...args) | ||
handleClientError(error) | ||
} | ||
|
||
originConsoleError.apply(window.console, args) | ||
} | ||
} | ||
} |
36 changes: 1 addition & 35 deletions
36
packages/next/src/client/components/globals/patch-console.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 |
---|---|---|
@@ -1,37 +1,3 @@ | ||
import { isNextRouterError } from '../is-next-router-error' | ||
import { handleClientError } from '../react-dev-overlay/internal/helpers/use-error-handler' | ||
|
||
const isReactOwnerStackEnabled = !!process.env.__NEXT_REACT_OWNER_STACK | ||
|
||
// Patch console.error to collect information about hydration errors | ||
function patchConsoleError() { | ||
// Ensure it's only patched once | ||
if (typeof window === 'undefined') { | ||
return | ||
} | ||
|
||
const originConsoleError = window.console.error | ||
window.console.error = (...args) => { | ||
// See https://github.com/facebook/react/blob/d50323eb845c5fde0d720cae888bf35dedd05506/packages/react-reconciler/src/ReactFiberErrorLogger.js#L78 | ||
const error = | ||
process.env.NODE_ENV !== 'production' | ||
? isReactOwnerStackEnabled | ||
? args[1] || args[0] | ||
: args[1] | ||
: args[0] | ||
|
||
if (!isNextRouterError(error)) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
const { storeHydrationErrorStateFromConsoleArgs } = | ||
require('../react-dev-overlay/internal/helpers/hydration-error-info') as typeof import('../react-dev-overlay/internal/helpers/hydration-error-info') | ||
|
||
storeHydrationErrorStateFromConsoleArgs(...args) | ||
handleClientError(error) | ||
} | ||
|
||
originConsoleError.apply(window.console, args) | ||
} | ||
} | ||
} | ||
import { patchConsoleError } from './intercept-console-error' | ||
|
||
patchConsoleError() |