Skip to content

sourcemap inject/upload adds a second debug ID snippet to files that already register one (Oxc-minified, React Native Metro), shifting the source map by one line #2267

Closed

Description

@esetnik

Summary

Since sentry 0.46.0, sentry sourcemap inject and sentry sourcemap upload prepend a runtime registration snippet to a file that already has one, if the existing snippet was rewritten by a minifier. The new snippet goes on a new first line and the source map gets a leading ;.

With @sentry/vite-plugin 11.12.0 on Vite 8 (rolldown), this breaks symbolication. The plugin injects its snippet in renderChunk, the minifier rewrites it, and the plugin then uploads a prepared copy of each chunk through sentry sourcemap upload. The uploader changes that copy, so the uploaded file and map are one line ahead of the file that is deployed. Frames resolve to the wrong function, or fail with js_invalid_sourcemap_location.

0.45.0 does not do this.

Versions

  • sentry 0.46.0, 0.47.0, 0.48.0, 0.49.0: affected
  • sentry 0.45.0: not affected
  • Found through @sentry/vite-plugin 11.12.0 (which depends on sentry ^0.49.0), vite 8.3.8

Minimal reproduction

No bundler or Sentry account needed.

a.js, where the snippet uses backtick strings as a minifier would write it:

(function(){try{var e=typeof globalThis<`u`?globalThis:{};var t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]=`11111111-2222-4333-8444-555555555555`,e._sentryDebugIdIdentifier=`sentry-dbid-11111111-2222-4333-8444-555555555555`)}catch{}})();console.log("hello");
//# sourceMappingURL=a.js.map
//# debugId=11111111-2222-4333-8444-555555555555

a.js.map:

{"version":3,"file":"a.js","sources":["a.ts"],"sourcesContent":["console.log(\"hello\");"],"names":[],"mappings":"AAAA","debug_id":"11111111-2222-4333-8444-555555555555","debugId":"11111111-2222-4333-8444-555555555555"}

Run:

npx sentry@0.49.0 sourcemap inject .

Actual result

a.js gains a new first line, with the same debug ID:

;!function(){try{var e="undefined"!=typeof window?window:...;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="11111111-2222-4333-8444-555555555555",...)}catch(e){}}();
(function(){try{var e=typeof globalThis<`u`?globalThis:{};...

and mappings in a.js.map changes from AAAA to ;AAAA.

Expected result

The file already has a debug ID comment and a working registration snippet for that ID, so it should be left unchanged, as 0.45.0 leaves it.

What triggers it

Same file, same map, only the quoting inside the existing snippet differs:

sentry version Snippet with "..." strings Snippet with `...` strings
0.45.0 unchanged unchanged
0.46.0 to 0.49.0 unchanged snippet prepended, map shifted

So the check for an existing snippet does not recognise the form a minifier produces. Vite 8's minifier turns the plugin's e._sentryDebugIds[n]="<id>" into e._sentryDebugIds[t]=`<id>` .

Effect through the Vite plugin

The plugin copies each chunk to a temporary folder, appends //# debugId=, and runs the upload on the copies. The deployed files are not touched. After the upload:

  • deployed chunk: N lines
  • uploaded chunk: one extra line at the top
  • uploaded map: on-disk mappings with ; prepended

Browsers report positions in the deployed file, so every lookup lands one line early in the uploaded map. A frame on a line that has no mappings in the shifted map fails with js_invalid_sourcemap_location; others resolve to the last token of the previous line. The plugin still logs "Successfully uploaded source maps to Sentry".

I confirmed this by downloading the uploaded artifact bundle and comparing it with the build output: the uploaded mappings equal ";" + the on-disk mappings.

Additional findings

While testing the fix I ran each snippet form this CLI recognises through several minifiers and then through injectDirectory, expecting the file to be left unchanged.

A second form is missed: Turbopack's snippet after Oxc. Turbopack initializes the registry inline:

n&&((e._debugIds||(e._debugIds={}))[n]="<id>")

Oxc folds that into a logical assignment, and also switches to a template literal:

t&&((e._debugIds||={})[t]=`<id>`)

The check only knows the long form, so this is missed even once template literals are accepted. A Turbopack chunk that is minified again by Oxc gets a second snippet in the same way.

Only Oxc triggers either problem. Five snippet forms (bundler plugin, this CLI, legacy CLI, formatted bracket form, Turbopack) through 20 minifier setups, 100 cases:

Minifier Setups Changes the quoting Folds the initialization
terser 5.51.2 default, ES2022 with 3 passes and unsafe, single quotes, beautify, no mangle no no
swc 1.16.22 default, ES2022 with 2 passes, no compress no no
esbuild 0.28.2 default, esnext, es2015, syntax only no no
Oxc (rolldown 1.2.19) default, no mangle, no compress, es2015, es2020, esnext, whitespace kept yes, whenever it removes whitespace yes, for Turbopack's form, when compressing for ES2021 or later
  • On main, Oxc's output is missed for every snippet form in every setup that removes whitespace. Compression and mangling make no difference to the quoting: the template literals come from code generation. With whitespace kept, Oxc leaves the quotes as written.
  • With template literals accepted, 96 of 100 pass. The 4 that fail are Turbopack's snippet under Oxc.
  • With the logical assignment accepted as well, all 100 pass.

File layout does not matter. With the Oxc-minified bundler plugin snippet and both changes, 15 layouts were all left unchanged: the debug ID comment before or after sourceMappingURL, no trailing newline, CRLF, a hashbang first, a "use strict" directive first, the snippet after other code, an uppercase ID, a 32-hex ID, the ID only in the map (debug_id or debugId), the ID only in the comment, a legacy //@ sourceMappingURL, and an inline map with and without the comment. So the //# debugId= and sourceMappingURL patterns are not affected.

A third form is missed, with no minifier involved: the React Native Metro plugin's snippet. It registers on a bare global variable instead of a property of the global object:

var _sentryDebugIds,_sentryDebugIdIdentifier;void 0===_sentryDebugIds&&(_sentryDebugIds={});try{var stack=(new Error).stack;stack&&(_sentryDebugIds[stack]="<id>",_sentryDebugIdIdentifier="sentry-dbid-<id>")}catch(e){}

The check requires a . or a bracketed name before the registry, so _sentryDebugIds[stack]= is not matched. With that snippet, a //# debugId= comment and a map carrying the same ID:

sentry version Result of sourcemap inject
0.45.0 unchanged
0.49.0 snippet prepended, mappings shifted

The same happens with a real Metro bundle: metro 0.88.0 with createSentryMetroSerializer from @sentry/react-native 8.35.0, minified or not. 0.45.0 leaves the bundle unchanged; 0.49.0 and current main prepend a snippet. The bundle had a plain JS entry file, so a full React Native app build is not tested.

uglify-js 3.19.3, Bun 1.4.4 and Closure Compiler v20240317 (WHITESPACE_ONLY and SIMPLE) were also checked and leave the snippets recognisable. Closure's ADVANCED level renames the _sentryDebugIds property itself, so the bundle stops registering and a new snippet is the right outcome.

Fix

Submitted in #2268. It makes the existing-snippet check accept template literals as well as quoted strings, the registry initialization written as ||= or ??=, and the registry as a bare global.

Activity

  1. linear-code commented on Nov 14, 2026

    @linear-code
  2. changed the title [-]`sourcemap inject`/`upload` adds a second debug ID snippet when the existing one was minified, shifting the uploaded source map by one line[/-] [+]`sourcemap inject`/`upload` adds a second debug ID snippet to files that already register one (Oxc-minified, React Native Metro), shifting the source map by one line[/+] on Nov 14, 2026
  3. added a commit that references this issue on Nov 16, 2026
    aa80347
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions