Skip to content

Commit 13bf471

Browse files
committed
fix: onerror mem leak
1 parent 1cce677 commit 13bf471

File tree

5 files changed

+10
-12
lines changed

5 files changed

+10
-12
lines changed

src/CssLoadingRuntimeModule.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ module.exports = class CssLoadingRuntimeModule extends RuntimeModule {
6060
this.runtimeOptions.linkType
6161
? `linkTag.type = ${JSON.stringify(this.runtimeOptions.linkType)};`
6262
: '',
63-
'var onLinkComplete = function (event) {',
64-
Template.indent([
63+
`var onLinkComplete = ${runtimeTemplate.basicFunction('event', [
6564
'// avoid mem leaks.',
6665
'linkTag.onerror = linkTag.onload = null;',
6766
"if (event.type === 'load') {",
@@ -76,8 +75,7 @@ module.exports = class CssLoadingRuntimeModule extends RuntimeModule {
7675
'reject(err);',
7776
]),
7877
'}',
79-
]),
80-
'};',
78+
])}`,
8179
'linkTag.onerror = linkTag.onload = onLinkComplete;',
8280
'linkTag.href = fullhref;',
8381
crossOriginLoading

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ module.exports = function (urlString) {
827827
/******/
828828
/******/ linkTag.rel = "stylesheet";
829829
/******/ linkTag.type = "text/css";
830-
/******/ var onLinkComplete = function (event) {
830+
/******/ var onLinkComplete = (event) => {
831831
/******/ // avoid mem leaks.
832832
/******/ linkTag.onerror = linkTag.onload = null;
833833
/******/ if (event.type === 'load') {
@@ -840,7 +840,7 @@ module.exports = function (urlString) {
840840
/******/ linkTag.parentNode.removeChild(linkTag)
841841
/******/ reject(err);
842842
/******/ }
843-
/******/ };
843+
/******/ }
844844
/******/ linkTag.onerror = linkTag.onload = onLinkComplete;
845845
/******/ linkTag.href = fullhref;
846846
/******/

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
/******/
163163
/******/ linkTag.rel = "stylesheet";
164164
/******/ linkTag.type = "text/css";
165-
/******/ var onLinkComplete = function (event) {
165+
/******/ var onLinkComplete = (event) => {
166166
/******/ // avoid mem leaks.
167167
/******/ linkTag.onerror = linkTag.onload = null;
168168
/******/ if (event.type === 'load') {
@@ -175,7 +175,7 @@
175175
/******/ linkTag.parentNode.removeChild(linkTag)
176176
/******/ reject(err);
177177
/******/ }
178-
/******/ };
178+
/******/ }
179179
/******/ linkTag.onerror = linkTag.onload = onLinkComplete;
180180
/******/ linkTag.href = fullhref;
181181
/******/

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
/******/
163163
/******/ linkTag.rel = "stylesheet";
164164
/******/ linkTag.type = "text/css";
165-
/******/ var onLinkComplete = function (event) {
165+
/******/ var onLinkComplete = (event) => {
166166
/******/ // avoid mem leaks.
167167
/******/ linkTag.onerror = linkTag.onload = null;
168168
/******/ if (event.type === 'load') {
@@ -175,7 +175,7 @@
175175
/******/ linkTag.parentNode.removeChild(linkTag)
176176
/******/ reject(err);
177177
/******/ }
178-
/******/ };
178+
/******/ }
179179
/******/ linkTag.onerror = linkTag.onload = onLinkComplete;
180180
/******/ linkTag.href = fullhref;
181181
/******/

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@
162162
/******/
163163
/******/ linkTag.rel = "stylesheet";
164164
/******/ linkTag.type = "text/css";
165-
/******/ var onLinkComplete = function (event) {
165+
/******/ var onLinkComplete = (event) => {
166166
/******/ // avoid mem leaks.
167167
/******/ linkTag.onerror = linkTag.onload = null;
168168
/******/ if (event.type === 'load') {
@@ -175,7 +175,7 @@
175175
/******/ linkTag.parentNode.removeChild(linkTag)
176176
/******/ reject(err);
177177
/******/ }
178-
/******/ };
178+
/******/ }
179179
/******/ linkTag.onerror = linkTag.onload = onLinkComplete;
180180
/******/ linkTag.href = fullhref;
181181
/******/

0 commit comments

Comments
 (0)