-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
fix: apply final hashes deterministically with stable placeholders set #5644
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: apply final hashes deterministically with stable placeholders set #5644
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #5644 +/- ##
=======================================
Coverage 99.39% 99.39%
=======================================
Files 242 242
Lines 9348 9349 +1
Branches 2470 2470
=======================================
+ Hits 9291 9292 +1
Misses 48 48
Partials 9 9 ☔ View full report in Codecov by Sentry. |
Makes sense, though I guess it is probably hard to write a meaningful test. One could write a manual test that bundles the same input twice and introduces a I wonder, though, if we really need to manually sort the placeholders before iterating. There is a |
I can take a look into drafting that up. Just to insure I found what you're referring to, you're suggesting modeling that test off of this one?
Just to be clear, you're suggesting the following?
I think that could work too. As you said, it seems that the I can refactor this change with your suggested approach and vet it against my use case if you think that is preferable. I'm good either way. |
Yes, roughly, except that of course you would build twice. And note that this is an old test, you can use async-await these days to make the test much nicer ;)
That is why I would also like to have this test. As I see it, the In any case, thank you so much for looking into this and providing a solution for this issue in the first place! I know that indeterminism is a major source of pain for those affected by it, and you are making it better for everyone. If you need help, let me know, then I can also have a look at writing that test. |
Thanks for your thoughts and guidance! I'll take a swing at the test shortly and also adjust the PR to use the existing placeholder set. I'll report back once that is done or if I could use any assistance with the test. Thanks again! |
5726962
to
af0fb72
Compare
@lukastaegert I removed the sorting, switched to the stable placeholder set, and introduced a test. I validated that the test fails on I've updated the PR description to reflect the latest changes. Let me know if you'd like me to make any additional changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing, great work!
This PR has been released as part of rollup@4.22.0. You can test it via |
It appears that this might cause some build failures that need further investigation.
It appears that this might cause some build failures that need further investigation.
It appears that this might cause some build failures that need further investigation.
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Issue does not exist, but I can create one if that would be helpful.
Description
The
generateFinalHashes
iterates over therenderedChunksByPlaceholder
map in afor..of
loop, which iterates via insertion order. TherenderedChunksByPlaceholder
has key/values set asynchronously withintransformChunksAndGenerateContentHashes
. Due to this,generateFinalHashes
does not apply final hashes in the same order between builds with the same input. So, when hash collisions occur, hashes associated with collisions may apply to chunks in different order across multiple builds. This change uses the stableplaceholders
to iterate over the chunks and deterministically apply the final hashes.Why is this important?
We encountered an issue where a chunk with the same name had different file contents between builds, which then failed an SRI check on the produced asset. We expected that if the hash did not change, then the contents did not change.
What we found occurred was a manual chunk depended on two dependencies with the same name and same file contents, which then resulted in a collision. The two dependencies of the manual chunk would have their hashes flip between builds depending on who got processed first within
generateFinalHashes
. Processing chunks in the same order when applying final hashes will insure a deterministic result and avoid this problem.How this happens