-
Notifications
You must be signed in to change notification settings - Fork 29
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
mini-css-extract-plugin logic is broken #29
Comments
Updated the report to highlight why this is broken for both chunkhash and contenthash. |
Here's an MVP reproduction of the bug: https://glitch.com/edit/#!/standing-flashy-slouch If you change the chunk loaded in the HTML from There are a couple of ways around this:
At the file
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
webpack-plugin-hash-output/src/OutputHash.js
Line 76 in 0b4adc2
The code added for mini-css-extract doesn't appear to work.
For CSS, we have a problem; if the user configured mini-css-extract-plugin with
[chunkhash]
in the filename, we'll wind up with that same chunkhash in both the JS and CSS filename. When we do the global replace, it'll replace all instances of that chunkhash with either the JS or CSS content hash depending on the order this code runs. So one of them will always fail. @GoodForOneFare pointed this out in his original pr. I think we could just throw an error if more than one file containschunk.renderedHash
.Using chunkhash with mini-css-extract-plugin appears to be wrong anyway, you're supposed to use contenthash. That's handled in the 'this is a massive hack' section, which looks for a module hash matching the one in the filename. But this breaks if the same CSS module is included in multiple chunks:
Supposed we have chunk A and B
A.files: [foo-abcd.css, ...]
B.files: [foo-abcd.css, ...]
On chunk A, we'll look for a module that has hash
abcd
. We find it and proceed normally, adding it to nameMap and updating the hash/renderedHash of the module itself. Now the module has hashhashed
, and the asset is renamed tofoo-hashed.css
.A.files: [foo-hashed.css, ...]
B.files: [foo-abcd.css, ...]
nameMap: { 'abcd': 'hashed' }
Now we're processing chunk B. We'll still be looking for a module hash 'abcd'. However, that module has been mutated when processing chunk A, so we never find it. As a result, chunk B and any following chunks will continue to emit their old chunk names. However, since the mapping from
abcd -> hashed
is in nameMap, we're rewriting all the runtime files to referencehashed
, and this results in broken module loading.I think the correct solution here is to look at
chunk.contentHash
; if any of the values there match the filename, we can use that asoldChunkName
. This avoids mutating any modules.The text was updated successfully, but these errors were encountered: