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

🐛 Fix chunk.getModules() webpack 5 deprecation warning #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions source/ReactLoadableSSRAddon.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,10 @@ class ReactLoadableSSRAddon {
* It tries to mimic https://github.com/webpack/webpack/blob/webpack-4/lib/Stats.js#L632
* implementation without expensive operations
* @param {array} compilationChunks
* @param {array} chunkGraph
* @returns {array}
*/
getMinimalStatsChunks(compilationChunks) {
getMinimalStatsChunks(compilationChunks, chunkGraph) {
const compareId = (a, b) => {
if (typeof a !== typeof b) {
return typeof a < typeof b ? -1 : 1;
Expand Down Expand Up @@ -218,8 +219,9 @@ class ReactLoadableSSRAddon {
files: this.ensureArray(chunk.files).slice(),
hash: chunk.renderedHash,
siblings: Array.from(siblings).sort(compareId),
// TODO: This is the final deprecation warning needing to be solved.
modules: chunk.getModules(),
// Webpack5 emit deprecation warning for chunk.getModules()
// "DEP_WEBPACK_CHUNK_GET_MODULES"
modules: WEBPACK_5 ? chunkGraph.getChunkModules(chunk) : chunk.getModules(),
});
});

Expand Down Expand Up @@ -247,7 +249,7 @@ class ReactLoadableSSRAddon {
|| '';
this.getEntrypoints(this.stats.entrypoints);

this.getAssets(this.getMinimalStatsChunks(compilation.chunks));
this.getAssets(this.getMinimalStatsChunks(compilation.chunks, compilation.chunkGraph));
Copy link
Contributor

Choose a reason for hiding this comment

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

Just in case this isn't present for webpack 4

Suggested change
this.getAssets(this.getMinimalStatsChunks(compilation.chunks, compilation.chunkGraph));
this.getAssets(this.getMinimalStatsChunks(compilation.chunks, compilation.chunkGraph || null));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think chunkGraph is present in webpack4, but not sure to understand why this call is needed? Do we want null instead of undefined?

Copy link
Contributor

Choose a reason for hiding this comment

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

That's true. Just trying to avoid strict mode madness where possible, but this might not be entirely needed.

this.processAssets(compilation.assets);
this.writeAssetsFile();

Expand Down