Skip to content

Commit 77be80c

Browse files
pmmmwhserkanyersen
andauthored
perf: fix loader memory leak from non-destroyed source map consumers (#537)
Co-authored-by: Serkan Yerşen <[email protected]>
1 parent d35f646 commit 77be80c

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,6 @@ yarn-error.log*
1919
.vscode
2020

2121
# test artifacts
22+
*.yalc
2223
*__tmp__
24+
yalc.lock

loader/index.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,15 @@ function ReactRefreshLoader(source, inputSourceMap, meta) {
7575
originalSourceMap = getIdentitySourceMap(source, this.resourcePath);
7676
}
7777

78-
const node = SourceNode.fromStringWithSourceMap(
79-
source,
80-
await new SourceMapConsumer(originalSourceMap)
81-
);
78+
return SourceMapConsumer.with(originalSourceMap, undefined, (consumer) => {
79+
const node = SourceNode.fromStringWithSourceMap(source, consumer);
8280

83-
node.prepend([RefreshSetupRuntime, '\n\n']);
84-
node.add(['\n\n', RefreshModuleRuntime]);
81+
node.prepend([RefreshSetupRuntime, '\n\n']);
82+
node.add(['\n\n', RefreshModuleRuntime]);
8583

86-
const { code, map } = node.toStringWithSourceMap();
87-
return [code, map.toJSON()];
84+
const { code, map } = node.toStringWithSourceMap();
85+
return [code, map.toJSON()];
86+
});
8887
} else {
8988
return [[RefreshSetupRuntime, source, RefreshModuleRuntime].join('\n\n'), inputSourceMap];
9089
}

0 commit comments

Comments
 (0)