From 6b6d76c99311614d7b67727747adb1ef51adf78a Mon Sep 17 00:00:00 2001 From: Eoghan Murray Date: Tue, 26 Jan 2021 16:23:41 +0000 Subject: [PATCH] Don't reuse ids when taking a full snapshot; as we are pausing mutations during snapshotting, we can continue afterwards with a freshly built DOM tree which has sequential ids according to the DOM walk (which are thus predictable and can potentially be stripped out during storage of full snapshot event) --- src/snapshot.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/snapshot.ts b/src/snapshot.ts index 3d04acc..4950a30 100644 --- a/src/snapshot.ts +++ b/src/snapshot.ts @@ -465,6 +465,7 @@ export function serializeNodeWithId( slimDOMOptions: SlimDOMOptions; recordCanvas?: boolean; preserveWhiteSpace?: boolean; + isFullSnapshot?: boolean; }, ): serializedNodeWithId | null { const { @@ -477,6 +478,7 @@ export function serializeNodeWithId( maskInputOptions = {}, slimDOMOptions, recordCanvas = false, + isFullSnapshot = false, } = options; let { preserveWhiteSpace = true } = options; const _serializedNode = serializeNode(n, { @@ -495,7 +497,7 @@ export function serializeNodeWithId( let id; // Try to reuse the previous id - if ('__sn' in n) { + if ('__sn' in n && !isFullSnapshot) { id = n.__sn.id; } else if ( slimDOMExcluded(_serializedNode, slimDOMOptions) || @@ -545,6 +547,7 @@ export function serializeNodeWithId( slimDOMOptions, recordCanvas, preserveWhiteSpace, + isFullSnapshot, }); if (serializedChildNode) { serializedNode.childNodes.push(serializedChildNode); @@ -625,6 +628,7 @@ function snapshot( maskInputOptions, slimDOMOptions, recordCanvas, + isFullSnapshot: true, }), idNodeMap, ];