-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix duplicated shadow dom #1095
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ba29607
fix: duplicated elements in shadow doms
YunFeng0817 c748b2f
add checker for replayer to make it stable when data has duplicated n…
YunFeng0817 ae3e8a9
apply review suggestions
YunFeng0817 0a290df
Merge branch 'master' into fix-duplicated-shadow-dom
YunFeng0817 36d72e3
add change log
YunFeng0817 5aa1822
Apply formatting changes
08e4b1c
update prettier to fit the master branch
YunFeng0817 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'rrweb-snapshot': patch | ||
'rrweb': patch | ||
--- | ||
|
||
Fix duplicated shadow doms |
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
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
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
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,150 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import { NodeType, serializedNode } from '../src/types'; | ||
import { isNodeMetaEqual } from '../src/utils'; | ||
import { serializedNodeWithId } from 'rrweb-snapshot'; | ||
|
||
describe('utils', () => { | ||
describe('isNodeMetaEqual()', () => { | ||
const document1: serializedNode = { | ||
type: NodeType.Document, | ||
compatMode: 'CSS1Compat', | ||
childNodes: [], | ||
}; | ||
const document2: serializedNode = { | ||
type: NodeType.Document, | ||
compatMode: 'BackCompat', | ||
childNodes: [], | ||
}; | ||
const documentType1: serializedNode = { | ||
type: NodeType.DocumentType, | ||
name: 'html', | ||
publicId: '', | ||
systemId: '', | ||
}; | ||
const documentType2: serializedNode = { | ||
type: NodeType.DocumentType, | ||
name: 'html', | ||
publicId: '', | ||
systemId: 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd', | ||
}; | ||
const text1: serializedNode = { | ||
type: NodeType.Text, | ||
textContent: 'Hello World', | ||
}; | ||
const text2: serializedNode = { | ||
type: NodeType.Text, | ||
textContent: 'Hello world', | ||
}; | ||
const comment1: serializedNode = { | ||
type: NodeType.Comment, | ||
textContent: 'Hello World', | ||
}; | ||
const comment2: serializedNode = { | ||
type: NodeType.Comment, | ||
textContent: 'Hello world', | ||
}; | ||
const element1: serializedNode = { | ||
type: NodeType.Element, | ||
tagName: 'div', | ||
attributes: { | ||
className: 'test', | ||
}, | ||
childNodes: [], | ||
}; | ||
const element2: serializedNode = { | ||
type: NodeType.Element, | ||
tagName: 'span', | ||
attributes: { | ||
'aria-label': 'Hello World', | ||
}, | ||
childNodes: [], | ||
}; | ||
const element3: serializedNode = { | ||
type: NodeType.Element, | ||
tagName: 'div', | ||
attributes: { id: 'test' }, | ||
childNodes: [comment1 as serializedNodeWithId], | ||
}; | ||
|
||
it('should return false if two nodes have different node types', () => { | ||
expect( | ||
isNodeMetaEqual( | ||
undefined as unknown as serializedNode, | ||
null as unknown as serializedNode, | ||
), | ||
).toBeFalsy(); | ||
expect(isNodeMetaEqual(document1, element1)).toBeFalsy(); | ||
expect(isNodeMetaEqual(document1, documentType1)).toBeFalsy(); | ||
expect(isNodeMetaEqual(documentType1, element1)).toBeFalsy(); | ||
expect(isNodeMetaEqual(text1, comment1)).toBeFalsy(); | ||
expect(isNodeMetaEqual(text1, element1)).toBeFalsy(); | ||
expect(isNodeMetaEqual(comment1, element1)).toBeFalsy(); | ||
}); | ||
|
||
it('should compare meta data of two document nodes', () => { | ||
expect( | ||
isNodeMetaEqual(document1, JSON.parse(JSON.stringify(document1))), | ||
).toBeTruthy(); | ||
expect( | ||
isNodeMetaEqual(JSON.parse(JSON.stringify(document2)), document2), | ||
).toBeTruthy(); | ||
expect(isNodeMetaEqual(document1, document2)).toBeFalsy(); | ||
}); | ||
|
||
it('should compare meta data of two documentType nodes', () => { | ||
expect( | ||
isNodeMetaEqual( | ||
documentType1, | ||
JSON.parse(JSON.stringify(documentType1)), | ||
), | ||
).toBeTruthy(); | ||
expect( | ||
isNodeMetaEqual( | ||
JSON.parse(JSON.stringify(documentType2)), | ||
documentType2, | ||
), | ||
).toBeTruthy(); | ||
expect(isNodeMetaEqual(documentType1, documentType2)).toBeFalsy(); | ||
}); | ||
|
||
it('should compare meta data of two text nodes', () => { | ||
expect( | ||
isNodeMetaEqual(text1, JSON.parse(JSON.stringify(text1))), | ||
).toBeTruthy(); | ||
expect( | ||
isNodeMetaEqual(JSON.parse(JSON.stringify(text2)), text2), | ||
).toBeTruthy(); | ||
expect(isNodeMetaEqual(text1, text2)).toBeFalsy(); | ||
}); | ||
|
||
it('should compare meta data of two comment nodes', () => { | ||
expect( | ||
isNodeMetaEqual(comment1, JSON.parse(JSON.stringify(comment1))), | ||
).toBeTruthy(); | ||
expect( | ||
isNodeMetaEqual(JSON.parse(JSON.stringify(comment2)), comment2), | ||
).toBeTruthy(); | ||
expect(isNodeMetaEqual(comment1, comment2)).toBeFalsy(); | ||
}); | ||
|
||
it('should compare meta data of two HTML elements', () => { | ||
expect( | ||
isNodeMetaEqual(element1, JSON.parse(JSON.stringify(element1))), | ||
).toBeTruthy(); | ||
expect( | ||
isNodeMetaEqual(JSON.parse(JSON.stringify(element2)), element2), | ||
).toBeTruthy(); | ||
expect( | ||
isNodeMetaEqual(element1, { | ||
...element1, | ||
childNodes: [comment2 as serializedNodeWithId], | ||
}), | ||
).toBeTruthy(); | ||
expect(isNodeMetaEqual(element1, element2)).toBeFalsy(); | ||
expect(isNodeMetaEqual(element1, element3)).toBeFalsy(); | ||
expect(isNodeMetaEqual(element2, element3)).toBeFalsy(); | ||
}); | ||
}); | ||
}); |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is quite a slow call to do, aren't you afraid this will slow down repeated
rrweb.takeFullSnapshot(true)
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also what happens if a node gets a new attribute since the last time it was snapshotted? Will this node get added twice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you are right, this function is slow. It's in the rebuilt.ts so I don't think this can slow down the takeFullSnapshot function. If the data events are correct, the program won't go to this path. This comparison will only be used when rrweb ingests any problematic data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the recorder works well, the incremental data will only change the node's attribute rather than totally recreate the node through this path.
In case the program goes here, the node will get added twice as you said. But honestly, I don't know what kind of error event data can lead to this. I wrote this function as a fallback.
Do you have any suggestions for improving the code here?