Skip to content

Commit

Permalink
fix(snapshot): Change to ignore all link[rel="modulepreload"] (#228)
Browse files Browse the repository at this point in the history
... removes requirement to have `as="script"` attribute. Also fixes
prefetch to extract file extension instead of checking end of string
since there can be URL parameters.
  • Loading branch information
billyvg committed Dec 17, 2024
1 parent 4fd55c0 commit 8a91047
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
12 changes: 8 additions & 4 deletions packages/rrweb-snapshot/src/rebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -265,15 +270,14 @@ function buildNode(
} else if (
tagName === 'link' &&
(n.attributes.rel === 'preload' ||
n.attributes.rel === 'modulepreload') &&
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 (
Expand Down
3 changes: 1 addition & 2 deletions packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -820,8 +820,7 @@ function slimDOMExcluded(
// (module)preload link
(sn.tagName === 'link' &&
(sn.attributes.rel === 'preload' ||
sn.attributes.rel === 'modulepreload') &&
sn.attributes.as === 'script') ||
sn.attributes.rel === 'modulepreload')) ||
// prefetch link
(sn.tagName === 'link' &&
sn.attributes.rel === 'prefetch' &&
Expand Down

0 comments on commit 8a91047

Please sign in to comment.