Skip to content

Commit 6f4e691

Browse files
<link> fixes re. modulepreload and fetch logic (#1614)
* `link[rel="modulepreload"]` doesn't require `as="script"` which is tied to rel="preload" only * extract file extension properly when examining `rel="prefetch"` to disregard URL parameters correctly Co-authored-by: Eoghan Murray <eoghan@getthere.ie>
1 parent dfb2991 commit 6f4e691

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

.changeset/short-hounds-confess.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"rrweb-snapshot": patch
3+
"rrweb": patch
4+
---
5+
6+
Change to ignore all link[rel="modulepreload"] instead of including only those with `as="script"`

packages/rrweb-snapshot/src/rebuild.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import {
77
type legacyAttributes,
88
} from '@rrweb/types';
99
import { type tagMap, type BuildCache } from './types';
10-
import { isElement, Mirror, isNodeMetaEqual } from './utils';
10+
import {
11+
isElement,
12+
Mirror,
13+
isNodeMetaEqual,
14+
extractFileExtension,
15+
} from './utils';
1116
import postcss from 'postcss';
1217

1318
const tagMap: tagMap = {
@@ -299,16 +304,15 @@ function buildNode(
299304
continue;
300305
} else if (
301306
tagName === 'link' &&
302-
(n.attributes.rel === 'preload' ||
303-
n.attributes.rel === 'modulepreload') &&
304-
n.attributes.as === 'script'
307+
((n.attributes.rel === 'preload' && n.attributes.as === 'script') ||
308+
n.attributes.rel === 'modulepreload')
305309
) {
306310
// ignore
307311
} else if (
308312
tagName === 'link' &&
309313
n.attributes.rel === 'prefetch' &&
310314
typeof n.attributes.href === 'string' &&
311-
n.attributes.href.endsWith('.js')
315+
extractFileExtension(n.attributes.href) === 'js'
312316
) {
313317
// ignore
314318
} else if (

packages/rrweb-snapshot/src/snapshot.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -819,9 +819,8 @@ function slimDOMExcluded(
819819
(sn.tagName === 'script' ||
820820
// (module)preload link
821821
(sn.tagName === 'link' &&
822-
(sn.attributes.rel === 'preload' ||
823-
sn.attributes.rel === 'modulepreload') &&
824-
sn.attributes.as === 'script') ||
822+
((sn.attributes.rel === 'preload' && sn.attributes.as === 'script') ||
823+
sn.attributes.rel === 'modulepreload')) ||
825824
// prefetch link
826825
(sn.tagName === 'link' &&
827826
sn.attributes.rel === 'prefetch' &&

0 commit comments

Comments
 (0)