Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(css): stabilize css module hashes with lightningcss in dev mode #19481

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

azat-io
Copy link
Contributor

@azat-io azat-io commented Feb 21, 2025

Description

Hello!

After upgrading Vite from version 6.0.5 to version 6.0.6 and above, I ran into an issue with hash mismatches in CSS class names in CSS files and in markup.

I found out that the problem is related to this change:
#19001

This PR fixes an issue where CSS module hashes were inconsistent between HTML markup and compiled CSS in development mode when using LightningCSS.

The problem occurred because query parameters (like ?direct) in file IDs were affecting hash generation in LightningCSS. This was particularly noticeable in frameworks like Qwik that use query parameters for direct imports in dev mode.

Fix:

  • Normalize file IDs by removing query parameters before passing to LightningCSS
  • Maintain null byte placeholder replacement for HTML proxy cases

Before the fix:

  • CSS module hashes in HTML could be different from the ones in compiled CSS
  • This caused styling mismatches in development mode
  • The issue was particularly visible with frameworks that use query parameters for imports

After the fix:

  • CSS module hashes are stable and consistent
  • Works correctly with frameworks' development mode imports
  • Maintains compatibility with HTML proxy handling

This fix works for me fine.

If you want to reproduce the problem, you can do the following:

  1. Clone this repo and install deps
  2. Install Vite v6.0.6 or higher
  3. Start dev server with pnpm docs:dev
  4. The site's styles look weird
  5. To fix problem downgrade Vite with pnpm add --save-dev vite@6.0.5 and restart dev server

refs #10514

@azat-io azat-io force-pushed the fix/handle-null-byte-lightningcss branch from 12bb88e to 02d1e07 Compare February 22, 2025 10:51
@azat-io azat-io changed the title fix: handle null byte in module id correctly for lightningcss fix(css): stabilize css module hashes with lightningcss in dev mode Feb 22, 2025
@azat-io
Copy link
Contributor Author

azat-io commented Feb 24, 2025

I think, I should mention here @sapphi-red as the author of this PR and @patak-dev as the reviewer. I'm sorry if I disturbed you.

@sapphi-red sapphi-red added feat: css p3-minor-bug An edge case that only affects very specific usage (priority) labels Feb 25, 2025
Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: css p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants