Skip to content

Commit

Permalink
fix(snapshot): Change to ignore all link[rel="modulepreload"]
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 6, 2024
1 parent a6b4a88 commit 042beb5
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 @@ -8,7 +8,12 @@ import {
attributes,

Check warning on line 8 in packages/rrweb-snapshot/src/rebuild.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrweb-snapshot/src/rebuild.ts#L8

[@typescript-eslint/no-unused-vars] 'attributes' is defined but never used.
legacyAttributes,
} from './types';
import { isElement, Mirror, isNodeMetaEqual } from './utils';
import {
isElement,
Mirror,
isNodeMetaEqual,
extractFileExtension,
} from './utils';

const tagMap: tagMap = {
script: 'noscript',
Expand Down Expand Up @@ -245,15 +250,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 @@ -1099,8 +1099,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 042beb5

Please sign in to comment.