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

Respect output.hashSalt in RealContentHashPlugin #16789

Merged
merged 1 commit into from Mar 8, 2023

Conversation

dmichon-msft
Copy link
Contributor

Update RealContentHashPlugin to initialize hash instances with the value of output.hashSalt, if provided. This allows developers to use the output.hashSalt property to force all emitted webpack assets to have new hashes, even though the content has not changed, for example to deliberately cache break a CDN.

Note that if the optimization.realContentHash property was set to false, the value of [contenthash] already included output.hashSalt in the calculation.

What kind of change does this PR introduce?
Fix #16788

Did you add tests for your changes?
Yes. Changes verify that running three configs with identical source files and two different values of output.hashSalt produce exactly 2 unique output hashes.

Does this PR introduce a breaking change?
This could be considered a breaking change if a consumer is using the output.hashSalt property and depending on the value of [contenthash] not changing when optimization.realContentHash is set.

Plugins that provide a custom implementation of the content hash (e.g. for Sub-Resource Integrity) will not be impacted, because this change only applies when the RealContentHashPlugin is the entity that generates the content hash.

What needs to be documented once your changes are merged?
Documentation of optimization.realContentHash should be updated to explicitly call out that it does include output.hashSalt if set. The current state of the documentation is unclear on whether or not it is expected.

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Mar 8, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: dmichon-msft / name: David Michon (07283fa)

@webpack-bot
Copy link
Contributor

For maintainers only:

  • This needs to be documented (issue in webpack/webpack.js.org will be filed when merged)
  • This needs to be backported to webpack 4 (issue will be created when merged)

Fix webpack#16788

Update RealContentHashPlugin to initialize hash instances with
the value of `output.hashSalt`, if provided.
@TheLarkInn
Copy link
Member

@alexander-akait I think this could be acceptable for v5 change. The behavior today is technically a bug, although [contenthash] will start to change when output.hashSalt is now provided.

@alexander-akait
Copy link
Member

@TheLarkInn Yeah, I agree, we can merge

@TheLarkInn TheLarkInn merged commit 710eaf4 into webpack:main Mar 8, 2023
44 of 46 checks passed
@dmichon-msft dmichon-msft deleted the contenthash-hashsalt branch March 8, 2023 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Shipped
Development

Successfully merging this pull request may close these issues.

optimization.realContentHash does not respect output.hashSalt
5 participants