next
Version:
The React Framework
96 lines (95 loc) • 3.57 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "createDedupedByCallsiteServerErrorLoggerDev", {
enumerable: true,
get: function() {
return createDedupedByCallsiteServerErrorLoggerDev;
}
});
const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
function _getRequireWildcardCache(nodeInterop) {
if (typeof WeakMap !== "function") return null;
var cacheBabelInterop = new WeakMap();
var cacheNodeInterop = new WeakMap();
return (_getRequireWildcardCache = function(nodeInterop) {
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
})(nodeInterop);
}
function _interop_require_wildcard(obj, nodeInterop) {
if (!nodeInterop && obj && obj.__esModule) {
return obj;
}
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
return {
default: obj
};
}
var cache = _getRequireWildcardCache(nodeInterop);
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {
__proto__: null
};
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
for(var key in obj){
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}
const errorRef = {
current: null
};
// React.cache is currently only available in canary/experimental React channels.
const cache = typeof _react.cache === 'function' ? _react.cache : (fn)=>fn;
// When Dynamic IO is enabled, we record these as errors so that they
// are captured by the dev overlay as it's more critical to fix these
// when enabled.
const logErrorOrWarn = process.env.__NEXT_DYNAMIC_IO ? console.error : console.warn;
// We don't want to dedupe across requests.
// The developer might've just attempted to fix the warning so we should warn again if it still happens.
const flushCurrentErrorIfNew = cache(// eslint-disable-next-line @typescript-eslint/no-unused-vars -- cache key
(key)=>{
try {
logErrorOrWarn(errorRef.current);
} finally{
errorRef.current = null;
}
});
function createDedupedByCallsiteServerErrorLoggerDev(getMessage) {
return function logDedupedError(...args) {
const message = getMessage(...args);
if (process.env.NODE_ENV !== 'production') {
var _stack;
const callStackFrames = (_stack = new Error().stack) == null ? void 0 : _stack.split('\n');
if (callStackFrames === undefined || callStackFrames.length < 4) {
logErrorOrWarn(message);
} else {
// Error:
// logDedupedError
// asyncApiBeingAccessedSynchronously
// <userland callsite>
// TODO: This breaks if sourcemaps with ignore lists are enabled.
const key = callStackFrames[4];
errorRef.current = message;
flushCurrentErrorIfNew(key);
}
} else {
logErrorOrWarn(message);
}
};
}
//# sourceMappingURL=create-deduped-by-callsite-server-error-logger.js.map
;