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

[Bug]: CSS Modules [hash] can occasionally be zero length if is entirely numeric #8735

Open
daveskybet opened this issue Dec 16, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@daveskybet
Copy link

System Info

System:
OS: macOS 14.6.1
CPU: (10) arm64 Apple M1 Pro
Memory: 454.94 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.9.0 - ~/.asdf/installs/nodejs/20.9.0/bin/node
Yarn: 4.4.0 - ~/.asdf/installs/nodejs/20.9.0/bin/yarn
npm: 10.1.0 - ~/.asdf/plugins/nodejs/shims/npm
Watchman: 2024.01.22.00 - /opt/homebrew/bin/watchman
Browsers:
Chrome: 131.0.6778.140
Safari: 17.6
npmPackages:
@rspack/cli: latest => 1.1.6
@rspack/core: latest => 1.1.6

Details

If the hash of a module name/path is entirely numeric the resultant hashed classname has a zero length (due to the removing of numeric characters at the start of the class name), i.e.

generator: {
  localIdentName: "[hash]-[local]",
},

for a module with a path/name of:

./node_modules/@ppb/the-wall-web/components/walls/Badge/Badge.css

results in a completely numeric hash of:

9200104150574146

(default settings of xxhash64/hex/16 - although have also had the same with md4 on a different module)

which due to the existing logic to not have a class name starting with a numeric character will continually remove the first character until the hash has a length of zero, resulting in class names such as:

{
  "badgeComponent": ".-badgeComponent",
  "badgeComponentGameInfo": ".-badgeComponentGameInfo",
  "rouletteNumbers": ".-rouletteNumbers",
  "rouletteNumbersBackground": ".-rouletteNumbersBackground",
}

Webpack currently has a solution for checking for this edge case and providing an alternative hash here:

https://github.com/webpack/webpack/blob/964c0315df0ee86a2b4edfdf621afa19db140d4f/lib/css/CssModulesPlugin.js#L437
https://github.com/webpack/webpack/blob/964c0315df0ee86a2b4edfdf621afa19db140d4f/lib/util/nonNumericOnlyHash.js

Which doesn't appear to have an equivalent in Rspack.

Reproduce link

No response

Reproduce Steps

  • Any Rspack app with the localIdentName set to [hash]-[local]
  • Have a css module file at a path that results in a completely numeric hash (as per the description ./node_modules/@ppb/the-wall-web/components/walls/Badge/Badge.css results in a completely numeric hash (with the default xxhash64 setting)
  • See the output classnames being broken (as the hash is zero length and now starts with a special character)
@daveskybet daveskybet added bug Something isn't working pending triage The issue/PR is currently untouched. labels Dec 16, 2024
@inottn inottn removed the pending triage The issue/PR is currently untouched. label Dec 17, 2024
@inottn
Copy link
Collaborator

inottn commented Dec 18, 2024

nonNumericOnlyHash is unrelated to localIdentName. The logic for localIdentName is here. This logic has recently changed, causing rspack to currently be inconsistent with webpack. Simply put, when a class name starts with a digit, webpack prefixes the class name with a '_'.

@daveskybet
Copy link
Author

Thanks for the correction @inottn, and seems like a simple enough correction to bring back inline with Webpack so have spun up a PR mentioned above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants