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
1 line
8.4 KiB
Plaintext
1 line
8.4 KiB
Plaintext
{"version":3,"file":"lazy-routes.js","sources":["../../../src/reactrouter-compat-utils/lazy-routes.tsx"],"sourcesContent":["import { WINDOW } from '@sentry/browser';\nimport type { Span } from '@sentry/core';\nimport { addNonEnumerableProperty, debug, isThenable } from '@sentry/core';\nimport { DEBUG_BUILD } from '../debug-build';\nimport type { Location, RouteObject } from '../types';\nimport { getActiveRootSpan, getNavigationContext } from './utils';\n\n/**\n * Captures location at invocation time. Prefers navigation context over window.location\n * since window.location hasn't updated yet when async handlers are invoked.\n *\n * When inside a patchRoutesOnNavigation call, uses the captured targetPath. If targetPath\n * is undefined (patchRoutesOnNavigation can be invoked without a path argument), returns\n * null rather than falling back to WINDOW.location which could be stale/wrong after the\n * user navigated away during async loading. Returning null causes the span name update\n * to be skipped, which is safer than using incorrect location data.\n */\nfunction captureCurrentLocation(): Location | null {\n const navContext = getNavigationContext();\n\n if (navContext) {\n if (navContext.targetPath) {\n return {\n pathname: navContext.targetPath,\n search: '',\n hash: '',\n state: null,\n key: 'default',\n };\n }\n // Don't fall back to potentially stale WINDOW.location\n return null;\n }\n\n if (typeof WINDOW !== 'undefined') {\n try {\n const windowLocation = WINDOW.location;\n if (windowLocation) {\n return {\n pathname: windowLocation.pathname,\n search: windowLocation.search || '',\n hash: windowLocation.hash || '',\n state: null,\n key: 'default',\n };\n }\n } catch {\n DEBUG_BUILD && debug.warn('[React Router] Could not access window.location');\n }\n }\n return null;\n}\n\n/**\n * Captures the active span at invocation time. Prefers navigation context span\n * to ensure we update the correct span even if another navigation starts.\n */\nfunction captureActiveSpan(): Span | undefined {\n const navContext = getNavigationContext();\n if (navContext) {\n return navContext.span;\n }\n return getActiveRootSpan();\n}\n\n/**\n * Creates a proxy wrapper for an async handler function.\n * Captures both the location and the active span at invocation time to ensure\n * the correct span is updated when the handler resolves.\n */\nexport function createAsyncHandlerProxy(\n originalFunction: (...args: unknown[]) => unknown,\n route: RouteObject,\n handlerKey: string,\n processResolvedRoutes: (\n resolvedRoutes: RouteObject[],\n parentRoute?: RouteObject,\n currentLocation?: Location,\n capturedSpan?: Span,\n ) => void,\n): (...args: unknown[]) => unknown {\n const proxy = new Proxy(originalFunction, {\n apply(target: (...args: unknown[]) => unknown, thisArg, argArray) {\n const locationAtInvocation = captureCurrentLocation();\n const spanAtInvocation = captureActiveSpan();\n const result = target.apply(thisArg, argArray);\n handleAsyncHandlerResult(\n result,\n route,\n handlerKey,\n processResolvedRoutes,\n locationAtInvocation,\n spanAtInvocation,\n );\n return result;\n },\n });\n\n addNonEnumerableProperty(proxy, '__sentry_proxied__', true);\n\n return proxy;\n}\n\n/**\n * Handles the result of an async handler function call.\n * Passes the captured span through to ensure the correct span is updated.\n */\nexport function handleAsyncHandlerResult(\n result: unknown,\n route: RouteObject,\n handlerKey: string,\n processResolvedRoutes: (\n resolvedRoutes: RouteObject[],\n parentRoute?: RouteObject,\n currentLocation?: Location,\n capturedSpan?: Span,\n ) => void,\n currentLocation: Location | null,\n capturedSpan: Span | undefined,\n): void {\n if (isThenable(result)) {\n (result as Promise<unknown>)\n .then((resolvedRoutes: unknown) => {\n if (Array.isArray(resolvedRoutes)) {\n processResolvedRoutes(resolvedRoutes, route, currentLocation ?? undefined, capturedSpan);\n }\n })\n .catch((e: unknown) => {\n DEBUG_BUILD && debug.warn(`Error resolving async handler '${handlerKey}' for route`, route, e);\n });\n } else if (Array.isArray(result)) {\n processResolvedRoutes(result, route, currentLocation ?? undefined, capturedSpan);\n }\n}\n\n/**\n * Recursively checks a route for async handlers and sets up Proxies to add discovered child routes to allRoutes when called.\n */\nexport function checkRouteForAsyncHandler(\n route: RouteObject,\n processResolvedRoutes: (\n resolvedRoutes: RouteObject[],\n parentRoute?: RouteObject,\n currentLocation?: Location,\n capturedSpan?: Span,\n ) => void,\n): void {\n // Set up proxies for any functions in the route's handle\n if (route.handle && typeof route.handle === 'object') {\n for (const key of Object.keys(route.handle)) {\n const maybeFn = route.handle[key];\n if (typeof maybeFn === 'function' && !(maybeFn as { __sentry_proxied__?: boolean }).__sentry_proxied__) {\n route.handle[key] = createAsyncHandlerProxy(maybeFn, route, key, processResolvedRoutes);\n }\n }\n }\n\n // Recursively check child routes\n if (Array.isArray(route.children)) {\n for (const child of route.children) {\n checkRouteForAsyncHandler(child, processResolvedRoutes);\n }\n }\n}\n"],"names":[],"mappings":";;;;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,sBAAsB,GAAoB;AACnD,EAAE,MAAM,UAAA,GAAa,oBAAoB,EAAE;;AAE3C,EAAE,IAAI,UAAU,EAAE;AAClB,IAAI,IAAI,UAAU,CAAC,UAAU,EAAE;AAC/B,MAAM,OAAO;AACb,QAAQ,QAAQ,EAAE,UAAU,CAAC,UAAU;AACvC,QAAQ,MAAM,EAAE,EAAE;AAClB,QAAQ,IAAI,EAAE,EAAE;AAChB,QAAQ,KAAK,EAAE,IAAI;AACnB,QAAQ,GAAG,EAAE,SAAS;AACtB,OAAO;AACP,IAAI;AACJ;AACA,IAAI,OAAO,IAAI;AACf,EAAE;;AAEF,EAAE,IAAI,OAAO,MAAA,KAAW,WAAW,EAAE;AACrC,IAAI,IAAI;AACR,MAAM,MAAM,cAAA,GAAiB,MAAM,CAAC,QAAQ;AAC5C,MAAM,IAAI,cAAc,EAAE;AAC1B,QAAQ,OAAO;AACf,UAAU,QAAQ,EAAE,cAAc,CAAC,QAAQ;AAC3C,UAAU,MAAM,EAAE,cAAc,CAAC,MAAA,IAAU,EAAE;AAC7C,UAAU,IAAI,EAAE,cAAc,CAAC,IAAA,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