added fonts
This commit is contained in:
1 parent
4134e3a234
commit
142d2986b6
9079 files changed
+1498421
-2
No files matched your search
Generated
Vendored
+68
@@ -0,0 +1,68 @@
|
||||
import { getDefaultHydrationErrorMessage, isHydrationError, testReactHydrationWarning } from '../is-hydration-error';
|
||||
import { hydrationErrorState, getReactHydrationDiffSegments } from './hydration-error-info';
|
||||
export function attachHydrationErrorState(error) {
|
||||
let parsedHydrationErrorState = {};
|
||||
const isHydrationWarning = testReactHydrationWarning(error.message);
|
||||
const isHydrationRuntimeError = isHydrationError(error);
|
||||
// If it's not hydration warnings or errors, skip
|
||||
if (!(isHydrationRuntimeError || isHydrationWarning)) {
|
||||
return;
|
||||
}
|
||||
const reactHydrationDiffSegments = 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,
|
||||
...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 : hydrationErrorState.warning) || [
|
||||
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 (!hydrationErrorState.reactOutputComponentDiff && diff) {
|
||||
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 && hydrationErrorState.reactOutputComponentDiff) {
|
||||
parsedHydrationErrorState.reactOutputComponentDiff = 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 (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
|
||||
...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 (hydrationErrorState.reactOutputComponentDiff) {
|
||||
parsedHydrationErrorState.reactOutputComponentDiff = hydrationErrorState.reactOutputComponentDiff;
|
||||
}
|
||||
}
|
||||
// If it's a hydration error, store the hydration error state into the error object
|
||||
;
|
||||
error.details = parsedHydrationErrorState;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=attach-hydration-error-state.js.map
|
||||
Generated
Vendored
+1
@@ -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":["getDefaultHydrationErrorMessage","isHydrationError","testReactHydrationWarning","hydrationErrorState","getReactHydrationDiffSegments","attachHydrationErrorState","error","parsedHydrationErrorState","isHydrationWarning","message","isHydrationRuntimeError","reactHydrationDiffSegments","diff","details","warning","notes","reactOutputComponentDiff"],"mappings":"AAAA,SACEA,+BAA+B,EAC/BC,gBAAgB,EAChBC,yBAAyB,QACpB,wBAAuB;AAC9B,SACEC,mBAAmB,EACnBC,6BAA6B,QAExB,yBAAwB;AAE/B,OAAO,SAASC,0BAA0BC,KAAY;IACpD,IAAIC,4BAAwD,CAAC;IAC7D,MAAMC,qBAAqBN,0BAA0BI,MAAMG,OAAO;IAClE,MAAMC,0BAA0BT,iBAAiBK;IAEjD,iDAAiD;IACjD,IAAI,CAAEI,CAAAA,2BAA2BF,kBAAiB,GAAI;QACpD;IACF;IAEA,MAAMG,6BAA6BP,8BACjCE,MAAMG,OAAO;IAEf,2CAA2C;IAC3C,sDAAsD;IACtD,qCAAqC;IACrC,IAAIE,4BAA4B;QAC9B,MAAMC,OAAOD,0BAA0B,CAAC,EAAE;QAC1CJ,4BAA4B;YAC1B,GAAI,AAACD,MAAcO,OAAO;YAC1B,GAAGV,mBAAmB;YACtB,oFAAoF;YACpF,oGAAoG;YACpG,mFAAmF;YAEnFW,SAAS,AAACF,CAAAA,QAAQ,CAACJ,qBACf,OACAL,oBAAoBW,OAAO,AAAD,KAAM;gBAClCd;gBACA;gBACA;aACD;YACD,2DAA2D;YAC3D,qDAAqD;YACrDe,OAAOP,qBAAqB,KAAKG,0BAA0B,CAAC,EAAE;YAC9DK,0BAA0BJ;QAC5B;QACA,iEAAiE;QACjE,oGAAoG;QACpG,2EAA2E;QAC3E,IAAI,CAACT,oBAAoBa,wBAAwB,IAAILine truncated
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
// 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.
|
||||
const digestSym = Symbol.for('next.console.error.digest');
|
||||
const consoleTypeSym = Symbol.for('next.console.error.type');
|
||||
export 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;
|
||||
}
|
||||
export const isConsoleError = (error)=>{
|
||||
return error && error[digestSym] === 'NEXT_CONSOLE_ERROR';
|
||||
};
|
||||
export const getConsoleErrorType = (error)=>{
|
||||
return error[consoleTypeSym];
|
||||
};
|
||||
|
||||
//# sourceMappingURL=console-error.js.map
|
||||
+1
@@ -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":["digestSym","Symbol","for","consoleTypeSym","createConsoleError","message","environmentName","error","Error","isConsoleError","getConsoleErrorType"],"mappings":"AAAA,yJAAyJ;AACzJ,MAAMA,YAAYC,OAAOC,GAAG,CAAC;AAC7B,MAAMC,iBAAiBF,OAAOC,GAAG,CAAC;AAUlC,OAAO,SAASE,mBACdC,OAAuB,EACvBC,eAA+B;IAE/B,MAAMC,QACJ,OAAOF,YAAY,WAAW,qBAAkB,CAAlB,IAAIG,MAAMH,UAAV,qBAAA;eAAA;oBAAA;sBAAA;IAAiB,KAAIA;IAErDE,KAAK,CAACP,UAAU,GAAG;IACnBO,KAAK,CAACJ,eAAe,GAAG,OAAOE,YAAY,WAAW,WAAW;IAEjE,IAAIC,mBAAmB,CAACC,MAAMD,eAAe,EAAE;QAC7CC,MAAMD,eAAe,GAAGA;IAC1B;IAEA,OAAOC;AACT;AAEA,OAAO,MAAME,iBAAiB,CAACF;IAC7B,OAAOA,SAASA,KAAK,CAACP,UAAU,KAAK;AACvC,EAAC;AAED,OAAO,MAAMU,sBAAsB,CAACH;IAClC,OAAOA,KAAK,CAACJ,eAAe;AAC9B,EAAC"}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// Dedupe the two consecutive errors: If the previous one is same as current one, ignore the current one.
|
||||
export 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);
|
||||
}
|
||||
|
||||
//# sourceMappingURL=enqueue-client-error.js.map
|
||||
+1
@@ -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;AACzG,OAAO,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"}
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
import { getHydrationErrorStackInfo, testReactHydrationWarning } from '../is-hydration-error';
|
||||
export 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'
|
||||
]);
|
||||
export 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);
|
||||
export const getReactHydrationDiffSegments = (msg)=>{
|
||||
if (msg) {
|
||||
const { message, diff } = getHydrationErrorStackInfo(msg);
|
||||
if (message) return [
|
||||
message,
|
||||
diff
|
||||
];
|
||||
}
|
||||
return 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 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 (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;
|
||||
}
|
||||
|
||||
//# sourceMappingURL=hydration-error-info.js.map
|
||||
+1
@@ -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
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
export const RuntimeErrorHandler = {
|
||||
hadRuntimeError: false
|
||||
};
|
||||
|
||||
//# sourceMappingURL=runtime-error-handler.js.map
|
||||
+1
@@ -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":"AAAA,OAAO,MAAMA,sBAAsB;IACjCC,iBAAiB;AACnB,EAAC"}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
import React from 'react';
|
||||
import isError from '../../../lib/is-error';
|
||||
import { copyNextErrorCode } from '../../../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 + "\\@)");
|
||||
export function getReactStitchedError(err) {
|
||||
const isErrorInstance = isError(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);
|
||||
copyNextErrorCode(err, newError);
|
||||
newError.stack = newStack;
|
||||
// Avoid duplicate overriding stack frames
|
||||
appendOwnerStack(newError);
|
||||
return newError;
|
||||
}
|
||||
function appendOwnerStack(error) {
|
||||
if (!React.captureOwnerStack) {
|
||||
return;
|
||||
}
|
||||
let stack = error.stack || '';
|
||||
// This module is only bundled in development mode so this is safe.
|
||||
const ownerStack = React.captureOwnerStack();
|
||||
// Avoid duplicate overriding stack frames
|
||||
if (ownerStack && stack.endsWith(ownerStack) === false) {
|
||||
stack += ownerStack;
|
||||
// Override stack
|
||||
error.stack = stack;
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=stitched-error.js.map
|
||||
+1
@@ -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":["React","isError","copyNextErrorCode","REACT_ERROR_STACK_BOTTOM_FRAME","REACT_ERROR_STACK_BOTTOM_FRAME_REGEX","RegExp","getReactStitchedError","err","isErrorInstance","originStack","stack","originMessage","message","stackLines","split","indexOfSplit","findIndex","line","test","isOriginalReactError","newStack","slice","join","newError","Error","Object","assign","appendOwnerStack","error","captureOwnerStack","ownerStack","endsWith"],"mappings":"AAAA,OAAOA,WAAW,QAAO;AACzB,OAAOC,aAAa,wBAAuB;AAC3C,SAASC,iBAAiB,QAAQ,qCAAoC;AAEtE,MAAMC,iCAAiC;AACvC,MAAMC,uCAAuC,IAAIC,OAC/C,AAAC,SAAMF,iCAA+B,SAAMA,iCAA+B;AAG7E,OAAO,SAASG,sBAAmCC,GAAM;IACvD,MAAMC,kBAAkBP,QAAQM;IAChC,MAAME,cAAcD,kBAAkBD,IAAIG,KAAK,IAAI,KAAK;IACxD,MAAMC,gBAAgBH,kBAAkBD,IAAIK,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,UAAUhB;IACxBL,kBAAkBK,KAAKgB;IACvBA,SAASb,KAAK,GAAGU;IAEjB,0CAA0C;IAC1CO,iBAAiBJ;IAEjB,OAAOA;AACT;AAEA,SAASI,iBAAiBC,KAAY;IACpC,IAAI,CAAC5B,MAAM6B,iBAAiB,EAAE;QAC5B;IACF;IACA,IAAInB,QAAQkB,MAAMlB,KAAK,IAAI;IAC3B,mEAAmE;IACnE,MAAMoB,aAAa9B,MAAM6B,iBAAiB;IAC1C,0CAA0C;IAC1C,IAAIC,cAAcpB,MAAMqB,QAAQ,CAACD,gBAAgB,OAAO;QACtDpB,SAASoB;QACT,iBAAiB;QACjBF,MAAMlB,KAAK,GAAGA;IAChB;AACF"}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
import { useEffect } from 'react';
|
||||
import { attachHydrationErrorState } from './attach-hydration-error-state';
|
||||
import { isNextRouterError } from '../is-next-router-error';
|
||||
import { storeHydrationErrorStateFromConsoleArgs } from './hydration-error-info';
|
||||
import { formatConsoleArgs, parseConsoleArgs } from '../../lib/console';
|
||||
import isError from '../../../lib/is-error';
|
||||
import { createConsoleError } from './console-error';
|
||||
import { enqueueConsecutiveDedupedError } from './enqueue-client-error';
|
||||
import { getReactStitchedError } from '../errors/stitched-error';
|
||||
const queueMicroTask = globalThis.queueMicrotask || ((cb)=>Promise.resolve().then(cb));
|
||||
const errorQueue = [];
|
||||
const errorHandlers = [];
|
||||
const rejectionQueue = [];
|
||||
const rejectionHandlers = [];
|
||||
export function handleConsoleError(originError, consoleErrorArgs) {
|
||||
let error;
|
||||
const { environmentName } = parseConsoleArgs(consoleErrorArgs);
|
||||
if (isError(originError)) {
|
||||
error = createConsoleError(originError, environmentName);
|
||||
} else {
|
||||
error = createConsoleError(formatConsoleArgs(consoleErrorArgs), environmentName);
|
||||
}
|
||||
error = getReactStitchedError(error);
|
||||
storeHydrationErrorStateFromConsoleArgs(...consoleErrorArgs);
|
||||
attachHydrationErrorState(error);
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
export function handleClientError(originError) {
|
||||
let error;
|
||||
if (isError(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 = getReactStitchedError(error);
|
||||
attachHydrationErrorState(error);
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
export function useErrorHandler(handleOnUnhandledError, handleOnUnhandledRejection) {
|
||||
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 (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 (isNextRouterError(reason)) {
|
||||
ev.preventDefault();
|
||||
return;
|
||||
}
|
||||
let error = reason;
|
||||
if (error && !isError(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);
|
||||
}
|
||||
}
|
||||
export 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);
|
||||
}
|
||||
}
|
||||
|
||||
//# sourceMappingURL=use-error-handler.js.map
|
||||
+1
@@ -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":["useEffect","attachHydrationErrorState","isNextRouterError","storeHydrationErrorStateFromConsoleArgs","formatConsoleArgs","parseConsoleArgs","isError","createConsoleError","enqueueConsecutiveDedupedError","getReactStitchedError","queueMicroTask","globalThis","queueMicrotask","cb","Promise","resolve","then","errorQueue","errorHandlers","rejectionQueue","rejectionHandlers","handleConsoleError","originError","consoleErrorArgs","error","environmentName","hLine truncated
|
||||
Reference in new issue
Block a user