Skip to content

Commit 031454d

Browse files
authored
fix: do not delete link tag if no preload (#2585)
1 parent a2bfb9b commit 031454d

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

.changeset/quiet-parrots-battle.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@module-federation/runtime': patch
3+
'@module-federation/sdk': patch
4+
---
5+
6+
fix: do not delete link tag if no preload

packages/runtime/src/utils/preload.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ export function preloadAssets(
174174
}
175175
return;
176176
},
177+
needDeleteLink: false,
177178
});
178179

179180
needAttach && document.head.appendChild(cssEl);
@@ -220,6 +221,7 @@ export function preloadAssets(
220221
}
221222
return;
222223
},
224+
needDeleteScript: true,
223225
});
224226
needAttach && document.head.appendChild(scriptEl);
225227
});

packages/sdk/src/dom.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ export function createScript(info: {
9090
script.onerror = null;
9191
script.onload = null;
9292
safeWrapper(() => {
93-
if (info.needDeleteScript) {
93+
const { needDeleteScript = true } = info;
94+
if (needDeleteScript) {
9495
script?.parentNode && script.parentNode.removeChild(script);
9596
}
9697
});
@@ -121,6 +122,7 @@ export function createLink(info: {
121122
url: string;
122123
cb: (value: void | PromiseLike<void>) => void;
123124
attrs: Record<string, string>;
125+
needDeleteLink?: boolean;
124126
createLinkHook?: (url: string) => HTMLLinkElement | void;
125127
}) {
126128
// <link rel="preload" href="script.js" as="script">
@@ -175,7 +177,10 @@ export function createLink(info: {
175177
link.onerror = null;
176178
link.onload = null;
177179
safeWrapper(() => {
178-
link?.parentNode && link.parentNode.removeChild(link);
180+
const { needDeleteLink = true } = info;
181+
if (needDeleteLink) {
182+
link?.parentNode && link.parentNode.removeChild(link);
183+
}
179184
});
180185
if (prev) {
181186
// eslint-disable-next-line @typescript-eslint/no-explicit-any

0 commit comments

Comments
 (0)