next
Version:
The React Framework
51 lines (50 loc) • 2.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
0 && (module.exports = {
isHangingPromiseRejectionError: null,
makeHangingPromise: null
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
isHangingPromiseRejectionError: function() {
return isHangingPromiseRejectionError;
},
makeHangingPromise: function() {
return makeHangingPromise;
}
});
function isHangingPromiseRejectionError(err) {
if (typeof err !== 'object' || err === null || !('digest' in err)) {
return false;
}
return err.digest === HANGING_PROMISE_REJECTION;
}
const HANGING_PROMISE_REJECTION = 'HANGING_PROMISE_REJECTION';
class HangingPromiseRejectionError extends Error {
constructor(expression){
super(`During prerendering, ${expression} rejects when the prerender is complete. Typically these errors are handled by React but if you move ${expression} to a different context by using \`setTimeout\`, \`after\`, or similar functions you may observe this error and you should handle it in that context.`), this.expression = expression, this.digest = HANGING_PROMISE_REJECTION;
}
}
function makeHangingPromise(signal, expression) {
const hangingPromise = new Promise((_, reject)=>{
signal.addEventListener('abort', ()=>{
reject(new HangingPromiseRejectionError(expression));
}, {
once: true
});
});
// We are fine if no one actually awaits this promise. We shouldn't consider this an unhandled rejection so
// we attach a noop catch handler here to suppress this warning. If you actually await somewhere or construct
// your own promise out of it you'll need to ensure you handle the error when it rejects.
hangingPromise.catch(ignoreReject);
return hangingPromise;
}
function ignoreReject() {}
//# sourceMappingURL=dynamic-rendering-utils.js.map