Skip to content

Commit 78f3c55

Browse files
committed
fix: onerror mem leak
1 parent f448ee1 commit 78f3c55

File tree

9 files changed

+49
-9
lines changed

9 files changed

+49
-9
lines changed

src/CssLoadingRuntimeModule.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,15 @@ module.exports = class CssLoadingRuntimeModule extends RuntimeModule {
6060
this.runtimeOptions.linkType
6161
? `linkTag.type = ${JSON.stringify(this.runtimeOptions.linkType)};`
6262
: '',
63-
'linkTag.onload = resolve;',
63+
'linkTag.onload = function() {',
64+
Template.indent([
65+
'linkTag.onerror = linkTag.onload = null;',
66+
'resolve();',
67+
]),
68+
'};',
6469
'linkTag.onerror = function(event) {',
6570
Template.indent([
71+
'linkTag.onerror = linkTag.onload = null;',
6672
'var request = event && event.target && event.target.href || fullhref;',
6773
'var err = new Error("Loading CSS chunk " + chunkId + " failed.\\n(" + request + ")");',
6874
'err.code = "CSS_CHUNK_LOAD_FAILED";',

src/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,9 +405,15 @@ class MiniCssExtractPlugin {
405405
this.runtimeOptions.linkType
406406
)};`
407407
: '',
408-
'linkTag.onload = resolve;',
408+
'linkTag.onload = function() {',
409+
Template.indent([
410+
'linkTag.onerror = linkTag.onload = null;',
411+
'resolve();',
412+
]),
413+
'};',
409414
'linkTag.onerror = function(event) {',
410415
Template.indent([
416+
'linkTag.onerror = linkTag.onload = null;',
411417
'var request = event && event.target && event.target.href || fullhref;',
412418
'var err = new Error("Loading CSS chunk " + chunkId + " failed.\\n(" + request + ")");',
413419
'err.code = "CSS_CHUNK_LOAD_FAILED";',

test/cases/hmr/expected/webpack-5/main.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,8 +827,12 @@ module.exports = function (urlString) {
827827
/******/
828828
/******/ linkTag.rel = "stylesheet";
829829
/******/ linkTag.type = "text/css";
830-
/******/ linkTag.onload = resolve;
830+
/******/ linkTag.onload = function() {
831+
/******/ linkTag.onerror = linkTag.onload = null;
832+
/******/ resolve();
833+
/******/ };
831834
/******/ linkTag.onerror = function(event) {
835+
/******/ linkTag.onerror = linkTag.onload = null;
832836
/******/ var request = event && event.target && event.target.href || fullhref;
833837
/******/ var err = new Error("Loading CSS chunk " + chunkId + " failed.\n(" + request + ")");
834838
/******/ err.code = "CSS_CHUNK_LOAD_FAILED";

test/cases/insert-function/expected/webpack-4/main.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,12 @@
104104
/******/
105105
/******/ linkTag.rel = "stylesheet";
106106
/******/ linkTag.type = "text/css";
107-
/******/ linkTag.onload = resolve;
107+
/******/ linkTag.onload = function() {
108+
/******/ linkTag.onerror = linkTag.onload = null;
109+
/******/ resolve();
110+
/******/ };
108111
/******/ linkTag.onerror = function(event) {
112+
/******/ linkTag.onerror = linkTag.onload = null;
109113
/******/ var request = event && event.target && event.target.href || fullhref;
110114
/******/ var err = new Error("Loading CSS chunk " + chunkId + " failed.\n(" + request + ")");
111115
/******/ err.code = "CSS_CHUNK_LOAD_FAILED";

test/cases/insert-function/expected/webpack-5/main.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,12 @@
162162
/******/
163163
/******/ linkTag.rel = "stylesheet";
164164
/******/ linkTag.type = "text/css";
165-
/******/ linkTag.onload = resolve;
165+
/******/ linkTag.onload = function() {
166+
/******/ linkTag.onerror = linkTag.onload = null;
167+
/******/ resolve();
168+
/******/ };
166169
/******/ linkTag.onerror = function(event) {
170+
/******/ linkTag.onerror = linkTag.onload = null;
167171
/******/ var request = event && event.target && event.target.href || fullhref;
168172
/******/ var err = new Error("Loading CSS chunk " + chunkId + " failed.\n(" + request + ")");
169173
/******/ err.code = "CSS_CHUNK_LOAD_FAILED";

test/cases/insert-string/expected/webpack-4/main.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,12 @@
104104
/******/
105105
/******/ linkTag.rel = "stylesheet";
106106
/******/ linkTag.type = "text/css";
107-
/******/ linkTag.onload = resolve;
107+
/******/ linkTag.onload = function() {
108+
/******/ linkTag.onerror = linkTag.onload = null;
109+
/******/ resolve();
110+
/******/ };
108111
/******/ linkTag.onerror = function(event) {
112+
/******/ linkTag.onerror = linkTag.onload = null;
109113
/******/ var request = event && event.target && event.target.href || fullhref;
110114
/******/ var err = new Error("Loading CSS chunk " + chunkId + " failed.\n(" + request + ")");
111115
/******/ err.code = "CSS_CHUNK_LOAD_FAILED";

test/cases/insert-string/expected/webpack-5/main.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,12 @@
162162
/******/
163163
/******/ linkTag.rel = "stylesheet";
164164
/******/ linkTag.type = "text/css";
165-
/******/ linkTag.onload = resolve;
165+
/******/ linkTag.onload = function() {
166+
/******/ linkTag.onerror = linkTag.onload = null;
167+
/******/ resolve();
168+
/******/ };
166169
/******/ linkTag.onerror = function(event) {
170+
/******/ linkTag.onerror = linkTag.onload = null;
167171
/******/ var request = event && event.target && event.target.href || fullhref;
168172
/******/ var err = new Error("Loading CSS chunk " + chunkId + " failed.\n(" + request + ")");
169173
/******/ err.code = "CSS_CHUNK_LOAD_FAILED";

test/cases/insert-undefined/expected/webpack-4/main.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,12 @@
104104
/******/
105105
/******/ linkTag.rel = "stylesheet";
106106
/******/ linkTag.type = "text/css";
107-
/******/ linkTag.onload = resolve;
107+
/******/ linkTag.onload = function() {
108+
/******/ linkTag.onerror = linkTag.onload = null;
109+
/******/ resolve();
110+
/******/ };
108111
/******/ linkTag.onerror = function(event) {
112+
/******/ linkTag.onerror = linkTag.onload = null;
109113
/******/ var request = event && event.target && event.target.href || fullhref;
110114
/******/ var err = new Error("Loading CSS chunk " + chunkId + " failed.\n(" + request + ")");
111115
/******/ err.code = "CSS_CHUNK_LOAD_FAILED";

test/cases/insert-undefined/expected/webpack-5/main.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,12 @@
162162
/******/
163163
/******/ linkTag.rel = "stylesheet";
164164
/******/ linkTag.type = "text/css";
165-
/******/ linkTag.onload = resolve;
165+
/******/ linkTag.onload = function() {
166+
/******/ linkTag.onerror = linkTag.onload = null;
167+
/******/ resolve();
168+
/******/ };
166169
/******/ linkTag.onerror = function(event) {
170+
/******/ linkTag.onerror = linkTag.onload = null;
167171
/******/ var request = event && event.target && event.target.href || fullhref;
168172
/******/ var err = new Error("Loading CSS chunk " + chunkId + " failed.\n(" + request + ")");
169173
/******/ err.code = "CSS_CHUNK_LOAD_FAILED";

0 commit comments

Comments
 (0)