From c4cb5226d55d961c58090e8890c9253b6a0b84aa Mon Sep 17 00:00:00 2001 From: eps1lon Date: Wed, 24 Apr 2024 16:39:16 +0200 Subject: [PATCH] Update onCaughtError interceptor Would be nice to do this via onCaughtError but I copying the full impl of `defaultOnCaughtError` seems sketchy. See https://vercel.slack.com/archives/C04TR3U872A/p1713969391445789 for quick proposal --- packages/next/src/client/app-index.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/next/src/client/app-index.tsx b/packages/next/src/client/app-index.tsx index f54d9ac06ca39..43cc320de537a 100644 --- a/packages/next/src/client/app-index.tsx +++ b/packages/next/src/client/app-index.tsx @@ -19,7 +19,8 @@ import { HMR_ACTIONS_SENT_TO_BROWSER } from '../server/dev/hot-reloader-types' // Since React doesn't call onerror for errors caught in error boundaries. const origConsoleError = window.console.error window.console.error = (...args) => { - if (isNextRouterError(args[0])) { + // error is the second argument to `console.error`: https://github.com/facebook/react/blob/d50323eb845c5fde0d720cae888bf35dedd05506/packages/react-reconciler/src/ReactFiberErrorLogger.js#L78 + if (isNextRouterError(args[1])) { return } origConsoleError.apply(window.console, args)