Skip to content

Commit 457624a

Browse files
committed
Cap laztRouteTimeout to finalTimeout
1 parent 4beb00c commit 457624a

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ test('lazyRouteTimeout: Infinity timeout always waits for routes', async ({ page
3535
);
3636
});
3737

38-
// Infinity timeout → waits however long needed
38+
// Infinity timeout → waits as long as possible (capped at finalTimeout to prevent indefinite hangs)
3939
await page.goto('/?idleTimeout=50&timeout=Infinity');
4040

4141
const navigationLink = page.locator('id=navigation-to-deep');
@@ -44,7 +44,7 @@ test('lazyRouteTimeout: Infinity timeout always waits for routes', async ({ page
4444

4545
const event = await transactionPromise;
4646

47-
// Should wait indefinitely and get full route
47+
// Should wait for routes to load (up to finalTimeout) and get full route
4848
expect(event.transaction).toBe('/deep/level2/level3/:id');
4949
expect(event.contexts?.trace?.data?.['sentry.source']).toBe('route');
5050
expect(event.contexts?.trace?.data?.['sentry.idle_span_finish_reason']).toBe('idleTimeout');

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ export interface ReactRouterOptions {
180180
* Maximum time (in milliseconds) to wait for lazy routes to load before finalizing span names.
181181
*
182182
* - Set to `0` to not wait at all (immediate finalization)
183-
* - Set to `Infinity` to wait indefinitely
183+
* - Set to `Infinity` to wait as long as possible (capped at `finalTimeout` to prevent indefinite hangs)
184184
* - Negative values will fall back to the default
185185
*
186186
* Defaults to 3× the configured `idleTimeout` (default: 3000ms).
@@ -562,11 +562,20 @@ export function createReactRouterV6CompatibleTracingIntegration(
562562
setup(client) {
563563
integration.setup(client);
564564

565+
const finalTimeout = options.finalTimeout ?? 30000;
565566
const defaultMaxWait = (options.idleTimeout ?? 1000) * 3;
566567
const configuredMaxWait = lazyRouteTimeout ?? defaultMaxWait;
567568

568-
// Validate and set
569-
if (Number.isNaN(configuredMaxWait)) {
569+
// Cap Infinity at finalTimeout to prevent indefinite hangs
570+
if (configuredMaxWait === Infinity) {
571+
_lazyRouteTimeout = finalTimeout;
572+
DEBUG_BUILD &&
573+
debug.log(
574+
'[React Router] lazyRouteTimeout set to Infinity, capping at finalTimeout:',
575+
finalTimeout,
576+
'ms to prevent indefinite hangs',
577+
);
578+
} else if (Number.isNaN(configuredMaxWait)) {
570579
DEBUG_BUILD &&
571580
debug.warn('[React Router] lazyRouteTimeout must be a number, falling back to default:', defaultMaxWait);
572581
_lazyRouteTimeout = defaultMaxWait;

0 commit comments

Comments
 (0)