Skip to content
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

⚡️ [RUMF-902] enable new mutation observer #842

Merged
merged 9 commits into from
May 12, 2021
1 change: 0 additions & 1 deletion packages/rum-recorder/src/boot/recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export function startRecording(

const { stop: stopRecording, takeFullSnapshot } = record({
emit: addRawRecord,
useNewMutationObserver: configuration.isEnabled('new-mutation-observer'),
})

lifeCycle.subscribe(LifeCycleEventType.VIEW_CREATED, takeFullSnapshot)
Expand Down
4 changes: 2 additions & 2 deletions packages/rum-recorder/src/domain/rrweb-snapshot/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { serializeNodeWithId, transformAttribute, snapshot } from './snapshot'
import { serializeNodeWithId, transformAttribute, serializeDocument } from './snapshot'
export * from './types'
export * from './serializationUtils'

export { snapshot, serializeNodeWithId, transformAttribute }
export { serializeDocument, serializeNodeWithId, transformAttribute }
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ describe('serializeNodeWithId', () => {
describe('ignores some nodes', () => {
const defaultOptions = {
doc: document,
skipChild: false,
map: {},
}

Expand Down
35 changes: 12 additions & 23 deletions packages/rum-recorder/src/domain/rrweb-snapshot/snapshot.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { nodeShouldBeHidden } from '../privacy'
import { PRIVACY_ATTR_NAME, PRIVACY_ATTR_VALUE_HIDDEN } from '../../constants'
import { SerializedNode, SerializedNodeWithId, NodeType, Attributes, INode, IdNodeMap } from './types'
import { SerializedNode, SerializedNodeWithId, NodeType, Attributes, IdNodeMap } from './types'
import { getSerializedNodeId, hasSerializedNode, IGNORED_NODE_ID, setSerializedNode } from './serializationUtils'

const tagNameRegex = /[^a-z1-6-_]/
Expand All @@ -10,11 +10,6 @@ function genId(): number {
return nextId++
}

export function cleanupSnapshot() {
// allow a new recording to start numbering nodes from scratch
nextId = 1
}

function getValidTagName(tagName: string): string {
const processedTagName = tagName.toLowerCase().trim()

Expand Down Expand Up @@ -358,15 +353,14 @@ function nodeShouldBeIgnored(sn: SerializedNode): boolean {
}

export function serializeNodeWithId(
n: Node | INode,
n: Node,
options: {
doc: Document
map: IdNodeMap
skipChild: boolean
preserveWhiteSpace?: boolean
}
): SerializedNodeWithId | null {
const { doc, map, skipChild = false } = options
const { doc, map } = options
let { preserveWhiteSpace = true } = options
const serializedNode = serializeNode(n, {
doc,
Expand Down Expand Up @@ -398,10 +392,10 @@ export function serializeNodeWithId(
if (id === IGNORED_NODE_ID) {
return null
}
map[id] = n as INode
let recordChild = !skipChild
map[id] = true
let recordChild = true
if (serializedNode.type === NodeType.Element) {
recordChild = recordChild && !serializedNode.shouldBeHidden
recordChild = !serializedNode.shouldBeHidden
// this property was not needed in replay side
delete serializedNode.shouldBeHidden
}
Expand All @@ -417,7 +411,6 @@ export function serializeNodeWithId(
const serializedChildNode = serializeNodeWithId(childN, {
doc,
map,
skipChild,
preserveWhiteSpace,
})
if (serializedChildNode) {
Expand All @@ -428,14 +421,10 @@ export function serializeNodeWithId(
return serializedNodeWithId
}

export function snapshot(n: Document): [SerializedNodeWithId | null, IdNodeMap] {
const idNodeMap: IdNodeMap = {}
return [
serializeNodeWithId(n, {
doc: n,
map: idNodeMap,
skipChild: false,
}),
idNodeMap,
]
export function serializeDocument(n: Document): SerializedNodeWithId {
bcaudan marked this conversation as resolved.
Show resolved Hide resolved
// We are sure that Documents are never ignored, so this function never returns null
return serializeNodeWithId(n, {
doc: n,
map: {},
})!
}
6 changes: 1 addition & 5 deletions packages/rum-recorder/src/domain/rrweb-snapshot/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ export type SerializedNode = DocumentNode | DocumentTypeNode | ElementNode | Tex

export type SerializedNodeWithId = SerializedNode & { id: number }

export interface INode extends Node {
__sn: SerializedNodeWithId
}

export type IdNodeMap = {
[key: number]: INode
[key: number]: true
}
72 changes: 0 additions & 72 deletions packages/rum-recorder/src/domain/rrweb/mutation.spec.ts

This file was deleted.

Loading