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.
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.
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.