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

Incorrect hash for dynamic CSS files not using contenthash, #17

Closed
isidrok opened this issue Sep 15, 2018 · 5 comments
Closed

Incorrect hash for dynamic CSS files not using contenthash, #17

isidrok opened this issue Sep 15, 2018 · 5 comments

Comments

@isidrok
Copy link

isidrok commented Sep 15, 2018

Hi, when using prerender-loader in conjunction with mini-css-extract-plugin there is an error loading CSS imported by dynamic-chunks when the hashing strategy is different from contenthash for that css file.

In that case, prerender-loader outputs a link pointing to a CSS file with a different hash.

Note that this doesn't apply to JS files nor to CSS files imported by the main (entrypoint) chunk.

A full reproduction is in https://github.com/isidrok/prerender-loader-reprod, look at the readme for more information.

The original discussion is in GoogleChromeLabs/critters#7

@developit
Copy link
Collaborator

This should be fixed now as long as you upgrade to the latest (0.4.4) mini-css-extract-plugin!

@developit
Copy link
Collaborator

Closing since you gave it a thumbs up - let me know if you're still hitting issues!

@isidrok
Copy link
Author

isidrok commented Nov 4, 2018

Just tried with the new version of mini-css-extract-plugin and neither critters nor prerender-loader output any error but the referenced css file is still incorrect for dynamically imported modules.

If I remove prerender-loader and just use Critters the following error is thrown:
TypeError: Cannot read property 'textContent' of undefined.

The css file referenced in the bundle under the comment mini-css-extract-plugin CSS loading is correct though.

After looking at the mini-css-extract-plugin source it seems they are handling hashes on the hashForChunk and contentHash hooks, maybe that happens after prerender-loader does its work, will check later.

Edit: after debugging the reproduction repo I saw that mini-css-extract-plugin hooks are running twice, once before prerender-loader and once again inside (it is beign added to the new compiler plugins), and it seems different assets (with different names) are being generated on each compilation which seems normal since using hash is supposed to create a different hash for each build?

Anyways I'm using contenthash and it works just fine so it may be enough with having this issue as reference...

@isidrok
Copy link
Author

isidrok commented Nov 4, 2018

Summarizing the previous comment:

My guess is that since prerender-loader is creating a new compilation, when using a hash different from contenthash it changes during that specific build and doesn't reference the assets of the main compilation.

@developit
Copy link
Collaborator

That makes sense. Perhaps it'd be worth having the plugin warn when [hash] is used.

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

No branches or pull requests

2 participants