This commit is contained in:
2026-04-12 01:02:14 +08:00
parent 509487f155
commit 9b053e302b
14085 changed files with 2680009 additions and 12 deletions

View File

@@ -0,0 +1,72 @@
// This file is only used in app router due to the specific error state handling.
import { isNextRouterError } from '../components/is-next-router-error';
import { isBailoutToCSRError } from '../../shared/lib/lazy-dynamic/bailout-to-csr';
import { reportGlobalError } from './report-global-error';
import { ErrorBoundaryHandler } from '../components/error-boundary';
import DefaultErrorBoundary from '../components/builtin/global-error';
const devToolErrorMod = process.env.NODE_ENV !== 'production' ? require('../../next-devtools/userspace/app/errors') : {
decorateDevError: (error)=>error,
handleClientError: ()=>{},
originConsoleError: console.error.bind(console)
};
export function onCaughtError(thrownValue, errorInfo) {
var _errorInfo_errorBoundary;
const errorBoundaryComponent = (_errorInfo_errorBoundary = errorInfo.errorBoundary) == null ? void 0 : _errorInfo_errorBoundary.constructor;
let isImplicitErrorBoundary;
if (process.env.NODE_ENV !== 'production') {
const { AppDevOverlayErrorBoundary } = require('../../next-devtools/userspace/app/app-dev-overlay-error-boundary');
isImplicitErrorBoundary = errorBoundaryComponent === AppDevOverlayErrorBoundary;
}
isImplicitErrorBoundary = isImplicitErrorBoundary || errorBoundaryComponent === ErrorBoundaryHandler && errorInfo.errorBoundary.props.errorComponent === DefaultErrorBoundary;
// Skip the segment explorer triggered error
if (process.env.NODE_ENV !== 'production') {
const { SEGMENT_EXPLORER_SIMULATED_ERROR_MESSAGE } = require('../../next-devtools/userspace/app/segment-explorer-node');
if (thrownValue instanceof Error && thrownValue.message === SEGMENT_EXPLORER_SIMULATED_ERROR_MESSAGE) {
return;
}
}
if (isImplicitErrorBoundary) {
// We don't consider errors caught unless they're caught by an explicit error
// boundary. The built-in ones are considered implicit.
// This mimics how the same app would behave without Next.js.
return onUncaughtError(thrownValue);
}
// Skip certain custom errors which are not expected to be reported on client
if (isBailoutToCSRError(thrownValue) || isNextRouterError(thrownValue)) return;
if (process.env.NODE_ENV !== 'production') {
var _errorInfo_componentStack;
const errorBoundaryName = (// read react component displayName
errorBoundaryComponent == null ? void 0 : errorBoundaryComponent.displayName) || (errorBoundaryComponent == null ? void 0 : errorBoundaryComponent.name) || 'Unknown';
const componentThatErroredFrame = errorInfo == null ? void 0 : (_errorInfo_componentStack = errorInfo.componentStack) == null ? void 0 : _errorInfo_componentStack.split('\n')[1];
var // regex to match the function name in the stack trace
// example 1: at Page (http://localhost:3000/_next/static/chunks/pages/index.js?ts=1631600000000:2:1)
// example 2: Page@http://localhost:3000/_next/static/chunks/pages/index.js?ts=1631600000000:2:1
_componentThatErroredFrame_match;
// Match chrome or safari stack trace
const matches = (_componentThatErroredFrame_match = componentThatErroredFrame == null ? void 0 : componentThatErroredFrame.match(/\s+at (\w+)\s+|(\w+)@/)) != null ? _componentThatErroredFrame_match : [];
const componentThatErroredName = matches[1] || matches[2] || 'Unknown';
// Create error location with errored component and error boundary, to match the behavior of default React onCaughtError handler.
const errorBoundaryMessage = "It was handled by the <" + errorBoundaryName + "> error boundary.";
const componentErrorMessage = componentThatErroredName ? "The above error occurred in the <" + componentThatErroredName + "> component." : "The above error occurred in one of your components.";
const errorLocation = componentErrorMessage + " " + errorBoundaryMessage;
const error = devToolErrorMod.decorateDevError(thrownValue);
// Log and report the error with location but without modifying the error stack
devToolErrorMod.originConsoleError('%o\n\n%s', thrownValue, errorLocation);
devToolErrorMod.handleClientError(error);
} else {
devToolErrorMod.originConsoleError(thrownValue);
}
}
export function onUncaughtError(thrownValue) {
// Skip certain custom errors which are not expected to be reported on client
if (isBailoutToCSRError(thrownValue) || isNextRouterError(thrownValue)) return;
if (process.env.NODE_ENV !== 'production') {
const error = devToolErrorMod.decorateDevError(thrownValue);
// TODO: Add an adendum to the overlay telling people about custom error boundaries.
reportGlobalError(error);
} else {
reportGlobalError(thrownValue);
}
}
//# sourceMappingURL=error-boundary-callbacks.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,23 @@
// This module can be shared between both pages router and app router
import { isBailoutToCSRError } from '../../shared/lib/lazy-dynamic/bailout-to-csr';
import isError from '../../lib/is-error';
import { reportGlobalError } from './report-global-error';
const recoverableErrors = new WeakSet();
export function isRecoverableError(error) {
return recoverableErrors.has(error);
}
export const onRecoverableError = (error)=>{
// x-ref: https://github.com/facebook/react/pull/28736
let cause = isError(error) && 'cause' in error ? error.cause : error;
// Skip certain custom errors which are not expected to be reported on client
if (isBailoutToCSRError(cause)) return;
if (process.env.NODE_ENV !== 'production') {
const { decorateDevError } = require('../../next-devtools/userspace/app/errors/stitched-error');
const causeError = decorateDevError(cause);
recoverableErrors.add(causeError);
cause = causeError;
}
reportGlobalError(cause);
};
//# sourceMappingURL=on-recoverable-error.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/client/react-client-callbacks/on-recoverable-error.ts"],"sourcesContent":["// This module can be shared between both pages router and app router\n\nimport type { HydrationOptions } from 'react-dom/client'\nimport { isBailoutToCSRError } from '../../shared/lib/lazy-dynamic/bailout-to-csr'\nimport isError from '../../lib/is-error'\nimport { reportGlobalError } from './report-global-error'\n\nconst recoverableErrors = new WeakSet<Error>()\n\nexport function isRecoverableError(error: Error): boolean {\n return recoverableErrors.has(error)\n}\n\nexport const onRecoverableError: HydrationOptions['onRecoverableError'] = (\n error\n) => {\n // x-ref: https://github.com/facebook/react/pull/28736\n let cause = isError(error) && 'cause' in error ? error.cause : error\n // Skip certain custom errors which are not expected to be reported on client\n if (isBailoutToCSRError(cause)) return\n\n if (process.env.NODE_ENV !== 'production') {\n const { decorateDevError } =\n require('../../next-devtools/userspace/app/errors/stitched-error') as typeof import('../../next-devtools/userspace/app/errors/stitched-error')\n const causeError = decorateDevError(cause)\n recoverableErrors.add(causeError)\n cause = causeError\n }\n\n reportGlobalError(cause)\n}\n"],"names":["isBailoutToCSRError","isError","reportGlobalError","recoverableErrors","WeakSet","isRecoverableError","error","has","onRecoverableError","cause","process","env","NODE_ENV","decorateDevError","require","causeError","add"],"mappings":"AAAA,qEAAqE;AAGrE,SAASA,mBAAmB,QAAQ,+CAA8C;AAClF,OAAOC,aAAa,qBAAoB;AACxC,SAASC,iBAAiB,QAAQ,wBAAuB;AAEzD,MAAMC,oBAAoB,IAAIC;AAE9B,OAAO,SAASC,mBAAmBC,KAAY;IAC7C,OAAOH,kBAAkBI,GAAG,CAACD;AAC/B;AAEA,OAAO,MAAME,qBAA6D,CACxEF;IAEA,sDAAsD;IACtD,IAAIG,QAAQR,QAAQK,UAAU,WAAWA,QAAQA,MAAMG,KAAK,GAAGH;IAC/D,6EAA6E;IAC7E,IAAIN,oBAAoBS,QAAQ;IAEhC,IAAIC,QAAQC,GAAG,CAACC,QAAQ,KAAK,cAAc;QACzC,MAAM,EAAEC,gBAAgB,EAAE,GACxBC,QAAQ;QACV,MAAMC,aAAaF,iBAAiBJ;QACpCN,kBAAkBa,GAAG,CAACD;QACtBN,QAAQM;IACV;IAEAb,kBAAkBO;AACpB,EAAC","ignoreList":[0]}

View File

@@ -0,0 +1,7 @@
export const reportGlobalError = typeof reportError === 'function' ? // emulating an uncaught JavaScript error.
reportError : (error)=>{
// TODO: Dispatch error event
globalThis.console.error(error);
};
//# sourceMappingURL=report-global-error.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/client/react-client-callbacks/report-global-error.ts"],"sourcesContent":["export const reportGlobalError =\n typeof reportError === 'function'\n ? // In modern browsers, reportError will dispatch an error event,\n // emulating an uncaught JavaScript error.\n reportError\n : (error: unknown) => {\n // TODO: Dispatch error event\n globalThis.console.error(error)\n }\n"],"names":["reportGlobalError","reportError","error","globalThis","console"],"mappings":"AAAA,OAAO,MAAMA,oBACX,OAAOC,gBAAgB,aAEnB,0CAA0C;AAC1CA,cACA,CAACC;IACC,6BAA6B;IAC7BC,WAAWC,OAAO,CAACF,KAAK,CAACA;AAC3B,EAAC","ignoreList":[0]}