Skip to content

Commit 3a45d99

Browse files
authored
fix(runtime): The preload link is inserted without specific purpose (#2152)
1 parent 637dcfc commit 3a45d99

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

.changeset/itchy-ravens-give.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/sdk': patch
3+
---
4+
5+
fix: Avoid style loss due to reuse of link without distinguishing purpose

packages/sdk/src/dom.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export function createScript(
9898
export function createLink(
9999
url: string,
100100
cb: (value: void | PromiseLike<void>) => void,
101-
attrs?: Record<string, any>,
101+
attrs: Record<string, string> = {},
102102
createLinkHook?: (url: string) => HTMLLinkElement | void,
103103
) {
104104
// <link rel="preload" href="script.js" as="script">
@@ -110,7 +110,12 @@ export function createLink(
110110
for (let i = 0; i < links.length; i++) {
111111
const l = links[i];
112112
const linkHref = l.getAttribute('href');
113-
if (linkHref && isStaticResourcesEqual(linkHref, url)) {
113+
const linkRef = l.getAttribute('ref');
114+
if (
115+
linkHref &&
116+
isStaticResourcesEqual(linkHref, url) &&
117+
linkRef === attrs['ref']
118+
) {
114119
link = l;
115120
needAttach = false;
116121
break;

0 commit comments

Comments
 (0)