Skip to content

Commit

Permalink
fix(runtime): The preload link is inserted without specific purpose (m…
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoushaw authored Mar 6, 2024
1 parent 637dcfc commit 3a45d99
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/itchy-ravens-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/sdk': patch
---

fix: Avoid style loss due to reuse of link without distinguishing purpose
9 changes: 7 additions & 2 deletions packages/sdk/src/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function createScript(
export function createLink(
url: string,
cb: (value: void | PromiseLike<void>) => void,
attrs?: Record<string, any>,
attrs: Record<string, string> = {},
createLinkHook?: (url: string) => HTMLLinkElement | void,
) {
// <link rel="preload" href="script.js" as="script">
Expand All @@ -110,7 +110,12 @@ export function createLink(
for (let i = 0; i < links.length; i++) {
const l = links[i];
const linkHref = l.getAttribute('href');
if (linkHref && isStaticResourcesEqual(linkHref, url)) {
const linkRef = l.getAttribute('ref');
if (
linkHref &&
isStaticResourcesEqual(linkHref, url) &&
linkRef === attrs['ref']
) {
link = l;
needAttach = false;
break;
Expand Down

0 comments on commit 3a45d99

Please sign in to comment.