fix(sourcemaps): Don't treat .map files as JavaScript when injecting - #3003
Merged
szokeasaurusrex merged 6 commits intoDec 10, 2025
Merged
szokeasaurusrex merged 6 commits into
szokeasaurusrex merged 6 commits into
Conversation
The inject command was incorrectly passing "map" as a JavaScript extension to inject_debug_ids(), causing .map files to be processed for JavaScript injection. This corrupted sourcemap files by injecting the debug ID runtime snippet into them. Root cause: In inject.rs, the extensions array included "map" for file discovery, but this same array was passed to inject_debug_ids() which expected only JavaScript extensions for filtering injection candidates. Fix: Separate js_extensions (for injection filtering) from search_extensions (for file discovery). Only pass js_extensions to inject_debug_ids() so .map files are filtered out during injection. Added regression test that verifies .map files never get JavaScript code injected, even if they could be misclassified as MinifiedSource.
fhaehnel-figma
requested review from
a team and
szokeasaurusrex
as code owners
December 2, 2025 16:37
Contributor
Author
|
Hey @szokeasaurusrex! We'd really appreciate eyes on this, it's causing us quite a lot of pain when trying to route our issues to the right teams at the moment! 🙏🏻 |
Member
|
Hi @fhaehnel-figma, this is on my radar, I'll get back to you within the next few days |
.map files as JavaScript when injecting
szokeasaurusrex
approved these changes
Dec 10, 2025
Member
|
@loewenheim, would appreciate a second review from you here, since I also made some changes to this |
loewenheim
approved these changes
Dec 10, 2025
loewenheim
left a comment
Contributor
There was a problem hiding this comment.
LGTM, thanks for fixing this!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The inject command was incorrectly passing "map" as a JavaScript extension to
inject_debug_ids(), causing.mapfiles to be processed for JavaScript injection. This corrupted sourcemap files by injecting the debug ID runtime snippet into them.Root cause: In
inject.rs, the extensions array included "map" for file discovery, but this same array was passed toinject_debug_ids()which expected only JavaScript extensions for filtering injection candidates.Fix: Separate
js_extensions(for injection filtering) fromsearch_extensions(for file discovery). Only passjs_extensionsto inject_debug_ids() so.mapfiles are filtered out during injection.Added regression test that verifies .map files never get JavaScript code injected, even if they could be misclassified as MinifiedSource.
Background
The Bug: The
sourcemaps injectcommand could corrupt.mapfiles by injecting JavaScript code into them, causing subsequent validation failures.This only happens sometimes, and can usually be worked around by re-running the command.
Root Cause:
src/commands/sourcemaps/inject.rs, the code built anextensionsarray containing["js", "cjs", "mjs", "map"]for file discoveryinject_debug_ids()as thejs_extensionsparameterinject_debug_ids()atsrc/utils/sourcemaps.rs:758, there's an extension filter:sourcemap_referencesHashMap as a source (rather than as a sourcemap), it would be processed as a JavaScript file and have the debug ID runtime snippet injected into itWhy It's Non-Deterministic
The non-determinism comes from Rust's HashMap iteration order:
sourcemap_referencesfield in SourceMapProcessor is aHashMap<String, Option<SourceMapReference>>(line 196 of sourcemaps.rs)for (source_url, sourcemap_url) in self.sourcemap_references.iter_mut()Issues