Skip to content

Commit 92b9336

Browse files
authored
Fixes gc issue with webpack production bundle (#82)
1 parent a6bafe6 commit 92b9336

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/renderer/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,11 @@ export class Renderer {
5252
); // Start reconcilation and render the result
5353
}
5454
}
55+
56+
// When webpack bundles everthing into one js file, there is no require cache. Hence, all the modules are present in a single array.
57+
// When all the instructions from this bundled js file is executed and there are no more events left to listen to,
58+
// NodeJs tries to clear up everything. Since all the modules in the bundled file are in a single variable and there is nothing referencing it,
59+
// the gc is able to clean up even those. This is not the case in a regular nodejs app where we have require cache that keeps reference to all the modules.
60+
// Hence to prevent all the modules from being gc'ed we keep reference to one of the modules in the entire array of modules.
61+
// Here, we chose React, but it can be anything.
62+
(global as any).__REACT__ = React;

0 commit comments

Comments
 (0)