Skip to content

Commit 5b4631b

Browse files
authored
fix: Exclude modulepreload as well (#52)
We were only excluding `<link rel="preload" as="script" />` but we should include `rel="modulepreload"` as well
1 parent 09687b0 commit 5b4631b

File tree

4 files changed

+5
-3
lines changed

4 files changed

+5
-3
lines changed

packages/rrweb-snapshot/src/rebuild.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ function buildNode(
198198
continue;
199199
} else if (
200200
tagName === 'link' &&
201-
n.attributes.rel === 'preload' &&
201+
(n.attributes.rel === 'preload' || n.attributes.rel === 'modulepreload') &&
202202
n.attributes.as === 'script'
203203
) {
204204
// ignore

packages/rrweb-snapshot/src/snapshot.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,9 +789,9 @@ function slimDOMExcluded(
789789
slimDOMOptions.script &&
790790
// script tag
791791
(sn.tagName === 'script' ||
792-
// preload link
792+
// (module)preload link
793793
(sn.tagName === 'link' &&
794-
sn.attributes.rel === 'preload' &&
794+
(sn.attributes.rel === 'preload' || sn.attributes.rel === 'modulepreload') &&
795795
sn.attributes.as === 'script') ||
796796
// prefetch link
797797
(sn.tagName === 'link' &&

packages/rrweb-snapshot/test/__snapshots__/integration.test.ts.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ exports[`integration tests [html file]: preload.html 1`] = `
337337
<title>Document</title>
338338
<link />
339339
<link />
340+
<link />
340341
</head>
341342
<body></body></html>"
342343
`;

packages/rrweb-snapshot/test/html/preload.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>Document</title>
7+
<link rel="modulepreload" href="https://example/path/to/preload.js" as="script" />
78
<link rel="preload" href="https://example/path/to/preload.js" as="script" />
89
<link rel="prefetch" href="https://example/path/to/prefetch.js" />
910
</head>

0 commit comments

Comments
 (0)