fix(css): rewrite root-relative dev CSS sourcemap sources (fixes #23195) - #23281
Open
santhiprakash wants to merge 3 commits into
Open
fix(css): rewrite root-relative dev CSS sourcemap sources (fixes #23195)#23281santhiprakash wants to merge 3 commits into
santhiprakash wants to merge 3 commits into
Conversation
- Problem: lightningcss URL-served CSS maps kept project-root-relative `sources` entries; transformRequest only rebased absolute paths. - Fix: resolve non-absolute sources against the module dir or project root, then emit paths relative to the served CSS file URL. - Verification: pnpm run test-serve sources-resolution.spec (2 passed).
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.
Problem
With
css.devSourcemap: true, URL-served CSS sourcemaps can keep project-root-relativesourcesentries (Shape 3 in #23195).transformRequestonly rebased absolute paths to be relative to the served module, so browsers resolve those entries against the CSS URL incorrectly and devtools fail to load the underlying files.Triage
main(2026-08-17): bug still present inpackages/vite/src/node/server/transformRequest.ts.main, not a duplicate approach.Fix
When rewriting sourcemap
sources, resolve non-absolute paths against the module directory or project root (whichever keeps the path inside the project), then emit paths relative to the served CSS file URL.Verification
pnpm run build pnpm exec vitest run -c vitest.config.e2e.ts \ playground/css-sourcemap/__tests__/sources-resolution.spec.ts \ playground/css-sourcemap/__tests__/lightningcss/sources-resolution.spec.tsResult: 2 files, 2 tests passed.
Risks
Low — scoped to dev sourcemap path rewriting in
transformRequest; no build output changes.fixes #23195