You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
webpack/rspack: transform hook sourcemaps are dropped or not composed #616
The webpack and Rspack adapters do not preserve source maps returned by a transform hook correctly:
When the loader has no input source map, the adapter discards res.map.
When both an input map and res.map exist, the adapter forwards only res.map instead of composing both mapping layers, so mappings from earlier loaders are lost.
As a result, the generated bundle reports incorrect original source locations even though the transform hook returns a valid source map.
The reproduction uses [email protected] and @rspack/[email protected]. Both cases run an unplugin transform that prepends one generated line and returns the corresponding high-resolution source map. The second case also runs a preceding loader that prepends a line and returns its own source map.
Actual result:
without-input-map: expected source line 1, received line 2
with-input-map: expected source line 1, received line 2
Expected behavior
The map returned by the transform hook should be preserved. The generated statement should trace back to line 1 of src/index.js in both cases, so pnpm repro should succeed.
When an input map is also present, the adapter should compose the transform map with the input map so the complete loader chain is retained.
Root cause
Both webpack-like transform loaders currently use this callback logic:
This explicitly passes a nullish input map when no input map exists, dropping res.map. When both maps exist, it selects one map without composing them.
This is related to #154 and follows up on #561 / #562: exposing inputSourceMap makes manual composition possible, but the adapter output still does not preserve the complete transform chain by default.
The thing that makes this class of bug expensive is that a dropped or uncomposed map is indistinguishable from a good one at rest. It parses, it loads, the debugger opens it, and nothing anywhere says the positions stopped being true.
It is measurable from the two artifacts alone, though, without knowing which hook dropped what. Three properties hold for the output of any correct generator: a mapping never points past the end of a line, never lands strictly inside an identifier, and when it carries a name the original source at that position starts with that name.
I ran that over esbuild and tsc output first as a control, because a check that flags everything is worth nothing: 371 mappings and 26 names, zero violations. Then I prepended three lines to an already-mapped bundle without recomposing, which is the same shape as a transform hook returning code and no map: 88 of 93 mappings stopped landing on a token. The two cases separate cleanly, so the condition is testable rather than only reportable.
Activity
tamerkalla commentedon Sep 5, 2026
The thing that makes this class of bug expensive is that a dropped or uncomposed map is indistinguishable from a good one at rest. It parses, it loads, the debugger opens it, and nothing anywhere says the positions stopped being true.
It is measurable from the two artifacts alone, though, without knowing which hook dropped what. Three properties hold for the output of any correct generator: a mapping never points past the end of a line, never lands strictly inside an identifier, and when it carries a
namethe original source at that position starts with that name.I ran that over esbuild and tsc output first as a control, because a check that flags everything is worth nothing: 371 mappings and 26 names, zero violations. Then I prepended three lines to an already-mapped bundle without recomposing, which is the same shape as a transform hook returning code and no map: 88 of 93 mappings stopped landing on a token. The two cases separate cleanly, so the condition is testable rather than only reportable.
If that is useful for pinning this as a regression test, the check is one function over the built code and the parsed map: https://www.npmjs.com/package/sourcemap-truth