Skip to content

Commit 02cc62d

Browse files
authored
fix(snapshot): dimensions for blocked element not being applied (#1331)
fix for replay of a blocked element when using 'fast forward' (rrdom) - Dimensions were not being properly applied when you seek to a position in the replay. Need to use `setProperty` rather than trying to set the width/height directly
1 parent 8e55c45 commit 02cc62d

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

.changeset/perfect-dolls-grab.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"rrweb-snapshot": patch
3+
---
4+
5+
fix dimensions for blocked element not being applied

packages/rrdom/test/virtual-dom.test.ts

+28
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as puppeteer from 'puppeteer';
77
import { vi } from 'vitest';
88
import { JSDOM } from 'jsdom';
99
import {
10+
buildNodeWithSN,
1011
cdataNode,
1112
commentNode,
1213
documentNode,
@@ -207,6 +208,33 @@ describe('RRDocument for browser environment', () => {
207208
expect((rrNode as RRElement).tagName).toEqual('SHADOWROOT');
208209
expect(rrNode).toBe(parentRRNode.shadowRoot);
209210
});
211+
212+
it('can rebuild blocked element with correct dimensions', () => {
213+
// @ts-expect-error Testing buildNodeWithSN with rr elements
214+
const node = buildNodeWithSN(
215+
{
216+
id: 1,
217+
tagName: 'svg',
218+
type: NodeType.Element,
219+
isSVG: true,
220+
attributes: {
221+
rr_width: '50px',
222+
rr_height: '50px',
223+
},
224+
childNodes: [],
225+
},
226+
{
227+
// @ts-expect-error
228+
doc: new RRDocument(),
229+
mirror,
230+
blockSelector: '*',
231+
slimDOMOptions: {},
232+
},
233+
) as RRElement;
234+
235+
expect(node.style.width).toBe('50px');
236+
expect(node.style.height).toBe('50px');
237+
});
210238
});
211239

212240
describe('create a RRDocument from a html document', () => {

packages/rrweb-snapshot/src/rebuild.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,9 @@ function buildNode(
328328
}
329329

330330
if (name === 'rr_width') {
331-
(node as HTMLElement).style.width = value.toString();
331+
(node as HTMLElement).style.setProperty('width', value.toString());
332332
} else if (name === 'rr_height') {
333-
(node as HTMLElement).style.height = value.toString();
333+
(node as HTMLElement).style.setProperty('height', value.toString());
334334
} else if (
335335
name === 'rr_mediaCurrentTime' &&
336336
typeof value === 'number'

packages/rrweb-snapshot/test/rebuild.test.ts

+26
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,32 @@ describe('rebuild', function () {
7272
});
7373
});
7474

75+
describe('rr_width/rr_height', function () {
76+
it('rebuild blocked element with correct dimensions', function () {
77+
const node = buildNodeWithSN(
78+
{
79+
id: 1,
80+
tagName: 'svg',
81+
type: NodeType.Element,
82+
isSVG: true,
83+
attributes: {
84+
rr_width: '50px',
85+
rr_height: '50px',
86+
},
87+
childNodes: [],
88+
},
89+
{
90+
doc: document,
91+
mirror,
92+
hackCss: false,
93+
cache,
94+
},
95+
) as HTMLDivElement;
96+
expect(node.style.width).toBe('50px');
97+
expect(node.style.height).toBe('50px');
98+
});
99+
});
100+
75101
describe('shadowDom', function () {
76102
it('rebuild shadowRoot without siblings', function () {
77103
const node = buildNodeWithSN(

0 commit comments

Comments
 (0)