Skip to content

Commit

Permalink
fix: memoy leak (#1836)
Browse files Browse the repository at this point in the history
  • Loading branch information
helloitsjoe committed Dec 19, 2023
1 parent 7effc30 commit c79f2cf
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions lib/child-compiler.js
Expand Up @@ -13,7 +13,6 @@
/** @typedef {import("webpack").sources.Source} Source */
/** @typedef {{hash: string, entry: Chunk, content: string, assets: {[name: string]: { source: Source, info: import("webpack").AssetInfo }}}} ChildCompilationTemplateResult */

let instanceId = 0;
/**
* The HtmlWebpackChildCompiler is a helper to allow reusing one childCompiler
* for multiple HtmlWebpackPlugin instances to improve the compilation performance.
Expand All @@ -24,8 +23,6 @@ class HtmlWebpackChildCompiler {
* @param {string[]} templates
*/
constructor (templates) {
/** Id for this ChildCompiler */
this.id = instanceId++;
/**
* @type {string[]} templateIds
* The template array will allow us to keep track which input generated which output
Expand Down Expand Up @@ -110,12 +107,12 @@ class HtmlWebpackChildCompiler {
childCompiler.context = mainCompilation.compiler.context;

// Generate output file names
const temporaryTemplateNames = this.templates.map((template, index) => `__child-HtmlWebpackPlugin_${index}-${this.id}`);
const temporaryTemplateNames = this.templates.map((template, index) => `__child-HtmlWebpackPlugin_${index}-${template}`);

// Add all templates
this.templates.forEach((template, index) => {
new EntryPlugin(childCompiler.context, 'data:text/javascript,__webpack_public_path__ = __webpack_base_uri__ = htmlWebpackPluginPublicPath;', `HtmlWebpackPlugin_${index}-${this.id}`).apply(childCompiler);
new EntryPlugin(childCompiler.context, template, `HtmlWebpackPlugin_${index}-${this.id}`).apply(childCompiler);
new EntryPlugin(childCompiler.context, 'data:text/javascript,__webpack_public_path__ = __webpack_base_uri__ = htmlWebpackPluginPublicPath;', `HtmlWebpackPlugin_${index}-${template}`).apply(childCompiler);
new EntryPlugin(childCompiler.context, template, `HtmlWebpackPlugin_${index}-${template}`).apply(childCompiler);
});

// The templates are compiled and executed by NodeJS - similar to server side rendering
Expand Down

2 comments on commit c79f2cf

@creage
Copy link

@creage creage commented on c79f2cf Jan 19, 2024

Choose a reason for hiding this comment

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

@helloitsjoe this change leads to an issue - webpack-dev-server doesn't pick changes:

[webpack-dev-server] App updated. Recompiling...
[webpack-dev-server] Nothing changed

Rolling back to html-webpack-plugin version 5.5.3 fixes the issue.

@helloitsjoe
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like this might be due to a change introduced in 5.5.4 and might be unrelated to this change, let's continue the discussion in #1836 (comment)

Please sign in to comment.