Skip to content

Commit

Permalink
fix: Exclude modulepreload as well (#52)
Browse files Browse the repository at this point in the history
We were only excluding `<link rel="preload" as="script" />` but we
should include `rel="modulepreload"` as well
  • Loading branch information
billyvg authored Feb 15, 2023
1 parent 09687b0 commit 5b4631b
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/rrweb-snapshot/src/rebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function buildNode(
continue;
} else if (
tagName === 'link' &&
n.attributes.rel === 'preload' &&
(n.attributes.rel === 'preload' || n.attributes.rel === 'modulepreload') &&
n.attributes.as === 'script'
) {
// ignore
Expand Down
4 changes: 2 additions & 2 deletions packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,9 +789,9 @@ function slimDOMExcluded(
slimDOMOptions.script &&
// script tag
(sn.tagName === 'script' ||
// preload link
// (module)preload link
(sn.tagName === 'link' &&
sn.attributes.rel === 'preload' &&
(sn.attributes.rel === 'preload' || sn.attributes.rel === 'modulepreload') &&
sn.attributes.as === 'script') ||
// prefetch link
(sn.tagName === 'link' &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ exports[`integration tests [html file]: preload.html 1`] = `
<title>Document</title>
<link />
<link />
<link />
</head>
<body></body></html>"
`;
Expand Down
1 change: 1 addition & 0 deletions packages/rrweb-snapshot/test/html/preload.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<link rel="modulepreload" href="https://example/path/to/preload.js" as="script" />
<link rel="preload" href="https://example/path/to/preload.js" as="script" />
<link rel="prefetch" href="https://example/path/to/prefetch.js" />
</head>
Expand Down

0 comments on commit 5b4631b

Please sign in to comment.