Skip to content

fix(nextjs): Don't report Next.js prerender control flow errors - #23691

Merged
chargome merged 3 commits into
developfrom
charlygomez/js-3434-nextjs-fetch-rejects-after-prerender-completes-on
Aug 31, 2026
Merged

chargome merged 3 commits into
developfrom
charlygomez/js-3434-nextjs-fetch-rejects-after-prerender-completes-on

Conversation

@chargome

@chargome chargome commented Aug 27, 2026

Copy link
Copy Markdown
Member

Next.js uses some thrown errors as control flow, not as real failures. unstable_rethrow lists them, and any code that catches user errors is supposed to ignore them. We only ignored redirects and not-founds, so we reported HANGING_PROMISE_REJECTION, NEXT_PRERENDER_INTERRUPTED, DYNAMIC_SERVER_USAGE and BAILOUT_TO_CLIENT_SIDE_RENDERING as errors.

This shows up most with Cache Components. An uncached fetch() during a prerender never actually runs — Next returns a promise that never resolves, then rejects it when the prerender is aborted. React throws that rejection away, but our server component wrapper caught it and sent it to Sentry.

There was also a second problem: since #18408 the filtering only ran if there was an active span. Without one, nothing was filtered, so even plain redirect() and notFound() got reported. Both wrappers now filter regardless of whether a span exists.

closes #23592

Next.js throws a set of errors to steer rendering rather than to signal a
failure. Its `unstable_rethrow` defines the contract any code wrapping user
land in a try/catch has to honor, but the Sentry wrappers only recognized
redirects and not-founds. Everything else - most visibly the
`HANGING_PROMISE_REJECTION` that Cache Components produces for uncached
`fetch()` during a prerender - was reported as an error.

Filtering was also coupled to `getActiveSpan()` being truthy, so with no
active span nothing was filtered at all, including redirects and not-founds.

Fixes #23592

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@linear-code

linear-code Bot commented Aug 27, 2026

Copy link
Copy Markdown

JS-3434

@github-actions

github-actions Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

size-limit report 📦

⚠️ Warning: Base artifact is not the latest one, because the latest workflow run is not done yet. This may lead to incorrect results. Try to re-run all tests to get up to date results.

Path Size % Change Change
@sentry/browser 28.56 kB - -
@sentry/browser - with treeshaking flags 26.92 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 26.82 kB - -
@sentry/browser (incl. Tracing) 48.75 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 48.76 kB - -
@sentry/browser (incl. Tracing, Profiling) 51.68 kB - -
@sentry/browser (incl. Tracing, Replay) 88.23 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 77.63 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 92.93 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 105.85 kB - -
@sentry/browser (incl. Feedback) 46.05 kB - -
@sentry/browser (incl. sendFeedback) 33.62 kB - -
@sentry/browser (incl. FeedbackAsync) 38.73 kB - -
@sentry/browser (incl. Metrics) 29.51 kB - -
@sentry/browser (incl. Logs) 29.8 kB - -
@sentry/browser (incl. Metrics & Logs) 30.43 kB - -
@sentry/react 30.3 kB - -
@sentry/react (incl. Tracing) 50.94 kB - -
@sentry/vue 35.73 kB - -
@sentry/vue (incl. Tracing) 51.02 kB - -
@sentry/svelte 28.59 kB - -
CDN Bundle 30.35 kB - -
CDN Bundle (incl. Tracing) 49.38 kB - -
CDN Bundle (incl. Logs, Metrics) 32.58 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 51.25 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 73.17 kB - -
CDN Bundle (incl. Tracing, Replay) 86.86 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 88.73 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 92.8 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 94.64 kB - -
CDN Bundle - uncompressed 89.95 kB - -
CDN Bundle (incl. Tracing) - uncompressed 147.2 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 96.24 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 152.89 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 225.41 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 266.69 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 272.37 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 280.4 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 286.06 kB - -
@sentry/nextjs (client) 53.56 kB +0.1% +51 B 🔺
@sentry/sveltekit (client) 49.19 kB - -
@sentry/core/server 65.67 kB - -
@sentry/core/browser 51.86 kB - -
@sentry/node 123.52 kB +0.02% +19 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 85.23 kB - -
@sentry/node - without tracing 87.78 kB +0.03% +22 B 🔺
@sentry/node - without channel injection 103.18 kB +0.03% +22 B 🔺
@sentry/aws-serverless 96.12 kB +0.03% +25 B 🔺
@sentry/cloudflare (withSentry) - minified 200.72 kB - -
@sentry/cloudflare (withSentry) 499.25 kB - -

View base workflow run

@chargome chargome self-assigned this Aug 31, 2026
@chargome

Copy link
Copy Markdown
Member Author

bugbot run

The hanging-promise e2e test concluded "no error was captured" after a fixed
5s sleep, which is flake-prone in both directions: a late event could be
missed, and every run paid the full 5s.

It now requests a route that captures an error tagged with a token unique to
the run. The token guarantees a cache miss, the request happens strictly
after the prefetch, and the SDK flushes per request - so once that error
arrives, any error the prefetch captured must have arrived too. It doubles as
a positive control that errors flow at all.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@chargome

Copy link
Copy Markdown
Member Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 223209d. Configure here.

@chargome
chargome marked this pull request as ready for review August 31, 2026 11:43
@chargome
chargome requested a review from a team as a code owner August 31, 2026 11:43
@chargome
chargome requested review from logaretm, nicohrubec and s1gr1d and removed request for a team August 31, 2026 11:43
Comment thread packages/nextjs/src/common/nextNavigationErrorUtils.ts
Comment thread packages/nextjs/src/common/nextNavigationErrorUtils.ts
`withServerActionInstrumentation` catches user land errors like the other
wrappers, so it honors the same `unstable_rethrow` contract. Next.js only
throws these from a prerender scope and server actions run in a request
scope, so this is not reachable today - it is consistency and a guard
against Next.js routing them differently later.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@chargome
chargome merged commit 604f142 into develop Aug 31, 2026
283 of 284 checks passed
@chargome
chargome deleted the charlygomez/js-3434-nextjs-fetch-rejects-after-prerender-completes-on branch August 31, 2026 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nextjs: fetch() rejects after prerender completes on cacheComponents route with no dynamic data access (HANGING_PROMISE_REJECTION)

2 participants