From c79f2cfdb3aaa6f1dbd87b64c7d13bc9ab21c59f Mon Sep 17 00:00:00 2001 From: Joe Boyle Date: Tue, 19 Dec 2023 09:18:41 -0500 Subject: [PATCH] fix: memoy leak (#1836) --- lib/child-compiler.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/child-compiler.js b/lib/child-compiler.js index 8bea9bec..ea5760f3 100644 --- a/lib/child-compiler.js +++ b/lib/child-compiler.js @@ -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. @@ -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 @@ -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