Skip to content

fix(css): rewrite root-relative dev CSS sourcemap sources (fixes #23195) - #23281

Open
santhiprakash wants to merge 3 commits into
vitejs:mainfrom
santhiprakash:fix/css-sourcemap-sources-rebased
Open

fix(css): rewrite root-relative dev CSS sourcemap sources (fixes #23195)#23281
santhiprakash wants to merge 3 commits into
vitejs:mainfrom
santhiprakash:fix/css-sourcemap-sources-rebased

Conversation

@santhiprakash

Copy link
Copy Markdown
Contributor

Problem

With css.devSourcemap: true, URL-served CSS sourcemaps can keep project-root-relative sources entries (Shape 3 in #23195). transformRequest only 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

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.ts

Result: 2 files, 2 tests passed.

Risks

Low — scoped to dev sourcemap path rewriting in transformRequest; no build output changes.

fixes #23195

- 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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dev CSS sourcemaps: sources are written against the wrong base

1 participant