-
Notifications
You must be signed in to change notification settings - Fork 170
⚗ [RUMF-902] implement a new mutation observer #810
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
Merged
BenoitZugmeyer
merged 15 commits into
master
from
benoit/reimplement-mutation-processing
Apr 30, 2021
Merged
Changes from 3 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
350bf67
🏗 [RUMF-902] introduce serializationUtils
BenoitZugmeyer ad81ffe
⚗ [RUMF-902] implement a new mutation observer
BenoitZugmeyer 3863583
🚩 [RUMF-902] use the new mutation observer via a FF
BenoitZugmeyer 50ec8a7
👌 apply some suggestions from code review
BenoitZugmeyer 826c5b0
rename utils.spec to serializationUtils.spec
BenoitZugmeyer e1fff95
👌 remove undefined properties when using existing nodes more thoroughly
BenoitZugmeyer f871a06
👌 remove the "handleMutations" function
BenoitZugmeyer fa95ba9
👌 make sure 'nodeIsIgnored' is only called with serialized nodes
BenoitZugmeyer 0d4e024
👌 rename a few things in the mutationObserver.spec
BenoitZugmeyer 6e4daeb
👌 clarify some mutationObserver tests
BenoitZugmeyer 6a232ed
👌 remove useless uses of [0] for unused snapshot results
BenoitZugmeyer 6e445db
👌 move and rename sortNodesByTopologicalOrder
BenoitZugmeyer 581bc9d
👌 remove unneeded record.spec unit test
BenoitZugmeyer 7492909
Update record spec test title
BenoitZugmeyer 0d860e0
Merge branch 'master' into benoit/reimplement-mutation-processing
BenoitZugmeyer 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import { serializeNodeWithId, transformAttribute, IGNORED_NODE, snapshot } from './snapshot' | ||
| import { serializeNodeWithId, transformAttribute, snapshot } from './snapshot' | ||
| export * from './types' | ||
| export * from './serializationUtils' | ||
|
|
||
| export { snapshot, serializeNodeWithId, transformAttribute, IGNORED_NODE } | ||
| export { snapshot, serializeNodeWithId, transformAttribute } |
36 changes: 36 additions & 0 deletions
36
packages/rum-recorder/src/domain/rrweb-snapshot/serializationUtils.ts
This file contains hidden or 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,36 @@ | ||
| import { SerializedNodeWithId } from './types' | ||
|
|
||
| export const IGNORED_NODE_ID = -2 | ||
|
|
||
| export interface NodeWithSerializedNode extends Node { | ||
| __sn: SerializedNodeWithId | ||
| } | ||
|
|
||
| export function hasSerializedNode(n: Node): n is NodeWithSerializedNode { | ||
| return '__sn' in n | ||
| } | ||
|
|
||
| export function getSerializedNodeId(n: NodeWithSerializedNode): number | ||
| export function getSerializedNodeId(n: Node): number | undefined | ||
| export function getSerializedNodeId(n: Node) { | ||
| return hasSerializedNode(n) ? n.__sn.id : undefined | ||
| } | ||
|
|
||
| export function setSerializedNode(n: Node, serializeNode: SerializedNodeWithId) { | ||
| ;(n as Partial<NodeWithSerializedNode>).__sn = serializeNode | ||
| } | ||
|
|
||
| export function nodeIsIgnored(n: Node): boolean { | ||
| return getSerializedNodeId(n) === IGNORED_NODE_ID | ||
| } | ||
|
|
||
| export function nodeOrAncestorsIsIgnored(n: Node) { | ||
| let current: Node | null = n | ||
| while (current) { | ||
| if (nodeIsIgnored(current)) { | ||
| return true | ||
| } | ||
| current = current.parentNode | ||
| } | ||
| return false | ||
| } | ||
This file contains hidden or 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 hidden or 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
29 changes: 29 additions & 0 deletions
29
packages/rum-recorder/src/domain/rrweb-snapshot/utils.spec.ts
This file contains hidden or 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,29 @@ | ||
| import { getSerializedNodeId, hasSerializedNode, setSerializedNode } from './serializationUtils' | ||
|
|
||
BenoitZugmeyer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| describe('serialized Node storage in DOM Nodes', () => { | ||
| describe('hasSerializedNode', () => { | ||
| it('returns false for DOM Nodes that are not yet serialized', () => { | ||
| expect(hasSerializedNode(document.createElement('div'))).toBe(false) | ||
| }) | ||
|
|
||
| it('returns true for DOM Nodes that have been serialized', () => { | ||
| const node = document.createElement('div') | ||
| setSerializedNode(node, {} as any) | ||
|
|
||
| expect(hasSerializedNode(node)).toBe(true) | ||
| }) | ||
| }) | ||
|
|
||
| describe('getSerializedNodeId', () => { | ||
| it('returns undefined for DOM Nodes that are not yet serialized', () => { | ||
| expect(getSerializedNodeId(document.createElement('div'))).toBe(undefined) | ||
| }) | ||
|
|
||
| it('returns the serialized Node id', () => { | ||
| const node = document.createElement('div') | ||
| setSerializedNode(node, { id: 42 } as any) | ||
|
|
||
| expect(getSerializedNodeId(node)).toBe(42) | ||
| }) | ||
| }) | ||
| }) | ||
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.