AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

Dev-Only Uncaught TypeError: Negative Timestamp In Performance.Measure During RSC Soft Navigation

In Next.js development mode, soft navigation to a route whose server component redirects after async work triggers an uncaught TypeError because React Server Components client code calls performance.measure with a negative end timestamp.

mediumConfidence 95%Next.jsAffected V16.3.3Affected V16.3.5

Origin Analysis

The React Server Components development client (react-server-dom-webpack) does not clamp the end timestamp for performance.measure in the errored and aborted branches of flushComponentPerformance, while it does clamp the start timestamp. The end value is computed as debugInfo.time + response._timeOrigin, where debugInfo.time is request-relative and response._timeOrigin is page-anchored, leading to large negative numbers that violate the Performance API contract and throw in Chromium.
1. Create an App Router page with 'export const dynamic = "force-dynamic";' that performs async work (e.g., auth check, DB query) and then calls redirect(). 2. Add a client-side link to this page from another page. 3. Run 'next dev' and open the other page in a Chromium browser. 4. Click the link to trigger a soft navigation (not a hard page load). 5. Observe the console: an uncaught TypeError 'Failed to execute 'measure' on 'Performance': '<Component>' cannot have a negative time stamp' appears and the dev overlay turns red.

Fixing Code Block

"use client"; // app/performance-patch.js if (typeof window !== 'undefined' && !window.__nextPerfMeasurePatched) { window.__nextPerfMeasurePatched = true; const originalMeasure = window.Performance.prototype.measure; window.Performance.prototype.measure = function(name, options) { if (options && typeof options === 'object') { if (typeof options.start === 'number' && options.start < 0) options.start = 0; if (typeof options.end === 'number' && options.end < 0) options.end = 0; } return originalMeasure.call(this, name, options); }; } // Import this file in app/layout.tsx: import './performance-patch';
This monkey-patch wraps the native Performance.prototype.measure to clamp any negative start or end timestamps to 0, preventing the browser exception. It is a temporary hotfix that can be dropped into any client-side script and imported in the root layout. The real fix should be applied inside Next.js's compiled react-server-dom-webpack client by clamping the end timestamp in the errored and aborted branches (lines 3909 and 4167) exactly like the start timestamp.

Edge Case Audit

This patch globally affects all performance.measure calls on the page and may mask legitimate negative timestamps that could indicate other bugs. It should be removed once the underlying issue is fixed in an official Next.js release. The patch is not effective in non-Chromium browsers if they throw on negative timestamps differently; however, the original bug is Chromium-specific. Upgrade to a fixed Next.js version when available and remove this workaround.

Ecosystem Topology