mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 18:32:56 +01:00
fix: memory leaks from worker recompilation with HMR
Add alreadyCompiled flag to prevent unnecessary worker rebuilds during development with Hot Module Replacement, which was causing memory leaks in both webpack and rspack.
This commit is contained in:
parent
f420968fc9
commit
1fcf768d0a
1 changed files with 14 additions and 1 deletions
|
|
@ -13,11 +13,17 @@ function getCompilerHook(
|
|||
{ id, entry, filename, chunkFilename, plugins }: IAddWorkerEntryPointPluginOptions
|
||||
) {
|
||||
const webpack = compiler.webpack ?? require('webpack');
|
||||
let alreadyCompiled = false;
|
||||
|
||||
return function (
|
||||
compilation: webpack.Compilation,
|
||||
callback: (error?: Error | null | false) => void
|
||||
) {
|
||||
if (alreadyCompiled) {
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
|
||||
const outputOptions = {
|
||||
filename,
|
||||
chunkFilename,
|
||||
|
|
@ -33,7 +39,14 @@ function getCompilerHook(
|
|||
new SingleEntryPlugin(compiler.context, entry, 'main').apply(childCompiler);
|
||||
plugins.forEach((plugin) => plugin.apply(childCompiler));
|
||||
|
||||
childCompiler.runAsChild((err?: Error | null) => callback(err));
|
||||
childCompiler.runAsChild((err?: Error | null) => {
|
||||
if (err) {
|
||||
callback(err);
|
||||
} else {
|
||||
alreadyCompiled = true;
|
||||
callback();
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue