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(index): assign empty module.id to prevent contenthash from changing unnecessarily #284

Merged
merged 2 commits into from Oct 2, 2018

Conversation

lfre
Copy link
Contributor

@lfre lfre commented Sep 22, 2018

Content hashes change when the entries order or length changes

  • Checks sourceMap before JSON.stringify, because it outputs "" on an empty string, modifying the hash unnecessarily.

Reproduction: https://github.com/lfre/mini-css-extract-plugin-contenthash

Type

  • Fix

Issues

SemVer

  • Patch

@jsf-clabot
Copy link

jsf-clabot commented Sep 22, 2018

CLA assistant check
All committers have signed the CLA.

@michael-ciniawsky michael-ciniawsky added this to the 0.4.3 milestone Sep 22, 2018
@michael-ciniawsky michael-ciniawsky changed the title fix: add empty id to prevent contenthash from changing unnecessarily fix(index): assign empty module.id to prevent contenthash from changing unnecessarily Sep 22, 2018
@michael-ciniawsky
Copy link
Member

@lfre Are those test also failing locally if you run them?

@lfre
Copy link
Contributor Author

lfre commented Sep 22, 2018

@michael-ciniawsky Yes, they are. It makes sense because this would change the hashes of the expected. I imagine I have to replace those. Do I go into each test and run their webpack configs, or is there another way?

@michael-ciniawsky
Copy link
Member

Yeah, seems to be the case please double check if the file contents still match :) super annoying... 🙄

@michael-ciniawsky
Copy link
Member

The async and MemoryFS test seem to be unrelated (not 💯 sure for the async one)

@lfre
Copy link
Contributor Author

lfre commented Sep 24, 2018

@michael-ciniawsky Updated the tests. A couple things to notice:

Everything else maintains the same contents. Let me know if these are bugs or unexpected pluses. For the duped file in contenthash-multiple-entries seems like a fix. Ready for another look.

@lfre
Copy link
Contributor Author

lfre commented Sep 24, 2018

npm run test -- --runInBand passes locally, and I'm seeing cd0bb358c45b584743d8ce4991777c42.svg created locally in js/simple-publicpath, so I'm not sure what's up with that.

@lfre
Copy link
Contributor Author

lfre commented Sep 30, 2018

@michael-ciniawsky @evilebottnawi @sokra I'd appreciate some feedback here. 🙏

@@ -1,4 +0,0 @@
.styleA { background: red; }
Copy link
Member

Choose a reason for hiding this comment

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

I wonder why this file was removed..

Copy link
Contributor Author

@lfre lfre Oct 2, 2018

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

👍

@alexander-akait
Copy link
Member

Looks tests also broken 😕

@lfre
Copy link
Contributor Author

lfre commented Oct 2, 2018

@evilebottnawi Tests are passing locally using latest node 8. Only one test is failing if you see the log and my comment #284 (comment). I'm going to try downgrading to node 6 to test but I'd appreciate any other ideas on how to approach this.

@alexander-akait
Copy link
Member

/cc @sokra can we merge and release patch?

@sokra
Copy link
Member

sokra commented Oct 2, 2018

/cc @sokra can we merge and release patch?

👍

@alexander-akait alexander-akait merged commit d7946d0 into webpack-contrib:master Oct 2, 2018
@michael-ciniawsky
Copy link
Member

Released in v0.4.4 🎉

@erykpiast
Copy link

erykpiast commented Nov 7, 2018

@lfre @michael-ciniawsky I have a question about this change or module id in general. In such case, when module is somehow empty, NamedModulesPlugin creates name like ?abcdef. For regular ones (or Normal in webpack's nomenclature) it outputs something like ./foo/bar/baz.js?abcdef. Until that ?... hash is based on FULL request path (ex. /home/user/projects/foo/bar/baz.js), it's different for different repository clones, ex. on different workstations and on CI. It makes file hashes quite unpredictable as sorting modules by id gives different results on different machines and hash calculation depends on that order (hash.update('a') && hash.update('b') gives different results than hash.update('b') && hash.update('a')).

So, my question is: would it be an issue to initialize id of CssModule with something like ${dependency.id}?css? I mean some value that starts with normal module id, so module order would be stable and not really dependent on that weird hash created from full request path.

@lfre
Copy link
Contributor Author

lfre commented Nov 10, 2018

@erykpiast Yes, initially I suggested using dependency.context #281 (comment), but id would also work. If you're using CI for your deployments, this wouldn't be a problem because the path would always be the same, but I can see this being an issue for manual uploads from different workstations.

@erykpiast
Copy link

erykpiast commented Nov 10, 2018

Hey @lfre, thank you for the response! I cannot get why your solution wasn’t accepted, what was the issue with it?

In my case CI is an issue as well, repository is cloned to directory prefixed with build ID, so absolute path differs from build to build. In the worst case, file hash changes when its contents did not change, so the whole idea of hashing looses its sense.

@erykpiast
Copy link

@lfre Maybe I'll open separate issue for this?

@lfre
Copy link
Contributor Author

lfre commented Nov 18, 2018

Go for it @erykpiast

@erykpiast
Copy link

👍#308

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants