.
This commit is contained in:
Generated
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
import type { ErrorInfo } from 'react';
|
||||
export declare function onCaughtError(thrownValue: unknown, errorInfo: ErrorInfo & {
|
||||
errorBoundary?: React.Component;
|
||||
}): void;
|
||||
export declare function onUncaughtError(thrownValue: unknown): void;
|
||||
+98
@@ -0,0 +1,98 @@
|
||||
// This file is only used in app router due to the specific error state handling.
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
0 && (module.exports = {
|
||||
onCaughtError: null,
|
||||
onUncaughtError: null
|
||||
});
|
||||
function _export(target, all) {
|
||||
for(var name in all)Object.defineProperty(target, name, {
|
||||
enumerable: true,
|
||||
get: all[name]
|
||||
});
|
||||
}
|
||||
_export(exports, {
|
||||
onCaughtError: function() {
|
||||
return onCaughtError;
|
||||
},
|
||||
onUncaughtError: function() {
|
||||
return onUncaughtError;
|
||||
}
|
||||
});
|
||||
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
||||
const _isnextroutererror = require("../components/is-next-router-error");
|
||||
const _bailouttocsr = require("../../shared/lib/lazy-dynamic/bailout-to-csr");
|
||||
const _reportglobalerror = require("./report-global-error");
|
||||
const _errorboundary = require("../components/error-boundary");
|
||||
const _globalerror = /*#__PURE__*/ _interop_require_default._(require("../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)
|
||||
};
|
||||
function onCaughtError(thrownValue, errorInfo) {
|
||||
const errorBoundaryComponent = 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 === _errorboundary.ErrorBoundaryHandler && errorInfo.errorBoundary.props.errorComponent === _globalerror.default;
|
||||
// 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 ((0, _bailouttocsr.isBailoutToCSRError)(thrownValue) || (0, _isnextroutererror.isNextRouterError)(thrownValue)) return;
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
const errorBoundaryName = // read react component displayName
|
||||
errorBoundaryComponent?.displayName || errorBoundaryComponent?.name || 'Unknown';
|
||||
const componentThatErroredFrame = errorInfo?.componentStack?.split('\n')[1];
|
||||
// Match chrome or safari stack trace
|
||||
const matches = // 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(/\s+at (\w+)\s+|(\w+)@/) ?? [];
|
||||
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);
|
||||
}
|
||||
}
|
||||
function onUncaughtError(thrownValue) {
|
||||
// Skip certain custom errors which are not expected to be reported on client
|
||||
if ((0, _bailouttocsr.isBailoutToCSRError)(thrownValue) || (0, _isnextroutererror.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.
|
||||
(0, _reportglobalerror.reportGlobalError)(error);
|
||||
} else {
|
||||
(0, _reportglobalerror.reportGlobalError)(thrownValue);
|
||||
}
|
||||
}
|
||||
|
||||
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
|
||||
Object.defineProperty(exports.default, '__esModule', { value: true });
|
||||
Object.assign(exports.default, exports);
|
||||
module.exports = exports.default;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=error-boundary-callbacks.js.map
|
||||
Generated
Vendored
+1
File diff suppressed because one or more lines are too long
+3
@@ -0,0 +1,3 @@
|
||||
import type { HydrationOptions } from 'react-dom/client';
|
||||
export declare function isRecoverableError(error: Error): boolean;
|
||||
export declare const onRecoverableError: HydrationOptions['onRecoverableError'];
|
||||
+66
@@ -0,0 +1,66 @@
|
||||
// This module can be shared between both pages router and app router
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
0 && (module.exports = {
|
||||
isRecoverableError: null,
|
||||
onRecoverableError: null
|
||||
});
|
||||
function _export(target, all) {
|
||||
for(var name in all)Object.defineProperty(target, name, {
|
||||
enumerable: true,
|
||||
get: all[name]
|
||||
});
|
||||
}
|
||||
_export(exports, {
|
||||
isRecoverableError: function() {
|
||||
return isRecoverableError;
|
||||
},
|
||||
onRecoverableError: function() {
|
||||
return onRecoverableError;
|
||||
}
|
||||
});
|
||||
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
||||
const _bailouttocsr = require("../../shared/lib/lazy-dynamic/bailout-to-csr");
|
||||
const _iserror = /*#__PURE__*/ _interop_require_default._(require("../../lib/is-error"));
|
||||
const _reportglobalerror = require("./report-global-error");
|
||||
const recoverableErrors = new WeakSet();
|
||||
const isInstantTest = process.env.__NEXT_EXPOSE_TESTING_API && typeof self !== 'undefined' && !!self.__next_instant_test;
|
||||
function isRecoverableError(error) {
|
||||
return recoverableErrors.has(error);
|
||||
}
|
||||
const onRecoverableError = (error)=>{
|
||||
// x-ref: https://github.com/facebook/react/pull/28736
|
||||
let cause = (0, _iserror.default)(error) && 'cause' in error ? error.cause : error;
|
||||
// Skip certain custom errors which are not expected to be reported on client
|
||||
if ((0, _bailouttocsr.isBailoutToCSRError)(cause)) return;
|
||||
// Instant Navigation Testing API: suppress "server could not finish this
|
||||
// Suspense boundary" errors (React error #419) during instant test mode.
|
||||
// The static shell intentionally has incomplete Suspense boundaries — React
|
||||
// correctly falls back to client rendering, which is expected.
|
||||
if (isInstantTest) {
|
||||
if ((0, _iserror.default)(cause)) {
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
if (cause.message.includes('#419')) return;
|
||||
} else {
|
||||
if (cause.message.includes('could not finish this Suspense boundary')) 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;
|
||||
}
|
||||
(0, _reportglobalerror.reportGlobalError)(cause);
|
||||
};
|
||||
|
||||
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
|
||||
Object.defineProperty(exports.default, '__esModule', { value: true });
|
||||
Object.assign(exports.default, exports);
|
||||
module.exports = exports.default;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=on-recoverable-error.js.map
|
||||
+1
@@ -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\nconst isInstantTest =\n process.env.__NEXT_EXPOSE_TESTING_API &&\n typeof self !== 'undefined' &&\n !!self.__next_instant_test\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 // Instant Navigation Testing API: suppress \"server could not finish this\n // Suspense boundary\" errors (React error #419) during instant test mode.\n // The static shell intentionally has incomplete Suspense boundaries — React\n // correctly falls back to client rendering, which is expected.\n if (isInstantTest) {\n if (isError(cause)) {\n if (process.env.NODE_ENV === 'production') {\n if (cause.message.includes('#419')) return\n } else {\n if (cause.message.includes('could not finish this Suspense boundary'))\n return\n }\n }\n }\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":["isRecoverableError","onRecoverableError","recoverableErrors","WeakSet","isInstantTest","process","env","__NEXT_EXPOSE_TESTING_API","self","__next_instant_test","error","has","cause","isError","isBailoutToCSRError","NODE_ENV","message","includes","decorateDevError","require","causeError","add","reportGlobalError"],"mappings":"AAAA,qEAAqE;;;;;;;;;;;;;;;;IAcrDA,kBAAkB;eAAlBA;;IAIHC,kBAAkB;eAAlBA;;;;8BAfuB;kEAChB;mCACc;AAElC,MAAMC,oBAAoB,IAAIC;AAE9B,MAAMC,gBACJC,QAAQC,GAAG,CAACC,yBAAyB,IACrC,OAAOC,SAAS,eAChB,CAAC,CAACA,KAAKC,mBAAmB;AAErB,SAAST,mBAAmBU,KAAY;IAC7C,OAAOR,kBAAkBS,GAAG,CAACD;AAC/B;AAEO,MAAMT,qBAA6D,CACxES;IAEA,sDAAsD;IACtD,IAAIE,QAAQC,IAAAA,gBAAO,EAACH,UAAU,WAAWA,QAAQA,MAAME,KAAK,GAAGF;IAC/D,6EAA6E;IAC7E,IAAII,IAAAA,iCAAmB,EAACF,QAAQ;IAEhC,yEAAyE;IACzE,yEAAyE;IACzE,4EAA4E;IAC5E,+DAA+D;IAC/D,IAAIR,eAAe;QACjB,IAAIS,IAAAA,gBAAO,EAACD,QAAQ;YAClB,IAAIP,QAAQC,GAAG,CAACS,QAAQ,KAAK,cAAc;gBACzC,IAAIH,MAAMI,OAAO,CAACC,QAAQ,CAAC,SAAS;YACtC,OAAO;gBACL,IAAIL,MAAMI,OAAO,CAACC,QAAQ,CAAC,4CACzB;YACJ;QACF;IACF;IAEA,IAAIZ,QAAQC,GAAG,CAACS,QAAQ,KAAK,cAAc;QACzC,MAAM,EAAEG,gBAAgB,EAAE,GACxBC,QAAQ;QACV,MAAMC,aAAaF,iBAAiBN;QACpCV,kBAAkBmB,GAAG,CAACD;QACtBR,QAAQQ;IACV;IAEAE,IAAAA,oCAAiB,EAACV;AACpB","ignoreList":[0]}
|
||||
+1
@@ -0,0 +1 @@
|
||||
export declare const reportGlobalError: (error: unknown) => void;
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "reportGlobalError", {
|
||||
enumerable: true,
|
||||
get: function() {
|
||||
return reportGlobalError;
|
||||
}
|
||||
});
|
||||
const reportGlobalError = typeof reportError === 'function' ? // emulating an uncaught JavaScript error.
|
||||
reportError : (error)=>{
|
||||
// TODO: Dispatch error event
|
||||
globalThis.console.error(error);
|
||||
};
|
||||
|
||||
if ((typeof exports.default === 'function' || (typeof exports.default === 'object' && exports.default !== null)) && typeof exports.default.__esModule === 'undefined') {
|
||||
Object.defineProperty(exports.default, '__esModule', { value: true });
|
||||
Object.assign(exports.default, exports);
|
||||
module.exports = exports.default;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=report-global-error.js.map
|
||||
+1
@@ -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":";;;;+BAAaA;;;eAAAA;;;AAAN,MAAMA,oBACX,OAAOC,gBAAgB,aAEnB,0CAA0C;AAC1CA,cACA,CAACC;IACC,6BAA6B;IAC7BC,WAAWC,OAAO,CAACF,KAAK,CAACA;AAC3B","ignoreList":[0]}
|
||||
Reference in New Issue
Block a user