Skip to content

Commit

Permalink
fix: memory leak in TransformNormalModuleFactoryPlugin (#414)
Browse files Browse the repository at this point in the history
Problem: plugin wraps createLoaderContext without checking if it was
already done before. As a result, in a watch mode more and more wrappers
get added on top of the function and eat more and more memory. Fixed by
saving original function on module instance itself and wrapping saved
function instead.
  • Loading branch information
SevInf authored and mzgoddard committed Jul 30, 2018
1 parent e370f1f commit 33b306b
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/TransformNormalModuleFactoryPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ class NormalModuleFactoryPlugin {
'HardSource - TransformNormalModuleFactoryPlugin',
module => {
if (module.constructor.name === 'NormalModule') {
const _createLoaderContext = module.createLoaderContext;
module.__originalCreateLoaderContext =
module.__originalCreateLoaderContext ||
module.createLoaderContext;
module.__hardSource_resolved = {};
module.createLoaderContext = (...args) => {
const loaderContext = _createLoaderContext.call(
module,
const loaderContext = module.__originalCreateLoaderContext(
...args,
);
const _resolve = loaderContext.resolve;
Expand Down

0 comments on commit 33b306b

Please sign in to comment.