Files
klz-cables.com/.pnpm-store/v10/files/89/bdf135454a0815799419ab780f3e8300abc0d48152e042c76518cda1a5f39b51871c1ed5e048a3db437c6c7e7724d75b468993ba9206370c176a191e91e7ef
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

104 lines
3.6 KiB
Plaintext

Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const core = require('@sentry/core');
const debugBuild = require('../common/debug-build.js');
// Inline AsyncLocalStorage interface from current types
// Avoids conflict with resolving it from getBuiltinModule
/**
* Prepares the global object to generate safe random IDs in cache components contexts
* See: https://github.com/getsentry/sentry-javascript/blob/ceb003c15973c2d8f437dfb7025eedffbc8bc8b0/packages/core/src/utils/propagationContext.ts#L1
*/
function prepareSafeIdGeneratorContext() {
const sym = Symbol.for('__SENTRY_SAFE_RANDOM_ID_WRAPPER__');
const globalWithSymbol = core.GLOBAL_OBJ;
// Get initial snapshot - if unavailable, don't set up the wrapper at all
const initialSnapshot = getAsyncLocalStorageSnapshot();
if (!initialSnapshot) {
return;
}
// We store a wrapper function instead of the raw snapshot because in serverless
// environments (e.g., Cloudflare Workers), the snapshot is bound to the request
// context it was created in. Once that request ends, the snapshot becomes invalid.
// The wrapper catches this and creates a fresh snapshot for the current request context.
let cachedSnapshot = initialSnapshot;
globalWithSymbol[sym] = (callback) => {
try {
return cachedSnapshot(callback);
} catch (error) {
// Only handle AsyncLocalStorage-related errors, rethrow others
if (!isAsyncLocalStorageError(error)) {
throw error;
}
// Snapshot likely stale, try to get a fresh one and retry
const freshSnapshot = getAsyncLocalStorageSnapshot();
// No snapshot available, fall back to direct execution
if (!freshSnapshot) {
return callback();
}
// Update the cached snapshot
cachedSnapshot = freshSnapshot;
// Retry the callback with the fresh snapshot
try {
return cachedSnapshot(callback);
} catch (retryError) {
// Only fall back for AsyncLocalStorage errors, rethrow others
if (!isAsyncLocalStorageError(retryError)) {
throw retryError;
}
// If fresh snapshot also fails with ALS error, fall back to direct execution
return callback();
}
}
};
debugBuild.DEBUG_BUILD && core.debug.log('[@sentry/nextjs] Prepared safe random ID generator context');
}
function getAsyncLocalStorage() {
// May exist in the Next.js runtime globals
// Doesn't exist in some of our tests
if (typeof AsyncLocalStorage !== 'undefined') {
return AsyncLocalStorage;
}
// Try to resolve it dynamically without synchronously importing the module
// This is done to avoid importing the module synchronously at the top
// which means this is safe across runtimes
if ('getBuiltinModule' in process && typeof process.getBuiltinModule === 'function') {
const { AsyncLocalStorage } = process.getBuiltinModule('async_hooks') ?? {};
return AsyncLocalStorage ;
}
return undefined;
}
function getAsyncLocalStorageSnapshot() {
const als = getAsyncLocalStorage();
if (!als || typeof als.snapshot !== 'function') {
debugBuild.DEBUG_BUILD &&
core.debug.warn(
'[@sentry/nextjs] No AsyncLocalStorage found in the runtime or AsyncLocalStorage.snapshot() is not available, skipping safe random ID generator context preparation, you may see some errors with cache components.',
);
return undefined;
}
return als.snapshot();
}
function isAsyncLocalStorageError(error) {
return error instanceof Error && error.message.includes('AsyncLocalStorage');
}
exports.prepareSafeIdGeneratorContext = prepareSafeIdGeneratorContext;
//# sourceMappingURL=prepareSafeIdGeneratorContext.js.map