-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
@wordpress/dependency-extraction-webpack-plugin
should use content hash
#34660
Comments
This will improve the long-term caching of the files by only busting caches of the files that have changed rather than busting the cache of every associated file when one does. This should also help reduce the instances of the wpcom TeamCity build deciding to change all the hashes, although completing that will also require a fix for WordPress/gutenberg#34660.
webpack/webpack.js.org#2096 - thanks for sharing the recommendation. @sirreal, do you remember why you settled on |
This is actually part of your contribution from #17298 😆 This is intended to set the script or style
gutenberg/lib/client-assets.php Line 246 in d3a5128
Version is intended to be a hash that represents the entire build and should change if any of the build changes. With I don't believe there's such a thing as |
If you want the version hash to take into account any css and whatever, because the one hash needs to cover all the entrypoint's files, I wouldn't complain about that. You could combine the hashes of every content type in The problem we're having is that the current hash takes into account stuff that doesn't make it into the output of any of the entrypoint's files, like variable names that have been minified away. There's no point in busting the cache when nothing in the files to be cached actually changed. |
Absolutely, if there's a better alternative it would be a welcome change. |
That's surprising 😅
From the WordPress core perspective it's the opposite. We want to maintain versioning for individual files/chunks. If a single chunk never changes then it's perfectly fine to keep the same version that is based on the actual content. I see now how the name the field can be confusing here. That means that we would benefit from switching to “runtimeChunk.contentHash”. |
Agreed, this is desirable. It would imply a change to the format of the generated asset file. They currently include exactly one version. The asset file would need to include the contentHash for all enqueue-able assets. |
Webpack 5 recommends using the content hash over the old-style chunk hash for cache invalidation, as the chunk hash can change even if the output does not. dependency-extraction-webpack-plugin will now include the content hash for each content type in the asset file. The `version` field is still present, now as a combined hash for all the content types reported, to maintain backwards compatibility. Fixes WordPress#34660
This will improve the long-term caching of the files by only busting caches of the files that have changed rather than busting the cache of every associated file when one does. This should also help reduce the instances of the wpcom TeamCity build deciding to change all the hashes, although completing that will also require a fix for WordPress/gutenberg#34660.
This will improve the long-term caching of the files by only busting caches of the files that have changed rather than busting the cache of every associated file when one does. This should also help reduce the instances of the wpcom TeamCity build deciding to change all the hashes, although completing that will also require a fix for WordPress/gutenberg#34660. Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/1257788621
#34969 is ready for the final review. Can someone help to test and validate the changes proposed? |
… output rather than Webpack internal state (#34969) * Use `contentHash` in dependency-extraction-webpack-plugin Webpack 5 recommends using the content hash over the old-style chunk hash for cache invalidation, as the chunk hash can change even if the output does not. dependency-extraction-webpack-plugin will now include the content hash for each content type in the asset file. The `version` field is still present, now as a combined hash for all the content types reported, to maintain backwards compatibility. Fixes #34660 * Don't expose individual assets' contentHashes, it's considered too scary. * Hash assets directly, chunk.contentHash doesn't get updated by minification * Switch hash to match #40503 * Changelog entry
Description
@wordpress/dependency-extraction-webpack-plugin
outputs the equivalent of[fullhash]
/[chunkhash]
as the "version" rather than[contenthash]
. Note that Webpack itself now recommends using[contenthash]
.The use of
[fullhash]
/[chunkhash]
can result in extraneous hash changes. For example, if the JavaScript is identical but some CSS changed, it will still change the hash for the JavaScript files.In certain configurations, this can even result in a hash change even if the code is unchanged, if the code is built in a different directory. See the reproduction below. We've been running into this frequently with the wpcom TeamCity builds of Jetpack.
You might fix this by changing
gutenberg/packages/dependency-extraction-webpack-plugin/lib/index.js
Line 186 in eb4c8e3
to
Step-by-step reproduction instructions
npm install && npx webpack
. It also works withpnpm
; I haven't testedyarn
.npm install && npx webpack
there too.dist
directories. See that, although everything else is identical, the "version" hash in the asset.php file is different.What's going on here is that
@babel/plugin-transform-runtime
withabsoluteRuntime: true
winds up injecting a variable name derived from the absolute path to@babel/runtime
. Even though this variable name gets minified away, it still affects the[fullhash]
/[chunkhash]
.Screenshots, screen recording, code snippet
No response
Environment info
N/A
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: