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
Inconsistent (JS) Output Hashes with emitted CSS files #3697
Comments
I believe this may be #3415 (see https://bundlers.tooling.report/hashing/asset-cascade/#rollup). |
Nothing changes though so I didn't think it was related |
I've also spent some time on augmentChunkHash to no avail. The issue persisted here with or without it. I left it out since it wasn't necessary for reproduction |
Additional things I have tried:
They all have no effect. It feels like there's an async step that isn't properly awaited somewhere; and so some builds do get to use that info-block as part of hash calculation, while others don't/aren't aware of that extra bit of information. |
This reproduces with older dependencies in the sample project, so it doesn't seem like a recent regression:
I also tried making the |
@benmccann thank you 🙏 I was going to walk through Rollup version history tomorrow |
My guess is that it is a race condition that depends on the order in which your modules resolve, load or transform. Would need a little more digging but if that is the case, it might be solvable by manually sorting some internal data structures once the graph is complete. |
That sounds like it could fit what I'm experiencing. Thank you for taking a look :) |
It turns out the issue stems from the fact that two assets with the same name "index" are emitted. When an asset is emitted, Rollup assigns a reference id to that asset. To make things reproducible, this id is based on a hash of the asset name. In case there are two assets with the same name, the second one of course will receive a different reference id, however it depends on the load order which is the second one. I believe the only way to make this more stable is to add information about how the file was emitted to the hash of the reference id, let's see. |
And of course the reference if is relevant because at the time when the hashing happens, the |
Actually it turns out this is quite tricky to fix as the plugin context at the moment does not "know" from what hook and associated with what file id it is called. Although this is not pretty, I would rather hope to fix this by fixing the hashing altogether. |
So if I understand correctly, you're saying that the internal reference IDs are different despite pointing to the same emitted asset? Even though those referenced files are built consistently, each of the reference importers are assuming/working with a different reference value. Because of this, the importers are generated with varying hash outputs? // Foo/index.css
//=> index.1234.css
// Hello/index.js
import style from '../Foo/index.css';
//=> import.meta.ROLLUP_FILE_URL_123
//=> index.1234.js
// World/index.js
import style from '../Foo/index.css';
//=> import.meta.ROLLUP_FILE_URL_456
//=> index.4567.js Assuming that's true – I'm still not sure how/why that would differ between builds. Something is non-deterministic (or a race condition --> not considered at time of determination) |
Well, the non-determinism is that the order in which the transform hooks for
Still, we could try to at least use the same id for assets that have the same source when initially emitted, hm. |
What happens when the emitted |
When there is neither a |
Gotcha, okay. Because I've tried without |
Should be finally fixed with #4543 |
This issue has been resolved via #4543 as part of rollup@3.0.0-7. Note that this is a pre-release, so to test it, you need to install Rollup via |
This issue has been resolved via #4543 as part of rollup@3.0.0-8. Note that this is a pre-release, so to test it, you need to install Rollup via |
This issue has been resolved via #4543 as part of rollup@3.0.0. You can test it via |
Expected Behavior
The generated file hashes should be identical between builds since nothing is changing.
Actual Behavior
Within ~10 builds of the same source files, there will be files that have different build hashes despite having identical output content – or in most cases, identical content except for import statements to other files that also inexplicably change.
In the repro provided (please see readme), there are two files that will have different output hashes within a 10-build loop. They have a maximum of 2 hash variations per file, which I find odd.
It seems to happen with a particular combination of shared dependency trees, dynamic imports, and CSS files (emitted as assets). I dumbed it down considerably, but it's by no means a farfetched application setup.
Thanks~!
The text was updated successfully, but these errors were encountered: