<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>
This commit is contained in:
6
.changeset/short-hounds-confess.md
Normal file
6
.changeset/short-hounds-confess.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"rrweb-snapshot": patch
|
||||
"rrweb": patch
|
||||
---
|
||||
|
||||
Change to ignore all link[rel="modulepreload"] instead of including only those with `as="script"`
|
||||
@@ -7,7 +7,12 @@ import {
|
||||
type legacyAttributes,
|
||||
} from '@rrweb/types';
|
||||
import { type tagMap, type BuildCache } from './types';
|
||||
import { isElement, Mirror, isNodeMetaEqual } from './utils';
|
||||
import {
|
||||
isElement,
|
||||
Mirror,
|
||||
isNodeMetaEqual,
|
||||
extractFileExtension,
|
||||
} from './utils';
|
||||
import postcss from 'postcss';
|
||||
|
||||
const tagMap: tagMap = {
|
||||
@@ -299,16 +304,15 @@ function buildNode(
|
||||
continue;
|
||||
} else if (
|
||||
tagName === 'link' &&
|
||||
(n.attributes.rel === 'preload' ||
|
||||
n.attributes.rel === 'modulepreload') &&
|
||||
n.attributes.as === 'script'
|
||||
((n.attributes.rel === 'preload' && n.attributes.as === 'script') ||
|
||||
n.attributes.rel === 'modulepreload')
|
||||
) {
|
||||
// ignore
|
||||
} else if (
|
||||
tagName === 'link' &&
|
||||
n.attributes.rel === 'prefetch' &&
|
||||
typeof n.attributes.href === 'string' &&
|
||||
n.attributes.href.endsWith('.js')
|
||||
extractFileExtension(n.attributes.href) === 'js'
|
||||
) {
|
||||
// ignore
|
||||
} else if (
|
||||
|
||||
@@ -819,9 +819,8 @@ function slimDOMExcluded(
|
||||
(sn.tagName === 'script' ||
|
||||
// (module)preload link
|
||||
(sn.tagName === 'link' &&
|
||||
(sn.attributes.rel === 'preload' ||
|
||||
sn.attributes.rel === 'modulepreload') &&
|
||||
sn.attributes.as === 'script') ||
|
||||
((sn.attributes.rel === 'preload' && sn.attributes.as === 'script') ||
|
||||
sn.attributes.rel === 'modulepreload')) ||
|
||||
// prefetch link
|
||||
(sn.tagName === 'link' &&
|
||||
sn.attributes.rel === 'prefetch' &&
|
||||
|
||||
Reference in New Issue
Block a user