From a1477ff2303f54159f10984b7bfc8d5826a3be94 Mon Sep 17 00:00:00 2001 From: Billy Vong Date: Tue, 10 Dec 2024 13:52:11 -0500 Subject: [PATCH 1/2] fix(snapshot): Change to ignore all `link[rel="modulepreload"]` (#228) ... 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. --- packages/rrweb-snapshot/src/rebuild.ts | 12 ++++++++---- packages/rrweb-snapshot/src/snapshot.ts | 3 +-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/rrweb-snapshot/src/rebuild.ts b/packages/rrweb-snapshot/src/rebuild.ts index f83ac0bc0b..b8c22bd74e 100644 --- a/packages/rrweb-snapshot/src/rebuild.ts +++ b/packages/rrweb-snapshot/src/rebuild.ts @@ -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 = { @@ -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 ( diff --git a/packages/rrweb-snapshot/src/snapshot.ts b/packages/rrweb-snapshot/src/snapshot.ts index 0e8ec68be9..35f21b1a58 100644 --- a/packages/rrweb-snapshot/src/snapshot.ts +++ b/packages/rrweb-snapshot/src/snapshot.ts @@ -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' && From ac9f15bf357ca59c9dccc4158081f57bf7f9b0e7 Mon Sep 17 00:00:00 2001 From: Billy Vong Date: Mon, 20 Jan 2025 13:07:32 -0500 Subject: [PATCH 2/2] include changeset --- .changeset/short-hounds-confess.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/short-hounds-confess.md diff --git a/.changeset/short-hounds-confess.md b/.changeset/short-hounds-confess.md new file mode 100644 index 0000000000..7cb8b0d5e2 --- /dev/null +++ b/.changeset/short-hounds-confess.md @@ -0,0 +1,6 @@ +--- +"rrweb-snapshot": patch +"rrweb": patch +--- + +Change to ignore all link[rel="modulepreload"] instead of including only those with `as="script"`