Skip to content

Commit

Permalink
fix(snapshot): dimensions for blocked element not being applied (rrwe…
Browse files Browse the repository at this point in the history
…b-io#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
  • Loading branch information
billyvg authored Sep 20, 2024
1 parent 8e55c45 commit 02cc62d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-dolls-grab.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"rrweb-snapshot": patch
---

fix dimensions for blocked element not being applied
28 changes: 28 additions & 0 deletions packages/rrdom/test/virtual-dom.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as puppeteer from 'puppeteer';
import { vi } from 'vitest';
import { JSDOM } from 'jsdom';
import {
buildNodeWithSN,
cdataNode,
commentNode,
documentNode,
Expand Down Expand Up @@ -207,6 +208,33 @@ describe('RRDocument for browser environment', () => {
expect((rrNode as RRElement).tagName).toEqual('SHADOWROOT');
expect(rrNode).toBe(parentRRNode.shadowRoot);
});

it('can rebuild blocked element with correct dimensions', () => {
// @ts-expect-error Testing buildNodeWithSN with rr elements
const node = buildNodeWithSN(
{
id: 1,
tagName: 'svg',
type: NodeType.Element,
isSVG: true,
attributes: {
rr_width: '50px',
rr_height: '50px',
},
childNodes: [],
},
{
// @ts-expect-error
doc: new RRDocument(),
mirror,
blockSelector: '*',
slimDOMOptions: {},
},
) as RRElement;

expect(node.style.width).toBe('50px');
expect(node.style.height).toBe('50px');
});
});

describe('create a RRDocument from a html document', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/rrweb-snapshot/src/rebuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ function buildNode(
}

if (name === 'rr_width') {
(node as HTMLElement).style.width = value.toString();
(node as HTMLElement).style.setProperty('width', value.toString());
} else if (name === 'rr_height') {
(node as HTMLElement).style.height = value.toString();
(node as HTMLElement).style.setProperty('height', value.toString());
} else if (
name === 'rr_mediaCurrentTime' &&
typeof value === 'number'
Expand Down
26 changes: 26 additions & 0 deletions packages/rrweb-snapshot/test/rebuild.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,32 @@ describe('rebuild', function () {
});
});

describe('rr_width/rr_height', function () {
it('rebuild blocked element with correct dimensions', function () {
const node = buildNodeWithSN(
{
id: 1,
tagName: 'svg',
type: NodeType.Element,
isSVG: true,
attributes: {
rr_width: '50px',
rr_height: '50px',
},
childNodes: [],
},
{
doc: document,
mirror,
hackCss: false,
cache,
},
) as HTMLDivElement;
expect(node.style.width).toBe('50px');
expect(node.style.height).toBe('50px');
});
});

describe('shadowDom', function () {
it('rebuild shadowRoot without siblings', function () {
const node = buildNodeWithSN(
Expand Down

0 comments on commit 02cc62d

Please sign in to comment.