Skip to content

fix(contribute): fix webpack 4 patterns in plugin-patterns Changed chunks section#8168

Merged
alexander-akait merged 3 commits intowebpack:mainfrom
raj-sapalya:fix/plugin-patterns-webpack5-chunks
Apr 6, 2026
Merged

fix(contribute): fix webpack 4 patterns in plugin-patterns Changed chunks section#8168
alexander-akait merged 3 commits intowebpack:mainfrom
raj-sapalya:fix/plugin-patterns-webpack5-chunks

Conversation

@raj-sapalya
Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?
Bug fix (documentation) — updates webpack 4 patterns that break in webpack 5.

Summary

The "Changed chunks" example has two bugs that cause incorrect behavior in webpack 5:

  1. compilation.chunks.filter() throws TypeError: compilation.chunks.filter is not a function
    because compilation.chunks is a Set in webpack 5, not an array.

  2. chunk.hash returns undefined in webpack 5 — causing every chunk to appear
    changed on every rebuild, even when nothing changed.

Changes

  • Replace .filter() with for...of iteration
  • Replace chunk.hash with chunk.contentHash.javascript
  • Use chunk.id ?? chunk.name as the tracking key
  • Skip chunks without a JavaScript content hash
  • Add W> warnings for both webpack 5 API changes
  • Add T> tip explaining the key choice and guard

Reopening #8167 with contributing guidelines followed.

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
webpack-js-org Ready Ready Preview, Comment Apr 6, 2026 3:15pm

Request Review

Calling `.filter()` or `.map()` directly on it throws a `TypeError`.
Use `for...of` or spread it into an array first.

W> `chunk.hash` was removed in webpack 5. Use `chunk.contentHash.javascript` instead. Using the old property returns `undefined`, causing every chunk to appear changed on every rebuild.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's avoid using webpack@5 or webpack@4 and just describe the actual types now

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point — I’ve removed the version references and described the behavior directly. Updated!

@alexander-akait alexander-akait merged commit 0093c61 into webpack:main Apr 6, 2026
9 checks passed
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

Successfully merging this pull request may close these issues.

2 participants