<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:
Billy Vong
2026-04-01 12:00:00 +08:00
committed by GitHub
parent ae96fefdd4
commit 955aa8ced0
3 changed files with 17 additions and 8 deletions

View 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"`

View File

@@ -7,7 +7,12 @@ import {
type legacyAttributes, type legacyAttributes,
} from '@rrweb/types'; } from '@rrweb/types';
import { type tagMap, type BuildCache } from './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'; import postcss from 'postcss';
const tagMap: tagMap = { const tagMap: tagMap = {
@@ -299,16 +304,15 @@ function buildNode(
continue; continue;
} else if ( } else if (
tagName === 'link' && tagName === 'link' &&
(n.attributes.rel === 'preload' || ((n.attributes.rel === 'preload' && n.attributes.as === 'script') ||
n.attributes.rel === 'modulepreload') && n.attributes.rel === 'modulepreload')
n.attributes.as === 'script'
) { ) {
// ignore // ignore
} else if ( } else if (
tagName === 'link' && tagName === 'link' &&
n.attributes.rel === 'prefetch' && n.attributes.rel === 'prefetch' &&
typeof n.attributes.href === 'string' && typeof n.attributes.href === 'string' &&
n.attributes.href.endsWith('.js') extractFileExtension(n.attributes.href) === 'js'
) { ) {
// ignore // ignore
} else if ( } else if (

View File

@@ -819,9 +819,8 @@ function slimDOMExcluded(
(sn.tagName === 'script' || (sn.tagName === 'script' ||
// (module)preload link // (module)preload link
(sn.tagName === 'link' && (sn.tagName === 'link' &&
(sn.attributes.rel === 'preload' || ((sn.attributes.rel === 'preload' && sn.attributes.as === 'script') ||
sn.attributes.rel === 'modulepreload') && sn.attributes.rel === 'modulepreload')) ||
sn.attributes.as === 'script') ||
// prefetch link // prefetch link
(sn.tagName === 'link' && (sn.tagName === 'link' &&
sn.attributes.rel === 'prefetch' && sn.attributes.rel === 'prefetch' &&