Skip to content

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

Open
santhiprakash wants to merge 1 commit into
vitejs:mainfrom
santhiprakash:fix/css-sourcemap-sources-shape3
Open

fix(css): rewrite root-relative dev CSS sourcemap sources (fixes #23195)#23205
santhiprakash wants to merge 1 commit into
vitejs:mainfrom
santhiprakash:fix/css-sourcemap-sources-shape3

Conversation

@santhiprakash

Copy link
Copy Markdown
Contributor

Problem

With css.devSourcemap: true and css.transformer: 'lightningcss', URL-served CSS sourcemaps keep sources entries relative to the project root (e.g. nested/dir/dep.css). The map is resolved against the CSS file URL, so those names double the path (/nested/dir/nested/dir/dep.css). Postcss URL-served maps were already correct because absolute sources get rebased in transformRequest.

Fixes #23195 (Shape 3).

Triage / Root cause

transformRequest rebases sourcemap sources to paths relative to the served module file, but only when path.isAbsolute(sourcePath). Lightningcss emits root-relative names that slip through unchanged.

Fix

  • Resolve non-absolute sources against the module directory or project root (whichever yields a valid relative path), then emit paths relative to the served file URL.
  • Add playground coverage for URL-served CSS source resolution (postcss regression + lightningcss fix).

Verification

  • pnpm run test-serve sources-resolution.spec — 2 passed
  • pnpm exec vitest run src/node/server/__tests__/transformRequest.spec.ts — 4 passed

Notes / Risks

- 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