Repository navigation
fix(webpack): keep source map positions in app-css-loader - #11646
Merged
Merged
Conversation
app-css-loader prepends two lines to the app entry module (a comment and the app css import) but passed the incoming source map through unchanged. Every position in the entry file was then resolved against a map for the unprefixed code, so stack frames and breakpoints in it landed a few lines off. Offset the map with webpack's ConcatSource/SourceMapSource instead, and stop running the module code through ts-dedent.
|
View your CI Pipeline Execution ↗ for commit 55cf982
💡 With Ultracache enabled, Nx Cloud learns each task's file inputs in CI and uses them on later runs. Turn on Ultracache in workspace settings ↗ · Read docs ↗ ☁️ Nx Cloud last updated this comment at |
commit: |
3 of 5 tasks
farfromrefug
approved these changes
Nov 20, 2026
NathanWalker
approved these changes
Nov 21, 2026
NathanWalker
left a comment
Contributor
There was a problem hiding this comment.
Using sources.ConcatSource (RawSource prefix + SourceMapSource) cleanly offsets the incoming map by the prepended CSS import lines, and dropping ts-dedent avoids unintended indentation changes on the entry module. Passing the raw prefix through when map is absent and covering all three paths in app-css-loader.spec.ts looks great.
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.
PR Checklist
__tests__/configurationsuites fail onmaintoo, with the same 14 tests: stale snapshots andTS2550onArray.prototype.at. Everything else passes, including the new spec.)What is the current behavior?
app-css-loaderruns as apostloader on the app entry module. When anapp.css/app.scsssits next to the entry, it prepends two lines (// Added by app-css-loaderand the css import) but returns the incoming source map unchanged. Every position in the entry file is then looked up in a map made for the code without those two lines, so stack frames and breakpoints in that file resolve to the wrong line. The error isn't a constant two lines, because TypeScript emit changes line counts (removeddeclarestatements and so on).Seen in a scratch app reporting to Sentry: the throw on
app.ts:28was reported as:31, and its caller on:62as:64. Sentry and a localSourceMapConsumerlookup agreed with each other, and the map'ssourcesContentmatched the file, so the upload was fine and the map itself was wrong. Only the entry file is affected.What is the new behavior?
The loader builds the output with webpack's
sources(ConcatSourceof aRawSourceprefix and aSourceMapSourceof the module) and returns that map, so positions after the prefix keep their original lines and columns. Without an incoming map it just prepends the import. It also stops passing the module code throughts-dedent, which could re-indent it.New spec
__tests__/loaders/app-css-loader.spec.ts:app.tswith its source map, asts-loaderdoes;throwand a call still resolve to their original lines (this failed before the fix: line 6 resolved to 9);Also checked on a real production bundle (Terser-minified ESM,
devtool: 'source-map') with the patched loader: the throw maps toapp.ts:28and the inlined call to:62:2, matching the source.Two other loaders rewrite code and pass the old map through:
native-class-downlevel-loader(replaces@NativeClassclasses with an ES5 transpile beforets-loader) andnative-class-strip-loader(changes line counts only for multi-line decorator arguments). They need a composed map rather than an offset, so they're left for a separate change.