Skip to content

Commit eb67c8b

Browse files
committed
chore: clear preload links when completed
1 parent 6047899 commit eb67c8b

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

packages/qwik/src/core/qrl/preload.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ export const loadBundleGraph = (element: Element) => {
103103

104104
// we stringify this in prefetch-implementation.ts
105105
export const makeMakePreloadLink =
106-
/*@__PURE__*/
107106
(canModulePreload: boolean | null) => (url: string, priority: boolean) => {
108107
const link = document.createElement('link');
109108
if (canModulePreload === null) {
@@ -119,16 +118,16 @@ export const makeMakePreloadLink =
119118
if (!canModulePreload) {
120119
link.as = 'script';
121120
}
121+
link.onload = link.onerror = () => link.remove();
122+
122123
document.head.appendChild(link);
123124
};
124-
const makePreloadLink = makeMakePreloadLink(null);
125+
const makePreloadLink = /*@__PURE__*/ makeMakePreloadLink(null);
125126

126127
const prioritizeLink = (url: string) => {
127128
const link = document.querySelector(`link[href="${url}"]`) as HTMLLinkElement | null;
128129
if (link) {
129130
link.fetchPriority = 'high';
130-
} else {
131-
console.warn(`Preload link ${url} not found`);
132131
}
133132
};
134133

starters/e2e/e2e.containers.spec.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,6 @@ test.describe("container", () => {
4242
const hash = await container.getAttribute("q:manifest-hash");
4343
const bundleLink = page.locator(`link#qwik-bg-${hash}`).first();
4444
await expect(bundleLink).toHaveAttribute("href");
45-
46-
const headPreload = page.locator(`head > link[rel="modulepreload"]`);
47-
const beforeCount = await headPreload.count();
48-
49-
const anchor = container.locator("a");
50-
await anchor.click();
51-
await expect(anchor).toHaveText("2 / 3");
52-
53-
const afterCount = await headPreload.count();
54-
expect(afterCount).toBeGreaterThan(beforeCount);
45+
// We don't have a way to check if other modules are preloaded, because the link goes away
5546
});
5647
});

0 commit comments

Comments
 (0)