Skip to content

Commit 8468d79

Browse files
committed
Optimize for bundle size
1 parent affcab6 commit 8468d79

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

packages/react/src/reactrouter-compat-utils/instrumentation.tsx

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -505,12 +505,8 @@ export function createReactRouterV6CompatibleTracingIntegration(
505505
// Get idleTimeout from browserTracingIntegration options (passed through)
506506
// idleTimeout from browserTracingIntegration (default: 1000ms)
507507
// Note: options already contains idleTimeout if user passed it to browserTracingIntegration
508-
const idleTimeout = options.idleTimeout ?? 1000;
509-
510-
// Calculate default: 3× idleTimeout
511-
const defaultMaxWait = idleTimeout * 3;
512-
513-
// Allow explicit override, otherwise use calculated default
508+
// Calculate default: 3× idleTimeout, allow explicit override
509+
const defaultMaxWait = (options.idleTimeout ?? 1000) * 3;
514510
const configuredMaxWait = maxLazyRouteWaitMs ?? defaultMaxWait;
515511

516512
// Validate and set
@@ -940,22 +936,17 @@ function patchSpanEnd(
940936
const promiseArray = Array.from(pendingPromises);
941937

942938
// Wait for all lazy routes to settle (never rejects, safe for all outcomes)
943-
const settledPromise = Promise.allSettled(promiseArray).then(() => {});
944-
945-
// Create timeout promise to prevent hanging indefinitely
946-
const timeoutPromise = new Promise<void>(resolve => {
947-
// Handle special case: Infinity means no timeout
948-
if (_maxLazyRouteWaitMs === Infinity) {
949-
// Don't resolve - wait indefinitely (user explicitly opted in)
950-
return;
951-
}
952-
setTimeout(resolve, _maxLazyRouteWaitMs);
953-
});
939+
const allSettled = Promise.allSettled(promiseArray).then(() => {});
940+
941+
// Race against timeout or wait indefinitely if Infinity
942+
const waitPromise =
943+
_maxLazyRouteWaitMs === Infinity
944+
? allSettled
945+
: Promise.race([allSettled, new Promise<void>(r => setTimeout(r, _maxLazyRouteWaitMs))]);
954946

955-
// Race: whichever completes first (routes resolve or timeout)
956-
Promise.race([settledPromise, timeoutPromise])
947+
// Update span name once routes are resolved or timeout expires
948+
waitPromise
957949
.then(() => {
958-
// Try to update span name with (hopefully) resolved routes
959950
tryUpdateSpanNameBeforeEnd(
960951
span,
961952
spanToJSON(span),
@@ -968,9 +959,8 @@ function patchSpanEnd(
968959
);
969960
originalEnd(...args);
970961
})
971-
.catch((error: unknown) => {
972-
// Defensive: allSettled never rejects, but be safe
973-
DEBUG_BUILD && debug.warn('Error waiting for lazy routes:', error);
962+
.catch(() => {
963+
// Defensive: should never happen with allSettled, but satisfy ESLint
974964
originalEnd(...args);
975965
});
976966
return;

0 commit comments

Comments
 (0)