<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,
|
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 (
|
||||||
|
|||||||
@@ -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' &&
|
||||||
|
|||||||
Reference in New Issue
Block a user