Skip to content

Commit 4c2af79

Browse files
committed
Was trying to 'catch out' the mutation handling by having siblings present on mutation processing before they could be added, but couldn't (deliberately) break anything. Adding test anyway as it might throw up an interesting scenario
1 parent 7734331 commit 4c2af79

File tree

3 files changed

+80
-2
lines changed

3 files changed

+80
-2
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<!DOCTYPE html>
22
<html>
3-
<body>
4-
</body>
3+
<body></body>
54
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
[
2+
{
3+
"type": 3,
4+
"data": {
5+
"source": 0,
6+
"texts": [],
7+
"attributes": [],
8+
"removes": [
9+
{
10+
"parentId": 7,
11+
"id": 8
12+
}
13+
],
14+
"adds": [
15+
{
16+
"parentId": 7,
17+
"nextId": null,
18+
"node": {
19+
"type": 2,
20+
"tagName": "div",
21+
"attributes": {},
22+
"childNodes": [],
23+
"id": 9
24+
}
25+
}
26+
]
27+
}
28+
},
29+
{
30+
"type": 3,
31+
"data": {
32+
"source": 0,
33+
"texts": [],
34+
"attributes": [],
35+
"removes": [],
36+
"adds": [
37+
{
38+
"parentId": 7,
39+
"nextId": null,
40+
"node": {
41+
"type": 2,
42+
"tagName": "div",
43+
"attributes": {},
44+
"childNodes": [],
45+
"id": 10
46+
}
47+
},
48+
{
49+
"parentId": 7,
50+
"nextId": 9,
51+
"node": {
52+
"type": 2,
53+
"tagName": "div",
54+
"attributes": {},
55+
"childNodes": [],
56+
"id": 11
57+
}
58+
}
59+
]
60+
}
61+
}
62+
]

packages/rrweb/test/record/mutation.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,4 +262,21 @@ describe('mutation', () => {
262262
const mutations = events.filter((e)=>e.type === EventType.IncrementalSnapshot);
263263
await assertSnapshot(mutations, true);
264264
});
265+
266+
it('siblings added in idleCallback', async () => {
267+
await page.evaluate(() => {
268+
document.body.childNodes.forEach((cn) => document.body.removeChild(cn)); // clear out text nodes created by server
269+
document.body.prepend(document.createElement('div'));
270+
requestAnimationFrame(() => {
271+
//rrweb.freezePage();
272+
document.body.prepend(document.createElement('div'));
273+
document.body.append(document.createElement('div'));
274+
});
275+
});
276+
await waitForRAF(page);
277+
const mutations = events.filter(
278+
(e) => e.type === EventType.IncrementalSnapshot,
279+
);
280+
await assertSnapshot(mutations, true);
281+
});
265282
});

0 commit comments

Comments
 (0)