added fonts

This commit is contained in:
guus committed 2025-07-02 11:28:41 +02:00
1 parent 4134e3a234
commit 142d2986b6
9079 files changed
+1498421 -2

No files matched your search

@@ -0,0 +1 @@
export declare function attachHydrationErrorState(error: Error): void;
@@ -0,0 +1,84 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "attachHydrationErrorState", {
enumerable: true,
get: function() {
return attachHydrationErrorState;
}
});
const _ishydrationerror = require("../is-hydration-error");
const _hydrationerrorinfo = require("./hydration-error-info");
function attachHydrationErrorState(error) {
let parsedHydrationErrorState = {};
const isHydrationWarning = (0, _ishydrationerror.testReactHydrationWarning)(error.message);
const isHydrationRuntimeError = (0, _ishydrationerror.isHydrationError)(error);
// If it's not hydration warnings or errors, skip
if (!(isHydrationRuntimeError || isHydrationWarning)) {
return;
}
const reactHydrationDiffSegments = (0, _hydrationerrorinfo.getReactHydrationDiffSegments)(error.message);
// If the reactHydrationDiffSegments exists
// and the diff (reactHydrationDiffSegments[1]) exists
// e.g. the hydration diff log error.
if (reactHydrationDiffSegments) {
const diff = reactHydrationDiffSegments[1];
parsedHydrationErrorState = {
...error.details,
..._hydrationerrorinfo.hydrationErrorState,
// If diff is present in error, we don't need to pick up the console logged warning.
// - if hydration error has diff, and is not hydration diff log, then it's a normal hydration error.
// - if hydration error no diff, then leverage the one from the hydration diff log.
warning: (diff && !isHydrationWarning ? null : _hydrationerrorinfo.hydrationErrorState.warning) || [
(0, _ishydrationerror.getDefaultHydrationErrorMessage)(),
'',
''
],
// When it's hydration diff log, do not show notes section.
// This condition is only for the 1st squashed error.
notes: isHydrationWarning ? '' : reactHydrationDiffSegments[0],
reactOutputComponentDiff: diff
};
// Cache the `reactOutputComponentDiff` into hydrationErrorState.
// This is only required for now when we still squashed the hydration diff log into hydration error.
// Once the all error is logged to dev overlay in order, this will go away.
if (!_hydrationerrorinfo.hydrationErrorState.reactOutputComponentDiff && diff) {
_hydrationerrorinfo.hydrationErrorState.reactOutputComponentDiff = diff;
}
// If it's hydration runtime error that doesn't contain the diff, combine the diff from the cached hydration diff.
if (!diff && isHydrationRuntimeError && _hydrationerrorinfo.hydrationErrorState.reactOutputComponentDiff) {
parsedHydrationErrorState.reactOutputComponentDiff = _hydrationerrorinfo.hydrationErrorState.reactOutputComponentDiff;
}
} else {
// Normal runtime error, where it doesn't contain the hydration diff.
// If there's any extra information in the error message to display,
// append it to the error message details property
if (_hydrationerrorinfo.hydrationErrorState.warning) {
// The patched console.error found hydration errors logged by React
// Append the logged warning to the error message
parsedHydrationErrorState = {
...error.details,
// It contains the warning, component stack, server and client tag names
..._hydrationerrorinfo.hydrationErrorState
};
}
// Consume the cached hydration diff.
// This is only required for now when we still squashed the hydration diff log into hydration error.
// Once the all error is logged to dev overlay in order, this will go away.
if (_hydrationerrorinfo.hydrationErrorState.reactOutputComponentDiff) {
parsedHydrationErrorState.reactOutputComponentDiff = _hydrationerrorinfo.hydrationErrorState.reactOutputComponentDiff;
}
}
// If it's a hydration error, store the hydration error state into the error object
;
error.details = parsedHydrationErrorState;
}
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=attach-hydration-error-state.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/client/components/errors/attach-hydration-error-state.ts"],"sourcesContent":["import {\n getDefaultHydrationErrorMessage,\n isHydrationError,\n testReactHydrationWarning,\n} from '../is-hydration-error'\nimport {\n hydrationErrorState,\n getReactHydrationDiffSegments,\n type HydrationErrorState,\n} from './hydration-error-info'\n\nexport function attachHydrationErrorState(error: Error) {\n let parsedHydrationErrorState: typeof hydrationErrorState = {}\n const isHydrationWarning = testReactHydrationWarning(error.message)\n const isHydrationRuntimeError = isHydrationError(error)\n\n // If it's not hydration warnings or errors, skip\n if (!(isHydrationRuntimeError || isHydrationWarning)) {\n return\n }\n\n const reactHydrationDiffSegments = getReactHydrationDiffSegments(\n error.message\n )\n // If the reactHydrationDiffSegments exists\n // and the diff (reactHydrationDiffSegments[1]) exists\n // e.g. the hydration diff log error.\n if (reactHydrationDiffSegments) {\n const diff = reactHydrationDiffSegments[1]\n parsedHydrationErrorState = {\n ...((error as any).details as HydrationErrorState),\n ...hydrationErrorState,\n // If diff is present in error, we don't need to pick up the console logged warning.\n // - if hydration error has diff, and is not hydration diff log, then it's a normal hydration error.\n // - if hydration error no diff, then leverage the one from the hydration diff log.\n\n warning: (diff && !isHydrationWarning\n ? null\n : hydrationErrorState.warning) || [\n getDefaultHydrationErrorMessage(),\n '',\n '',\n ],\n // When it's hydration diff log, do not show notes section.\n // This condition is only for the 1st squashed error.\n notes: isHydrationWarning ? '' : reactHydrationDiffSegments[0],\n reactOutputComponentDiff: diff,\n }\n // Cache the `reactOutputComponentDiff` into hydrationErrorState.\n // This is only required for now when we still squashed the hydration diff log into hydration error.\n // Once the all error is logged to dev overlay in order, this will go away.\n if (!hydrationErrorState.reactOutputComponentDiff && diff) {\n hydrationErrorState.reactOutputComponentDiff = diff\n }\n // If it's hydration runtime error that doesn't contain the diff, combine the diff from the cached hydration diff.\n if (\n !diff &&\n isHydrationRuntimeError &&\n hydrationErrorState.reactOutputComponentDiff\n ) {\n parsedHydrationErrorState.reactOutputComponentDiff =\n hydrationErrorState.reactOutputComponentDiff\n }\n } else {\n // Normal runtime error, where it doesn't contain the hydration diff.\n\n // If there's any extra information in the error message to display,\n // append it to the error message details property\n if (hydrationErrorState.warning) {\n // The patched console.error found hydration errors logged by React\n // Append the logged warning to the error message\n parsedHydrationErrorState = {\n ...(error as any).details,\n // It contains the warning, component stack, server and client tag names\n ...hydrationErrorState,\n }\n }\n // Consume the cached hydration diff.\n // This is only required for now when we still squashed the hydration diff log into hydration error.\n // Once the all error is logged to dev overlay in order, this will go away.\n if (hydrationErrorState.reactOutputComponentDiff) {\n parsedHydrationErrorState.reactOutputComponentDiff =\n hydrationErrorState.reactOutputComponentDiff\n }\n }\n // If it's a hydration error, store the hydration error state into the error object\n ;(error as any).details = parsedHydrationErrorState\n}\n"],"names":["attachHydrationErrorState","error","parsedHydrationErrorState","isHydrationWarning","testReactHydrationWarning","message","isHydrationRuntimeError","isHydrationError","reactHydrationDiffSegments","getReactHydrationDiffSegments","diff","details","hydrationErrorState","warning","getDefaultHydrationErrorMessage","notes","reactOutputComponentDiff"],"mappings":";;;;+BAWgBA;;;eAAAA;;;kCAPT;oCAKA;AAEA,SAASA,0BAA0BC,KAAY;IACpD,IAAIC,4BAAwD,CAAC;IAC7D,MAAMC,qBAAqBC,IAAAA,2CAAyB,EAACH,MAAMI,OAAO;IAClE,MAAMC,0BAA0BC,IAAAA,kCAAgB,EAACN;IAEjD,iDAAiD;IACjD,IAAI,CAAEK,CAAAA,2BAA2BH,kBAAiB,GAAI;QACpD;IACF;IAEA,MAAMK,6BAA6BC,IAAAA,iDAA6B,EAC9DR,MAAMI,OAAO;IAEf,2CAA2C;IAC3C,sDAAsD;IACtD,qCAAqC;IACrC,IAAIG,4BAA4B;QAC9B,MAAME,OAAOF,0BAA0B,CAAC,EAAE;QAC1CN,4BAA4B;YAC1B,GAAI,AAACD,MAAcU,OAAO;YAC1B,GAAGC,uCAAmB;YACtB,oFAAoF;YACpF,oGAAoG;YACpG,mFAAmF;YAEnFC,SAAS,AAACH,CAAAA,QAAQ,CAACP,qBACf,OACAS,uCAAmB,CAACC,OAAO,AAAD,KAAM;gBAClCC,IAAAA,iDAA+B;gBAC/B;gBACA;aACD;YACD,2DAA2D;YAC3D,qDAAqD;YACrDC,OAAOZ,qBAAqB,KAAKK,0BAA0B,CAAC,EAAE;YAC9DQ,0BAA0BN;QAC5B;QACA,iEAAiE;QACjE,oGAAoG;QACpG,2EAA2E;QAC3E,IAAI,CAACE,uCAAmB,CAACI,wBAAwB,IAAIN,MAAM;YACzDE,uCAAmLine truncated
+11
View File
@@ -0,0 +1,11 @@
declare const digestSym: unique symbol;
declare const consoleTypeSym: unique symbol;
export type ConsoleError = Error & {
[digestSym]: 'NEXT_CONSOLE_ERROR';
[consoleTypeSym]: 'string' | 'error';
environmentName: string;
};
export declare function createConsoleError(message: string | Error, environmentName?: string | null): ConsoleError;
export declare const isConsoleError: (error: any) => error is ConsoleError;
export declare const getConsoleErrorType: (error: ConsoleError) => "string" | "error";
export {};
+56
View File
@@ -0,0 +1,56 @@
// To distinguish from React error.digest, we use a different symbol here to determine if the error is from console.error or unhandled promise rejection.
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
createConsoleError: null,
getConsoleErrorType: null,
isConsoleError: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
createConsoleError: function() {
return createConsoleError;
},
getConsoleErrorType: function() {
return getConsoleErrorType;
},
isConsoleError: function() {
return isConsoleError;
}
});
const digestSym = Symbol.for('next.console.error.digest');
const consoleTypeSym = Symbol.for('next.console.error.type');
function createConsoleError(message, environmentName) {
const error = typeof message === 'string' ? Object.defineProperty(new Error(message), "__NEXT_ERROR_CODE", {
value: "E394",
enumerable: false,
configurable: true
}) : message;
error[digestSym] = 'NEXT_CONSOLE_ERROR';
error[consoleTypeSym] = typeof message === 'string' ? 'string' : 'error';
if (environmentName && !error.environmentName) {
error.environmentName = environmentName;
}
return error;
}
const isConsoleError = (error)=>{
return error && error[digestSym] === 'NEXT_CONSOLE_ERROR';
};
const getConsoleErrorType = (error)=>{
return error[consoleTypeSym];
};
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=console-error.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/client/components/errors/console-error.ts"],"sourcesContent":["// To distinguish from React error.digest, we use a different symbol here to determine if the error is from console.error or unhandled promise rejection.\nconst digestSym = Symbol.for('next.console.error.digest')\nconst consoleTypeSym = Symbol.for('next.console.error.type')\n\n// Represent non Error shape unhandled promise rejections or console.error errors.\n// Those errors will be captured and displayed in Error Overlay.\nexport type ConsoleError = Error & {\n [digestSym]: 'NEXT_CONSOLE_ERROR'\n [consoleTypeSym]: 'string' | 'error'\n environmentName: string\n}\n\nexport function createConsoleError(\n message: string | Error,\n environmentName?: string | null\n): ConsoleError {\n const error = (\n typeof message === 'string' ? new Error(message) : message\n ) as ConsoleError\n error[digestSym] = 'NEXT_CONSOLE_ERROR'\n error[consoleTypeSym] = typeof message === 'string' ? 'string' : 'error'\n\n if (environmentName && !error.environmentName) {\n error.environmentName = environmentName\n }\n\n return error\n}\n\nexport const isConsoleError = (error: any): error is ConsoleError => {\n return error && error[digestSym] === 'NEXT_CONSOLE_ERROR'\n}\n\nexport const getConsoleErrorType = (error: ConsoleError) => {\n return error[consoleTypeSym]\n}\n"],"names":["createConsoleError","getConsoleErrorType","isConsoleError","digestSym","Symbol","for","consoleTypeSym","message","environmentName","error","Error"],"mappings":"AAAA,yJAAyJ;;;;;;;;;;;;;;;;;IAYzIA,kBAAkB;eAAlBA;;IAqBHC,mBAAmB;eAAnBA;;IAJAC,cAAc;eAAdA;;;AA5Bb,MAAMC,YAAYC,OAAOC,GAAG,CAAC;AAC7B,MAAMC,iBAAiBF,OAAOC,GAAG,CAAC;AAU3B,SAASL,mBACdO,OAAuB,EACvBC,eAA+B;IAE/B,MAAMC,QACJ,OAAOF,YAAY,WAAW,qBAAkB,CAAlB,IAAIG,MAAMH,UAAV,qBAAA;eAAA;oBAAA;sBAAA;IAAiB,KAAIA;IAErDE,KAAK,CAACN,UAAU,GAAG;IACnBM,KAAK,CAACH,eAAe,GAAG,OAAOC,YAAY,WAAW,WAAW;IAEjE,IAAIC,mBAAmB,CAACC,MAAMD,eAAe,EAAE;QAC7CC,MAAMD,eAAe,GAAGA;IAC1B;IAEA,OAAOC;AACT;AAEO,MAAMP,iBAAiB,CAACO;IAC7B,OAAOA,SAASA,KAAK,CAACN,UAAU,KAAK;AACvC;AAEO,MAAMF,sBAAsB,CAACQ;IAClC,OAAOA,KAAK,CAACH,eAAe;AAC9B"}
@@ -0,0 +1 @@
export declare function enqueueConsecutiveDedupedError(queue: Array<Error>, error: Error): void;
@@ -0,0 +1,27 @@
// Dedupe the two consecutive errors: If the previous one is same as current one, ignore the current one.
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "enqueueConsecutiveDedupedError", {
enumerable: true,
get: function() {
return enqueueConsecutiveDedupedError;
}
});
function enqueueConsecutiveDedupedError(queue, error) {
const previousError = queue[queue.length - 1];
// Compare the error stack to dedupe the consecutive errors
if (previousError && previousError.stack === error.stack) {
return;
}
queue.push(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=enqueue-client-error.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/client/components/errors/enqueue-client-error.ts"],"sourcesContent":["// Dedupe the two consecutive errors: If the previous one is same as current one, ignore the current one.\nexport function enqueueConsecutiveDedupedError(\n queue: Array<Error>,\n error: Error\n) {\n const previousError = queue[queue.length - 1]\n // Compare the error stack to dedupe the consecutive errors\n if (previousError && previousError.stack === error.stack) {\n return\n }\n queue.push(error)\n}\n"],"names":["enqueueConsecutiveDedupedError","queue","error","previousError","length","stack","push"],"mappings":"AAAA,yGAAyG;;;;;+BACzFA;;;eAAAA;;;AAAT,SAASA,+BACdC,KAAmB,EACnBC,KAAY;IAEZ,MAAMC,gBAAgBF,KAAK,CAACA,MAAMG,MAAM,GAAG,EAAE;IAC7C,2DAA2D;IAC3D,IAAID,iBAAiBA,cAAcE,KAAK,KAAKH,MAAMG,KAAK,EAAE;QACxD;IACF;IACAJ,MAAMK,IAAI,CAACJ;AACb"}
@@ -0,0 +1,19 @@
export type HydrationErrorState = {
warning?: [string, string, string];
serverContent?: string;
clientContent?: string;
notes?: string;
reactOutputComponentDiff?: string;
};
type NullableText = string | null | undefined;
export declare const hydrationErrorState: HydrationErrorState;
export declare const getHydrationWarningType: (message: NullableText) => "tag" | "text" | "text-in-tag";
export declare const getReactHydrationDiffSegments: (msg: NullableText) => (string | undefined)[] | undefined;
/**
* Patch console.error to capture hydration errors.
* If any of the knownHydrationWarnings are logged, store the message and component stack.
* When the hydration runtime error is thrown, the message and component stack are added to the error.
* This results in a more helpful error message in the error overlay.
*/
export declare function storeHydrationErrorStateFromConsoleArgs(...args: any[]): void;
export {};
+171
View File
@@ -0,0 +1,171 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
getHydrationWarningType: null,
getReactHydrationDiffSegments: null,
hydrationErrorState: null,
storeHydrationErrorStateFromConsoleArgs: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
getHydrationWarningType: function() {
return getHydrationWarningType;
},
getReactHydrationDiffSegments: function() {
return getReactHydrationDiffSegments;
},
hydrationErrorState: function() {
return hydrationErrorState;
},
storeHydrationErrorStateFromConsoleArgs: function() {
return storeHydrationErrorStateFromConsoleArgs;
}
});
const _ishydrationerror = require("../is-hydration-error");
const hydrationErrorState = {};
// https://github.com/facebook/react/blob/main/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js used as a reference
const htmlTagsWarnings = new Set([
'Warning: In HTML, %s cannot be a child of <%s>.%s\nThis will cause a hydration error.%s',
'Warning: In HTML, %s cannot be a descendant of <%s>.\nThis will cause a hydration error.%s',
'Warning: In HTML, text nodes cannot be a child of <%s>.\nThis will cause a hydration error.',
"Warning: In HTML, whitespace text nodes cannot be a child of <%s>. Make sure you don't have any extra whitespace between tags on each line of your source code.\nThis will cause a hydration error.",
'Warning: Expected server HTML to contain a matching <%s> in <%s>.%s',
'Warning: Did not expect server HTML to contain a <%s> in <%s>.%s'
]);
const textAndTagsMismatchWarnings = new Set([
'Warning: Expected server HTML to contain a matching text node for "%s" in <%s>.%s',
'Warning: Did not expect server HTML to contain the text node "%s" in <%s>.%s'
]);
const getHydrationWarningType = (message)=>{
if (typeof message !== 'string') {
// TODO: Doesn't make sense to treat no message as a hydration error message.
// We should bail out somewhere earlier.
return 'text';
}
const normalizedMessage = message.startsWith('Warning: ') ? message : "Warning: " + message;
if (isHtmlTagsWarning(normalizedMessage)) return 'tag';
if (isTextInTagsMismatchWarning(normalizedMessage)) return 'text-in-tag';
return 'text';
};
const isHtmlTagsWarning = (message)=>htmlTagsWarnings.has(message);
const isTextInTagsMismatchWarning = (msg)=>textAndTagsMismatchWarnings.has(msg);
const getReactHydrationDiffSegments = (msg)=>{
if (msg) {
const { message, diff } = (0, _ishydrationerror.getHydrationErrorStackInfo)(msg);
if (message) return [
message,
diff
];
}
return undefined;
};
function storeHydrationErrorStateFromConsoleArgs() {
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
args[_key] = arguments[_key];
}
let [msg, firstContent, secondContent, ...rest] = args;
if ((0, _ishydrationerror.testReactHydrationWarning)(msg)) {
// Some hydration warnings has 4 arguments, some has 3, fallback to the last argument
// when the 3rd argument is not the component stack but an empty string
const isReact18 = msg.startsWith('Warning: ');
// For some warnings, there's only 1 argument for template.
// The second argument is the diff or component stack.
if (args.length === 3) {
secondContent = '';
}
const warning = [
// remove the last %s from the message
msg,
firstContent,
secondContent
];
const lastArg = (rest[rest.length - 1] || '').trim();
if (!isReact18) {
hydrationErrorState.reactOutputComponentDiff = lastArg;
} else {
hydrationErrorState.reactOutputComponentDiff = generateHydrationDiffReact18(msg, firstContent, secondContent, lastArg);
}
hydrationErrorState.warning = warning;
hydrationErrorState.serverContent = firstContent;
hydrationErrorState.clientContent = secondContent;
}
}
/*
* Some hydration errors in React 18 does not have the diff in the error message.
* Instead it has the error stack trace which is component stack that we can leverage.
* Will parse the diff from the error stack trace
* e.g.
* Warning: Expected server HTML to contain a matching <div> in <p>.
* at div
* at p
* at div
* at div
* at Page
* output:
* <Page>
* <div>
* <p>
* > <div>
*
*/ function generateHydrationDiffReact18(message, firstContent, secondContent, lastArg) {
const componentStack = lastArg;
let firstIndex = -1;
let secondIndex = -1;
const hydrationWarningType = getHydrationWarningType(message);
// at div\n at Foo\n at Bar (....)\n -> [div, Foo]
const components = componentStack.split('\n')// .reverse()
.map((line, index)=>{
// `<space>at <component> (<location>)` -> `at <component> (<location>)`
line = line.trim();
// extract `<space>at <component>` to `<<component>>`
// e.g. ` at Foo` -> `<Foo>`
const [, component, location] = /at (\w+)( \((.*)\))?/.exec(line) || [];
// If there's no location then it's user-land stack frame
if (!location) {
if (component === firstContent && firstIndex === -1) {
firstIndex = index;
} else if (component === secondContent && secondIndex === -1) {
secondIndex = index;
}
}
return location ? '' : component;
}).filter(Boolean).reverse();
let diff = '';
for(let i = 0; i < components.length; i++){
const component = components[i];
const matchFirstContent = hydrationWarningType === 'tag' && i === components.length - firstIndex - 1;
const matchSecondContent = hydrationWarningType === 'tag' && i === components.length - secondIndex - 1;
if (matchFirstContent || matchSecondContent) {
const spaces = ' '.repeat(Math.max(i * 2 - 2, 0) + 2);
diff += "> " + spaces + "<" + component + ">\n";
} else {
const spaces = ' '.repeat(i * 2 + 2);
diff += spaces + "<" + component + ">\n";
}
}
if (hydrationWarningType === 'text') {
const spaces = ' '.repeat(components.length * 2);
diff += "+ " + spaces + '"' + firstContent + '"\n';
diff += "- " + spaces + '"' + secondContent + '"\n';
} else if (hydrationWarningType === 'text-in-tag') {
const spaces = ' '.repeat(components.length * 2);
diff += "> " + spaces + "<" + secondContent + ">\n";
diff += "> " + spaces + '"' + firstContent + '"\n';
}
return diff;
}
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=hydration-error-info.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/client/components/errors/hydration-error-info.ts"],"sourcesContent":["import {\n getHydrationErrorStackInfo,\n testReactHydrationWarning,\n} from '../is-hydration-error'\n\nexport type HydrationErrorState = {\n // Hydration warning template format: <message> <serverContent> <clientContent>\n warning?: [string, string, string]\n serverContent?: string\n clientContent?: string\n // React 19 hydration diff format: <notes> <link> <component diff?>\n notes?: string\n reactOutputComponentDiff?: string\n}\n\ntype NullableText = string | null | undefined\n\nexport const hydrationErrorState: HydrationErrorState = {}\n\n// https://github.com/facebook/react/blob/main/packages/react-dom/src/__tests__/ReactDOMHydrationDiff-test.js used as a reference\nconst htmlTagsWarnings = new Set([\n 'Warning: In HTML, %s cannot be a child of <%s>.%s\\nThis will cause a hydration error.%s',\n 'Warning: In HTML, %s cannot be a descendant of <%s>.\\nThis will cause a hydration error.%s',\n 'Warning: In HTML, text nodes cannot be a child of <%s>.\\nThis will cause a hydration error.',\n \"Warning: In HTML, whitespace text nodes cannot be a child of <%s>. Make sure you don't have any extra whitespace between tags on each line of your source code.\\nThis will cause a hydration error.\",\n 'Warning: Expected server HTML to contain a matching <%s> in <%s>.%s',\n 'Warning: Did not expect server HTML to contain a <%s> in <%s>.%s',\n])\nconst textAndTagsMismatchWarnings = new Set([\n 'Warning: Expected server HTML to contain a matching text node for \"%s\" in <%s>.%s',\n 'Warning: Did not expect server HTML to contain the text node \"%s\" in <%s>.%s',\n])\n\nexport const getHydrationWarningType = (\n message: NullableText\n): 'tag' | 'text' | 'text-in-tag' => {\n if (typeof message !== 'string') {\n // TODO: Doesn't make sense to treat no message as a hydration error message.\n // We should bail out somewhere earlier.\n return 'text'\n }\n\n const normalizedMessage = message.startsWith('Warning: ')\n ? message\n : `Warning: ${message}`\n\n if (isHtmlTagsWarning(normalizedMessage)) return 'tag'\n if (isTextInTagsMismatchWarning(normalizedMessage)) return 'text-in-tag'\n\n return 'text'\n}\n\nconst isHtmlTagsWarning = (message: string) => htmlTagsWarnings.has(message)\n\nconst isTextInTagsMismatchWarning = (msg: string) =>\n textAndTagsMismatchWarnings.has(msg)\n\nexport const getReactHydrationDiffSegments = (msg: NullableText) => {\n if (msg) {\n const { message, diff } = getHydrationErrorStackInfo(msg)\n if (message) return [message, diff]\n }\n return undefined\n}\n\n/**\n * Patch console.error to capture hydration errors.\n * If any of the knownHydrationWarnings are logged, store the message and component stack.\n * When the hydration runtime error is thrown, the message and component stack are added to the error.\n * This results in a more helpful error message in the error overlay.\n */\n\nexport function storeHydrationErrorStateFromConsoleArgs(...args: any[]) {\n let [msg, firstContent, secondContent, ...rest] = args\n if (testReactHydrationWarning(msg)) {\n // Some hydration warnings has 4 arguments, some has 3, fallback to the last argument\n // when the 3rd argument is not the component stack but an empty string\n const isReact18 = msg.startsWith('Warning: ')\n\n // For some warnings, there's only 1 argument for template.\n // The second argument is the diff or component stack.\n if (args.length === 3) {\n secondContent = ''\n }\n\n const warning: [string, string, string] = [\n // remove the last %s from the message\n msg,\n firstContent,\n secondContent,\n ]\n\n const lastArg = (rest[rest.length - 1] || '').trim()\n if (!isReact18) {\n hydrationErrorState.reactOutputComponentDiff = lastArg\n } else {\n hydrationErrorState.reactOutputComponentDiff =\n generateHydrationDiffReact18(msg, firstContent, secondContent, lastArg)\n }\n\n hydrationErrorState.warning = warning\n hydrationErrorState.serverContent = firstContent\n hydrationErrorState.clientContent = secondContent\n }\n}\n\n/*\n * Some hydration errors in React 18 does not have the diff in the error message.\n * Instead it has the error stack trace which is component stack that we can leverage.\n * Will parse the diff from the error stack trace\n * e.g.\n * Warning: Expected server HTML to contain a matching <div> in <p>.\n * at div\n * at p\n * at div\n * at div\n * at Page\n * output:\n * <Page>\n * <div>\n * <p>\n * > <div>\n *\n */\nfunction generateHydrationDiffReact18(\n message: string,\n firstContent: string,\n secondContent: string,\n lastArg: string\n) {\n const componentStack = lastArg\n let firstIndex = -1\n let secondIndex = -1\n const hydrationWarningType = getHydrationWarningType(message)\n\n // at div\\n at Foo\\n at Bar (....)\\n -> [dLine truncated
@@ -0,0 +1,3 @@
export declare const RuntimeErrorHandler: {
hadRuntimeError: boolean;
};
@@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "RuntimeErrorHandler", {
enumerable: true,
get: function() {
return RuntimeErrorHandler;
}
});
const RuntimeErrorHandler = {
hadRuntimeError: false
};
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=runtime-error-handler.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/client/components/errors/runtime-error-handler.ts"],"sourcesContent":["export const RuntimeErrorHandler = {\n hadRuntimeError: false,\n}\n"],"names":["RuntimeErrorHandler","hadRuntimeError"],"mappings":";;;;+BAAaA;;;eAAAA;;;AAAN,MAAMA,sBAAsB;IACjCC,iBAAiB;AACnB"}
+1
View File
@@ -0,0 +1 @@
export declare function getReactStitchedError<T = unknown>(err: T): Error | T;
+60
View File
@@ -0,0 +1,60 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "getReactStitchedError", {
enumerable: true,
get: function() {
return getReactStitchedError;
}
});
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
const _react = /*#__PURE__*/ _interop_require_default._(require("react"));
const _iserror = /*#__PURE__*/ _interop_require_default._(require("../../../lib/is-error"));
const _errortelemetryutils = require("../../../lib/error-telemetry-utils");
const REACT_ERROR_STACK_BOTTOM_FRAME = 'react-stack-bottom-frame';
const REACT_ERROR_STACK_BOTTOM_FRAME_REGEX = new RegExp("(at " + REACT_ERROR_STACK_BOTTOM_FRAME + " )|(" + REACT_ERROR_STACK_BOTTOM_FRAME + "\\@)");
function getReactStitchedError(err) {
const isErrorInstance = (0, _iserror.default)(err);
const originStack = isErrorInstance ? err.stack || '' : '';
const originMessage = isErrorInstance ? err.message : '';
const stackLines = originStack.split('\n');
const indexOfSplit = stackLines.findIndex((line)=>REACT_ERROR_STACK_BOTTOM_FRAME_REGEX.test(line));
const isOriginalReactError = indexOfSplit >= 0 // has the react-stack-bottom-frame
;
let newStack = isOriginalReactError ? stackLines.slice(0, indexOfSplit).join('\n') : originStack;
const newError = Object.defineProperty(new Error(originMessage), "__NEXT_ERROR_CODE", {
value: "E394",
enumerable: false,
configurable: true
});
// Copy all enumerable properties, e.g. digest
Object.assign(newError, err);
(0, _errortelemetryutils.copyNextErrorCode)(err, newError);
newError.stack = newStack;
// Avoid duplicate overriding stack frames
appendOwnerStack(newError);
return newError;
}
function appendOwnerStack(error) {
if (!_react.default.captureOwnerStack) {
return;
}
let stack = error.stack || '';
// This module is only bundled in development mode so this is safe.
const ownerStack = _react.default.captureOwnerStack();
// Avoid duplicate overriding stack frames
if (ownerStack && stack.endsWith(ownerStack) === false) {
stack += ownerStack;
// Override stack
error.stack = stack;
}
}
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=stitched-error.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/client/components/errors/stitched-error.ts"],"sourcesContent":["import React from 'react'\nimport isError from '../../../lib/is-error'\nimport { copyNextErrorCode } from '../../../lib/error-telemetry-utils'\n\nconst REACT_ERROR_STACK_BOTTOM_FRAME = 'react-stack-bottom-frame'\nconst REACT_ERROR_STACK_BOTTOM_FRAME_REGEX = new RegExp(\n `(at ${REACT_ERROR_STACK_BOTTOM_FRAME} )|(${REACT_ERROR_STACK_BOTTOM_FRAME}\\\\@)`\n)\n\nexport function getReactStitchedError<T = unknown>(err: T): Error | T {\n const isErrorInstance = isError(err)\n const originStack = isErrorInstance ? err.stack || '' : ''\n const originMessage = isErrorInstance ? err.message : ''\n const stackLines = originStack.split('\\n')\n const indexOfSplit = stackLines.findIndex((line) =>\n REACT_ERROR_STACK_BOTTOM_FRAME_REGEX.test(line)\n )\n const isOriginalReactError = indexOfSplit >= 0 // has the react-stack-bottom-frame\n let newStack = isOriginalReactError\n ? stackLines.slice(0, indexOfSplit).join('\\n')\n : originStack\n\n const newError = new Error(originMessage)\n // Copy all enumerable properties, e.g. digest\n Object.assign(newError, err)\n copyNextErrorCode(err, newError)\n newError.stack = newStack\n\n // Avoid duplicate overriding stack frames\n appendOwnerStack(newError)\n\n return newError\n}\n\nfunction appendOwnerStack(error: Error) {\n if (!React.captureOwnerStack) {\n return\n }\n let stack = error.stack || ''\n // This module is only bundled in development mode so this is safe.\n const ownerStack = React.captureOwnerStack()\n // Avoid duplicate overriding stack frames\n if (ownerStack && stack.endsWith(ownerStack) === false) {\n stack += ownerStack\n // Override stack\n error.stack = stack\n }\n}\n"],"names":["getReactStitchedError","REACT_ERROR_STACK_BOTTOM_FRAME","REACT_ERROR_STACK_BOTTOM_FRAME_REGEX","RegExp","err","isErrorInstance","isError","originStack","stack","originMessage","message","stackLines","split","indexOfSplit","findIndex","line","test","isOriginalReactError","newStack","slice","join","newError","Error","Object","assign","copyNextErrorCode","appendOwnerStack","error","React","captureOwnerStack","ownerStack","endsWith"],"mappings":";;;;+BASgBA;;;eAAAA;;;;gEATE;kEACE;qCACc;AAElC,MAAMC,iCAAiC;AACvC,MAAMC,uCAAuC,IAAIC,OAC/C,AAAC,SAAMF,iCAA+B,SAAMA,iCAA+B;AAGtE,SAASD,sBAAmCI,GAAM;IACvD,MAAMC,kBAAkBC,IAAAA,gBAAO,EAACF;IAChC,MAAMG,cAAcF,kBAAkBD,IAAII,KAAK,IAAI,KAAK;IACxD,MAAMC,gBAAgBJ,kBAAkBD,IAAIM,OAAO,GAAG;IACtD,MAAMC,aAAaJ,YAAYK,KAAK,CAAC;IACrC,MAAMC,eAAeF,WAAWG,SAAS,CAAC,CAACC,OACzCb,qCAAqCc,IAAI,CAACD;IAE5C,MAAME,uBAAuBJ,gBAAgB,EAAE,mCAAmC;;IAClF,IAAIK,WAAWD,uBACXN,WAAWQ,KAAK,CAAC,GAAGN,cAAcO,IAAI,CAAC,QACvCb;IAEJ,MAAMc,WAAW,qBAAwB,CAAxB,IAAIC,MAAMb,gBAAV,qBAAA;eAAA;oBAAA;sBAAA;IAAuB;IACxC,8CAA8C;IAC9Cc,OAAOC,MAAM,CAACH,UAAUjB;IACxBqB,IAAAA,sCAAiB,EAACrB,KAAKiB;IACvBA,SAASb,KAAK,GAAGU;IAEjB,0CAA0C;IAC1CQ,iBAAiBL;IAEjB,OAAOA;AACT;AAEA,SAASK,iBAAiBC,KAAY;IACpC,IAAI,CAACC,cAAK,CAACC,iBAAiB,EAAE;QAC5B;IACF;IACA,IAAIrB,QAAQmB,MAAMnB,KAAK,IAAI;IAC3B,mEAAmE;IACnE,MAAMsB,aAAaF,cAAK,CAACC,iBAAiB;IAC1C,0CAA0C;IAC1C,IAAIC,cAActB,MAAMuB,QAAQ,CAACD,gBAAgB,OAAO;QACtDtB,SAASsB;QACT,iBAAiB;QACjBH,MAAMnB,KAAK,GAAGA;IAChB;AACF"}
@@ -0,0 +1,5 @@
export type ErrorHandler = (error: Error) => void;
export declare function handleConsoleError(originError: unknown, consoleErrorArgs: any[]): void;
export declare function handleClientError(originError: unknown): void;
export declare function useErrorHandler(handleOnUnhandledError: ErrorHandler, handleOnUnhandledRejection: ErrorHandler): void;
export declare function handleGlobalErrors(): void;
+158
View File
@@ -0,0 +1,158 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
handleClientError: null,
handleConsoleError: null,
handleGlobalErrors: null,
useErrorHandler: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
handleClientError: function() {
return handleClientError;
},
handleConsoleError: function() {
return handleConsoleError;
},
handleGlobalErrors: function() {
return handleGlobalErrors;
},
useErrorHandler: function() {
return useErrorHandler;
}
});
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
const _react = require("react");
const _attachhydrationerrorstate = require("./attach-hydration-error-state");
const _isnextroutererror = require("../is-next-router-error");
const _hydrationerrorinfo = require("./hydration-error-info");
const _console = require("../../lib/console");
const _iserror = /*#__PURE__*/ _interop_require_default._(require("../../../lib/is-error"));
const _consoleerror = require("./console-error");
const _enqueueclienterror = require("./enqueue-client-error");
const _stitchederror = require("../errors/stitched-error");
const queueMicroTask = globalThis.queueMicrotask || ((cb)=>Promise.resolve().then(cb));
const errorQueue = [];
const errorHandlers = [];
const rejectionQueue = [];
const rejectionHandlers = [];
function handleConsoleError(originError, consoleErrorArgs) {
let error;
const { environmentName } = (0, _console.parseConsoleArgs)(consoleErrorArgs);
if ((0, _iserror.default)(originError)) {
error = (0, _consoleerror.createConsoleError)(originError, environmentName);
} else {
error = (0, _consoleerror.createConsoleError)((0, _console.formatConsoleArgs)(consoleErrorArgs), environmentName);
}
error = (0, _stitchederror.getReactStitchedError)(error);
(0, _hydrationerrorinfo.storeHydrationErrorStateFromConsoleArgs)(...consoleErrorArgs);
(0, _attachhydrationerrorstate.attachHydrationErrorState)(error);
(0, _enqueueclienterror.enqueueConsecutiveDedupedError)(errorQueue, error);
for (const handler of errorHandlers){
// Delayed the error being passed to React Dev Overlay,
// avoid the state being synchronously updated in the component.
queueMicroTask(()=>{
handler(error);
});
}
}
function handleClientError(originError) {
let error;
if ((0, _iserror.default)(originError)) {
error = originError;
} else {
// If it's not an error, format the args into an error
const formattedErrorMessage = originError + '';
error = Object.defineProperty(new Error(formattedErrorMessage), "__NEXT_ERROR_CODE", {
value: "E394",
enumerable: false,
configurable: true
});
}
error = (0, _stitchederror.getReactStitchedError)(error);
(0, _attachhydrationerrorstate.attachHydrationErrorState)(error);
(0, _enqueueclienterror.enqueueConsecutiveDedupedError)(errorQueue, error);
for (const handler of errorHandlers){
// Delayed the error being passed to React Dev Overlay,
// avoid the state being synchronously updated in the component.
queueMicroTask(()=>{
handler(error);
});
}
}
function useErrorHandler(handleOnUnhandledError, handleOnUnhandledRejection) {
(0, _react.useEffect)(()=>{
// Handle queued errors.
errorQueue.forEach(handleOnUnhandledError);
rejectionQueue.forEach(handleOnUnhandledRejection);
// Listen to new errors.
errorHandlers.push(handleOnUnhandledError);
rejectionHandlers.push(handleOnUnhandledRejection);
return ()=>{
// Remove listeners.
errorHandlers.splice(errorHandlers.indexOf(handleOnUnhandledError), 1);
rejectionHandlers.splice(rejectionHandlers.indexOf(handleOnUnhandledRejection), 1);
// Reset error queues.
errorQueue.splice(0, errorQueue.length);
rejectionQueue.splice(0, rejectionQueue.length);
};
}, [
handleOnUnhandledError,
handleOnUnhandledRejection
]);
}
function onUnhandledError(event) {
if ((0, _isnextroutererror.isNextRouterError)(event.error)) {
event.preventDefault();
return false;
}
// When there's an error property present, we log the error to error overlay.
// Otherwise we don't do anything as it's not logging in the console either.
if (event.error) {
handleClientError(event.error);
}
}
function onUnhandledRejection(ev) {
const reason = ev == null ? void 0 : ev.reason;
if ((0, _isnextroutererror.isNextRouterError)(reason)) {
ev.preventDefault();
return;
}
let error = reason;
if (error && !(0, _iserror.default)(error)) {
error = Object.defineProperty(new Error(error + ''), "__NEXT_ERROR_CODE", {
value: "E394",
enumerable: false,
configurable: true
});
}
rejectionQueue.push(error);
for (const handler of rejectionHandlers){
handler(error);
}
}
function handleGlobalErrors() {
if (typeof window !== 'undefined') {
try {
// Increase the number of stack frames on the client
Error.stackTraceLimit = 50;
} catch (e) {}
window.addEventListener('error', onUnhandledError);
window.addEventListener('unhandledrejection', onUnhandledRejection);
}
}
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=use-error-handler.js.map
@@ -0,0 +1 @@
{"version":3,"sources":["../../../../src/client/components/errors/use-error-handler.ts"],"sourcesContent":["import { useEffect } from 'react'\nimport { attachHydrationErrorState } from './attach-hydration-error-state'\nimport { isNextRouterError } from '../is-next-router-error'\nimport { storeHydrationErrorStateFromConsoleArgs } from './hydration-error-info'\nimport { formatConsoleArgs, parseConsoleArgs } from '../../lib/console'\nimport isError from '../../../lib/is-error'\nimport { createConsoleError } from './console-error'\nimport { enqueueConsecutiveDedupedError } from './enqueue-client-error'\nimport { getReactStitchedError } from '../errors/stitched-error'\n\nconst queueMicroTask =\n globalThis.queueMicrotask || ((cb: () => void) => Promise.resolve().then(cb))\n\nexport type ErrorHandler = (error: Error) => void\n\nconst errorQueue: Array<Error> = []\nconst errorHandlers: Array<ErrorHandler> = []\nconst rejectionQueue: Array<Error> = []\nconst rejectionHandlers: Array<ErrorHandler> = []\n\nexport function handleConsoleError(\n originError: unknown,\n consoleErrorArgs: any[]\n) {\n let error: Error\n const { environmentName } = parseConsoleArgs(consoleErrorArgs)\n if (isError(originError)) {\n error = createConsoleError(originError, environmentName)\n } else {\n error = createConsoleError(\n formatConsoleArgs(consoleErrorArgs),\n environmentName\n )\n }\n error = getReactStitchedError(error)\n\n storeHydrationErrorStateFromConsoleArgs(...consoleErrorArgs)\n attachHydrationErrorState(error)\n\n enqueueConsecutiveDedupedError(errorQueue, error)\n for (const handler of errorHandlers) {\n // Delayed the error being passed to React Dev Overlay,\n // avoid the state being synchronously updated in the component.\n queueMicroTask(() => {\n handler(error)\n })\n }\n}\n\nexport function handleClientError(originError: unknown) {\n let error: Error\n if (isError(originError)) {\n error = originError\n } else {\n // If it's not an error, format the args into an error\n const formattedErrorMessage = originError + ''\n error = new Error(formattedErrorMessage)\n }\n error = getReactStitchedError(error)\n\n attachHydrationErrorState(error)\n\n enqueueConsecutiveDedupedError(errorQueue, error)\n for (const handler of errorHandlers) {\n // Delayed the error being passed to React Dev Overlay,\n // avoid the state being synchronously updated in the component.\n queueMicroTask(() => {\n handler(error)\n })\n }\n}\n\nexport function useErrorHandler(\n handleOnUnhandledError: ErrorHandler,\n handleOnUnhandledRejection: ErrorHandler\n) {\n useEffect(() => {\n // Handle queued errors.\n errorQueue.forEach(handleOnUnhandledError)\n rejectionQueue.forEach(handleOnUnhandledRejection)\n\n // Listen to new errors.\n errorHandlers.push(handleOnUnhandledError)\n rejectionHandlers.push(handleOnUnhandledRejection)\n\n return () => {\n // Remove listeners.\n errorHandlers.splice(errorHandlers.indexOf(handleOnUnhandledError), 1)\n rejectionHandlers.splice(\n rejectionHandlers.indexOf(handleOnUnhandledRejection),\n 1\n )\n\n // Reset error queues.\n errorQueue.splice(0, errorQueue.length)\n rejectionQueue.splice(0, rejectionQueue.length)\n }\n }, [handleOnUnhandledError, handleOnUnhandledRejection])\n}\n\nfunction onUnhandledError(event: WindowEventMap['error']): void | boolean {\n if (isNextRouterError(event.error)) {\n event.preventDefault()\n return false\n }\n // When there's an error property present, we log the error to error overlay.\n // Otherwise we don't do anything as it's not logging in the console either.\n if (event.error) {\n handleClientError(event.error)\n }\n}\n\nfunction onUnhandledRejection(ev: WindowEventMap['unhandledrejection']): void {\n const reason = ev?.reason\n if (isNextRouterError(reason)) {\n ev.preventDefault()\n return\n }\n\n let error = reason\n if (error && !isError(error)) {\n error = new Error(error + '')\n }\n\n rejectionQueue.push(error)\n for (const handler of rejectionHandlers) {\n handler(error)\n }\n}\n\nexport function handleGlobalErrors() {\n if (typeof window !== 'undefined') {\n try {\n // Increase the number of stack frames on the client\n Error.stackTraceLimit = 50\n } catch {}\n\n window.addEventListener('error', onUnhandledError)\n window.addEventListener('unhandledrejection', onUnhandledRejection)\n }\n}\n"],"names":["handleClientError","handleConsoleError","handleGlobalErrors","useErrorHandler","queueMicroTask","globalThis","queueMicrotask","cb","Promise","resolve","then","errorQueue","errorHandlers","rejectionQueue","rejectionHandlers","originError","consoleErrorArgs","error","environmentName","parseConsoleArgs","isError","createConsoleError","formatConsoleArgs","getReactStitchedError","storeHydrationErrorStateFromConsoleArgs","attachHydrationErrorState","enqueueLine truncated