Skip to content

fix(css): keep Lightning CSS module names stable for ?inline imports (fix #23735) - #23736

Open
everton-dgn wants to merge 9 commits into
vitejs:mainfrom
everton-dgn:fix/lightningcss-inline-module-hashes
Open

everton-dgn wants to merge 9 commits into
vitejs:mainfrom
everton-dgn:fix/lightningcss-inline-module-hashes

Conversation

@everton-dgn

@everton-dgn everton-dgn commented Oct 12, 2026 •

Copy link
Copy Markdown

Fixes #23735.

With css.transformer: 'lightningcss', a CSS Module imported normally and with ?inline gets different class names. compileLightningCSS passes removeDirectQuery(id) as the filename, so inline stays in the path Lightning CSS hashes, and the selectors in the ?inline string don't match the module's exports.

By default Lightning CSS prefixes names with a hash of the filename, and its docs describe [hash] as "a hash of the full file path" (CSS modules docs). So whatever Vite passes as the filename is the hash input. Vite already removes ?direct from it for this reason (#19481), and this PR does the same for inline.

inline parameters are removed, with values and repeats, only when CSS Modules is enabled for the file. The path and the other parameters keep their bytes and order, so vue&type=style&index=0 keeps its own names and ?inline-css is untouched. Plain CSS and cssModules: false keep the full query in the filename seen by Lightning CSS visitors.

How this differs from #23371: that PR targeted #22957, changed both transformers, passed cleanUrl(filename) to Lightning CSS and added generic-names. It was closed with a link to this comment, which treats the PostCSS case as a postcss-modules bug. This PR leaves PostCSS alone and adds no dependency. I didn't use cleanUrl because it drops the whole query: App.vue?vue&type=style&index=0&lang.module.css and index=1 would both hash /App.vue and get the same names.

#22957 (PostCSS with a string generateScopedName) is not fixed here. Nuxt's ?inline&used isn't covered either, since used is kept.

Framework-free repro: https://github.com/everton-dgn/vite-lightningcss-inline-repro. pnpm install && pnpm check fails on Vite 8.3.4 and passes against a local build with this patch.

Validation:

  • CSS unit tests: 65 passed, covering matching names, semantic query identity and visitor filenames when module processing is inactive.
  • pnpm run test-serve css: 147 passed, 42 skipped.
  • pnpm run test-build css: 151 passed, 38 skipped.
  • pnpm run test-serve-bundled css: 135 passed, 44 skipped, 10 todo.
  • pnpm run typecheck, ESLint and Oxfmt passed. The full monorepo suite was not run locally.

AI disclosure: AI tools were used to investigate the bug, write the patch and tests, and draft this description. I reviewed every change in the diff and ran the checks listed above.

@everton-dgn

Copy link
Copy Markdown
Author

Could someone rerun the macOS job?

css-codesplit uses the default PostCSS transformer, so it does not reach the changed compileLightningCSS function.

These failures already occurred on main with Node 24 on macOS during bundled dev: the stylesheet assertion in run 37743896832 and the module assertion in run 36839299914. The previous commit here, c7414917, has the same code and passed the same macOS job in run 38215978087. The merge after it only changed docs/guide/env-and-mode.md.

@everton-dgn

Copy link
Copy Markdown
Author

Could someone rerun the Ubuntu/Node 26 and macOS/Node 24 jobs in run 38320165323?

Both fixtures use the default PostCSS transformer, so neither reaches the changed compileLightningCSS code. Both tests have already failed on main with the same assertion:

  • csp > dynamic css, expected 'black' to be 'red', in Test serve on Ubuntu/Node 24: job 112698453262.
  • css-codesplit > should load all stylesheets, expected 'black' to be 'green', in bundled dev on macOS/Node 24: job 113200804143.

Both spec files also pass locally on macOS, on head e56e4cdd and base dce9fe69.

everton-dgn added a commit to everton-dgn/boilerplate_solidjs that referenced this pull request Oct 23, 2026
Update filesystem-routing to 0.4.1, which keeps the route scan order on
watcher updates (solidjs/filesystem-routing#28) and removes watched routes
by the file that added them, so its Bun patch is dropped. The generated
route declarations now type each ref by its picked exports. The middleware
comment no longer claims that the API handler only takes a Request.

Update vite-plus and vite-plus-core to 1.4.0. The CSS Modules patch still
applies unchanged, since vitejs/vite#23736 is not in this release, and
moves to the new version key. The bundled oxlint now asks for String.raw
in the relative import restriction regex.

Update the Node runtime to the 24.22.1 security release and raise the
engine floor to match.
@everton-dgn

Copy link
Copy Markdown
Author

Could someone rerun just the Windows / Node 26 job on d0cfc38e1? The PR job and an earlier Windows job on main both timed out waiting for /hot updated/ in the same bundled-dev HMR test (acceptExports, dynamic import). The HMR spec passed locally on macOS.

The original Ubuntu / Node 26 failure was separate. The two CSS sourcemap builds shared an output directory, so one could remove the script referenced by the other's HTML. The variants now build in separate directories, and the Ubuntu job passed.

This branch has not been deployed

No deployments
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.

Lightning CSS generates different CSS Module names for normal and ?inline imports

1 participant