forked from rrweb-io/rrweb
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: inserted styles lost when moving elements
fix code for nodejs tests change fix direction to avoid issues with duplicate styles change fix direction to avoid issues with duplicate styles
- Loading branch information
Showing
3 changed files
with
286 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
205 changes: 205 additions & 0 deletions
205
packages/rrweb/test/events/moving-style-sheet-on-diff.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
import { EventType, IncrementalSource } from '@rrweb/types'; | ||
import type { eventWithTime } from '@rrweb/types'; | ||
|
||
const now = Date.now(); | ||
const events: eventWithTime[] = [ | ||
{ | ||
type: EventType.DomContentLoaded, | ||
data: {}, | ||
timestamp: now, | ||
}, | ||
{ | ||
type: EventType.Load, | ||
data: {}, | ||
timestamp: now + 10, | ||
}, | ||
{ | ||
type: EventType.Meta, | ||
data: { | ||
href: 'http://localhost', | ||
width: 1000, | ||
height: 800, | ||
}, | ||
timestamp: now + 10, | ||
}, | ||
// full snapshot: | ||
{ | ||
data: { | ||
node: { | ||
type: 0, | ||
childNodes: [ | ||
{ | ||
type: 1, | ||
name: 'html', | ||
publicId: '', | ||
systemId: '', | ||
id: 2, | ||
}, | ||
{ | ||
type: 2, | ||
tagName: 'html', | ||
attributes: { | ||
lang: 'en', | ||
}, | ||
childNodes: [ | ||
{ | ||
type: 2, | ||
tagName: 'head', | ||
attributes: {}, | ||
childNodes: [ | ||
{ | ||
type: 2, | ||
tagName: 'style', | ||
attributes: {}, | ||
childNodes: [ | ||
{ | ||
type: 3, | ||
textContent: | ||
'#wrapper { width: 200px; margin: 50px auto; background-color: gainsboro; padding: 20px; }.target-element { padding: 12px; margin-top: 12px; }', | ||
isStyle: true, | ||
id: 6, | ||
}, | ||
], | ||
id: 5, | ||
}, | ||
{ | ||
type: 2, | ||
tagName: 'style', | ||
attributes: {}, | ||
childNodes: [ | ||
{ | ||
type: 3, | ||
textContent: | ||
'.new-element-class { font-size: 32px; color: tomato; }', | ||
isStyle: true, | ||
id: 8, | ||
}, | ||
], | ||
id: 7, | ||
}, | ||
], | ||
id: 4, | ||
}, | ||
{ | ||
type: 2, | ||
tagName: 'body', | ||
attributes: {}, | ||
childNodes: [ | ||
{ | ||
type: 2, | ||
tagName: 'div', | ||
attributes: { | ||
id: 'wrapper', | ||
}, | ||
childNodes: [ | ||
{ | ||
type: 2, | ||
tagName: 'div', | ||
attributes: { | ||
class: 'target-element', | ||
}, | ||
childNodes: [ | ||
{ | ||
type: 2, | ||
tagName: 'p', | ||
attributes: { | ||
class: 'target-element-child', | ||
}, | ||
childNodes: [ | ||
{ | ||
type: 3, | ||
textContent: 'Element to style', | ||
id: 113, | ||
}, | ||
], | ||
id: 12, | ||
}, | ||
], | ||
id: 11, | ||
}, | ||
], | ||
id: 10, | ||
}, | ||
], | ||
id: 9, | ||
}, | ||
], | ||
id: 3, | ||
}, | ||
], | ||
id: 1, | ||
}, | ||
initialOffset: { | ||
left: 0, | ||
top: 0, | ||
}, | ||
}, | ||
type: EventType.FullSnapshot, | ||
timestamp: now + 20, | ||
}, | ||
// 1st mutation that applies StyleSheetRule | ||
{ | ||
type: EventType.IncrementalSnapshot, | ||
data: { | ||
source: IncrementalSource.StyleSheetRule, | ||
id: 5, | ||
adds: [ | ||
{ | ||
rule: '.target-element{background-color:teal;}', | ||
}, | ||
], | ||
}, | ||
timestamp: now + 30, | ||
}, | ||
// 2nd mutation inserts new style element to trigger other style element to get moved in diff | ||
{ | ||
type: EventType.IncrementalSnapshot, | ||
data: { | ||
source: IncrementalSource.Mutation, | ||
texts: [], | ||
attributes: [], | ||
removes: [ | ||
{ parentId: 4, id: 7 } | ||
], | ||
adds: [ | ||
{ | ||
parentId: 4, | ||
nextId: 5, | ||
node: { | ||
type: 2, | ||
tagName: 'style', | ||
attributes: {}, | ||
childNodes: [], | ||
id: 98, | ||
}, | ||
}, | ||
{ | ||
parentId: 98, | ||
nextId: null, | ||
node: { | ||
type: 3, | ||
textContent: | ||
'.new-element-class { font-size: 32px; color: tomato; }', | ||
isStyle: true, | ||
id: 99, | ||
}, | ||
}, | ||
], | ||
}, | ||
timestamp: now + 2000, | ||
}, | ||
// dummy event to have somewhere to skip | ||
{ | ||
data: { | ||
adds: [], | ||
texts: [], | ||
source: IncrementalSource.Mutation, | ||
removes: [], | ||
attributes: [], | ||
}, | ||
type: EventType.IncrementalSnapshot, | ||
timestamp: now + 3000, | ||
}, | ||
]; | ||
|
||
export default events; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters