fix: sort CSS module exports for deterministic output hashes#9
Open
asurare wants to merge 1 commit into
Open
Conversation
mhsdesign
reviewed
Jun 23, 2026
mhsdesign
left a comment
Owner
There was a problem hiding this comment.
thanks for this fix, didnt know anyone uses this lib actually as esbuild kinda has modules support now (just not perfect one)
Owner
There was a problem hiding this comment.
please do not include the lock update - indeed i should update the dependencies but currently in the nmp eco system i think its better to not trust anyone;)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Object.entries(exports)iterates in the order the properties were inserted into the JS object. lightningcss is written in Rust; its internalHashMap(which backs theexportsobject it returns) uses a randomly-seeded hasher for DOS protection. The iteration order therefore differs between process invocations, even for identical input.This means the generated JS:
can become:
on the next run — same class names, different property order. esbuild hashes the chunk content, so a reordered object is a different hash, causing every chunk that transitively imports the module to also get a new hash. In a real project (~150 esbuild chunks) every single JS chunk changed hash between consecutive builds with no source changes.
The fix applied here is to simply sort exports alphabetically before generating the object literal, with :
With this fix, running esbuild with splitting enabled produces bit-for-bit identical output.