Skip to content

fix: real content hash accidentally overwrite user's code #19110

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ahabhgk
Copy link
Contributor

@ahabhgk ahabhgk commented Jan 2, 2025

fix #14058

What kind of change does this PR introduce?

Introduce optimization.realContentHash = 'prefixed'

When 'prefixed' is used, RealContentHashPlugin will add a prefix ("__WEBPACK_RCH_PLACEHOLDER__" by default) for chunk.contentHash when creating the contentHash, so all the contentHashes will have the prefix, and contentHashes in generated code will also have the prefix, then RealContentHashPlugin will only replace the code that have this prefix, to avoid accidentally replace user's code.

Did you add tests for your changes?

Yes

Does this PR introduce a breaking change?

No

The only breaking change is now before RealContentHashPlugin finish replacing, assetInfo.contenthash will have a prefix, I'm not sure whether this is will break other plugins, so I introduce a new option optimization.realContentHash = 'prefixed', and enable it when futureDefaults is enabled, optimization.realContentHash = true is still as is.

What needs to be documented once your changes are merged?

optimization.realContentHash = 'prefixed'

@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)

@ahabhgk ahabhgk marked this pull request as draft January 2, 2025 10:40
Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

What about if custom plugin emit hash(es) without prefix (for example html plugin)? Can we add a test case?

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.

Circular hash dependency for hashed folder names
3 participants