Skip to content

fix(bundler-plugins): Check globalThis before global in the injected snippet - #25365

Open
JPeer264 wants to merge 1 commit into
fix/nuxt-5-server-sourcescontentfrom
jp/nuxt-cloudflare-sourcemap-symbolication
Open

JPeer264 wants to merge 1 commit into
fix/nuxt-5-server-sourcescontentfrom
jp/nuxt-cloudflare-sourcemap-symbolication

Conversation

@JPeer264

Copy link
Copy Markdown
Member

part of #20051
part of JS-2027

Description

This changes the injected debug ID snippet to check globalThis before window and global. The same header in the Next.js module metadata loader and the Remix v3 debug ID helper gets the same order.

Why

When a second bundler runs over a chunk that already has the snippet, it can turn the free global into a const declared further down in the file. Nitro's node compat does this for the server runtime chunk. The snippet then reads that binding in the temporal dead zone, typeof throws, and the snippet's own try/catch hides the error. The chunk registers no debug ID, and Sentry reports js_no_source for all of its frames although the map was uploaded.

Known issues

  • Nuxt on Cloudflare also needs no_bundle and rules in the wrangler config, so that wrangler does not merge the Nitro chunks into one index.js. This is a documentation change.
  • @sentry/nuxt@10 uses @sentry/vite-plugin and @sentry/rollup-plugin from sentry-javascript-bundler-plugins. The v10 line needs the same change there.

Sentry events

Before, nitro.mjs has no debug ID, 7 frames unresolved: https://sentry-sdks.sentry.io/issues/7717023698/events/68bf257795504851aa62d6a642b0dd85/?project=4510555608449024
After, all frames resolved: https://sentry-sdks.sentry.io/issues/7717259820/events/9939fb348971417091c1a05b91ce5023/?project=4510555608449024

Most of the changed files are test snapshots that contain the snippet text.

…ted snippet

The debug ID snippet resolved the global object by checking `global` before
`globalThis`. A second bundling pass over an already-injected chunk can rewrite
that free `global` into a `const` declared further down the file, which Nitro's
node compat does. Reading it from the top of the file then hits the temporal
dead zone, where `typeof` throws instead of returning "undefined", and the
snippet's own try/catch swallowed the error. The chunk registered no debug ID
and its frames stayed unsymbolicated.

Checking `globalThis` first means the other identifiers are never evaluated in
any runtime that has it.

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

linear-code Bot commented Oct 14, 2026

Copy link
Copy Markdown

JS-2027

@JPeer264
JPeer264 added this pull request to stack #25366 October 14, 2026 13:08
@JPeer264
JPeer264 marked this pull request as ready for review October 14, 2026 13:08
@JPeer264
JPeer264 requested a review from a team as a code owner October 14, 2026 13:08
@JPeer264
JPeer264 requested review from chargome and s1gr1d and removed request for a team October 14, 2026 13:08
@JPeer264

Copy link
Copy Markdown
Member Author

bugbot run

@JPeer264 JPeer264 self-assigned this Oct 14, 2026
@JPeer264
JPeer264 requested review from nicohrubec and removed request for chargome October 14, 2026 13:09

@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 57ee188. Configure here.

This branch has not been deployed

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

1 participant