Initial commit

This commit is contained in:
bilulib
2025-04-13 00:18:57 +02:00
parent cff009bb7c
commit d894249e61
18301 changed files with 2905442 additions and 3845 deletions

View File

@@ -0,0 +1,5 @@
import type { ErrorInfo } from 'react';
export declare function onCaughtError(err: unknown, errorInfo: ErrorInfo & {
errorBoundary?: React.Component;
}): void;
export declare function onUncaughtError(err: unknown, errorInfo: React.ErrorInfo): void;

View File

@@ -0,0 +1,102 @@
// 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 _stitchederror = require("../components/errors/stitched-error");
const _useerrorhandler = require("../components/errors/use-error-handler");
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 _interceptconsoleerror = require("../components/globals/intercept-console-error");
const _errorboundary = require("../components/error-boundary");
function onCaughtError(err, 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('../components/react-dev-overlay/app/app-dev-overlay-error-boundary');
isImplicitErrorBoundary = errorBoundaryComponent === AppDevOverlayErrorBoundary;
}
isImplicitErrorBoundary = isImplicitErrorBoundary || errorBoundaryComponent === _errorboundary.ErrorBoundaryHandler && errorInfo.errorBoundary.props.errorComponent === _errorboundary.GlobalError;
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(err, errorInfo);
}
// Skip certain custom errors which are not expected to be reported on client
if ((0, _bailouttocsr.isBailoutToCSRError)(err) || (0, _isnextroutererror.isNextRouterError)(err)) 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 stitchedError = (0, _stitchederror.getReactStitchedError)(err);
// TODO: change to passing down errorInfo later
// In development mode, pass along the component stack to the error
if (errorInfo.componentStack) {
;
stitchedError._componentStack = errorInfo.componentStack;
}
// Log and report the error with location but without modifying the error stack
(0, _interceptconsoleerror.originConsoleError)('%o\n\n%s', err, errorLocation);
(0, _useerrorhandler.handleClientError)(stitchedError);
} else {
(0, _interceptconsoleerror.originConsoleError)(err);
}
}
function onUncaughtError(err, errorInfo) {
// Skip certain custom errors which are not expected to be reported on client
if ((0, _bailouttocsr.isBailoutToCSRError)(err) || (0, _isnextroutererror.isNextRouterError)(err)) return;
if (process.env.NODE_ENV !== 'production') {
const stitchedError = (0, _stitchederror.getReactStitchedError)(err);
// TODO: change to passing down errorInfo later
// In development mode, pass along the component stack to the error
if (errorInfo.componentStack) {
;
stitchedError._componentStack = errorInfo.componentStack;
}
// TODO: Add an adendum to the overlay telling people about custom error boundaries.
(0, _reportglobalerror.reportGlobalError)(stitchedError);
} else {
(0, _reportglobalerror.reportGlobalError)(err);
}
}
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

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,2 @@
import type { HydrationOptions } from 'react-dom/client';
export declare const onRecoverableError: HydrationOptions['onRecoverableError'];

View File

@@ -0,0 +1,37 @@
// This module can be shared between both pages router and app router
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "onRecoverableError", {
enumerable: true,
get: function() {
return onRecoverableError;
}
});
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
const _bailouttocsr = require("../../shared/lib/lazy-dynamic/bailout-to-csr");
const _reportglobalerror = require("./report-global-error");
const _stitchederror = require("../components/errors/stitched-error");
const _iserror = /*#__PURE__*/ _interop_require_default._(require("../../lib/is-error"));
const onRecoverableError = (error, errorInfo)=>{
// x-ref: https://github.com/facebook/react/pull/28736
const cause = (0, _iserror.default)(error) && 'cause' in error ? error.cause : error;
const stitchedError = (0, _stitchederror.getReactStitchedError)(cause);
// In development mode, pass along the component stack to the error
if (process.env.NODE_ENV === 'development' && errorInfo.componentStack) {
;
stitchedError._componentStack = errorInfo.componentStack;
}
// Skip certain custom errors which are not expected to be reported on client
if ((0, _bailouttocsr.isBailoutToCSRError)(cause)) return;
(0, _reportglobalerror.reportGlobalError)(stitchedError);
};
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

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 { reportGlobalError } from './report-global-error'\nimport { getReactStitchedError } from '../components/errors/stitched-error'\nimport isError from '../../lib/is-error'\n\nexport const onRecoverableError: HydrationOptions['onRecoverableError'] = (\n error,\n errorInfo\n) => {\n // x-ref: https://github.com/facebook/react/pull/28736\n const cause = isError(error) && 'cause' in error ? error.cause : error\n const stitchedError = getReactStitchedError(cause)\n // In development mode, pass along the component stack to the error\n if (process.env.NODE_ENV === 'development' && errorInfo.componentStack) {\n ;(stitchedError as any)._componentStack = errorInfo.componentStack\n }\n // Skip certain custom errors which are not expected to be reported on client\n if (isBailoutToCSRError(cause)) return\n\n reportGlobalError(stitchedError)\n}\n"],"names":["onRecoverableError","error","errorInfo","cause","isError","stitchedError","getReactStitchedError","process","env","NODE_ENV","componentStack","_componentStack","isBailoutToCSRError","reportGlobalError"],"mappings":"AAAA,qEAAqE;;;;;+BAQxDA;;;eAAAA;;;;8BALuB;mCACF;+BACI;kEAClB;AAEb,MAAMA,qBAA6D,CACxEC,OACAC;IAEA,sDAAsD;IACtD,MAAMC,QAAQC,IAAAA,gBAAO,EAACH,UAAU,WAAWA,QAAQA,MAAME,KAAK,GAAGF;IACjE,MAAMI,gBAAgBC,IAAAA,oCAAqB,EAACH;IAC5C,mEAAmE;IACnE,IAAII,QAAQC,GAAG,CAACC,QAAQ,KAAK,iBAAiBP,UAAUQ,cAAc,EAAE;;QACpEL,cAAsBM,eAAe,GAAGT,UAAUQ,cAAc;IACpE;IACA,6EAA6E;IAC7E,IAAIE,IAAAA,iCAAmB,EAACT,QAAQ;IAEhCU,IAAAA,oCAAiB,EAACR;AACpB"}

View File

@@ -0,0 +1 @@
export declare const reportGlobalError: (error: unknown) => void;

View File

@@ -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

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":";;;;+BAAaA;;;eAAAA;;;AAAN,MAAMA,oBACX,OAAOC,gBAAgB,aAEnB,0CAA0C;AAC1CA,cACA,CAACC;IACC,6BAA6B;IAC7BC,WAAWC,OAAO,CAACF,KAAK,CAACA;AAC3B"}