From 5c26751a6ef22d9dbbf7d89b20c19376d0f0ead8 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 c6249eb..c25ce1c 100644 --- a/src/snapshot.ts +++ b/src/snapshot.ts @@ -652,6 +652,7 @@ export function serializeNodeWithId( onSerialize?: (n: INode) => unknown; onIframeLoad?: (iframeINode: INode, node: serializedNodeWithId) => unknown; iframeLoadTimeout?: number; + isFullSnapshot?: boolean; }, ): serializedNodeWithId | null { const { @@ -670,6 +671,7 @@ export function serializeNodeWithId( onSerialize, onIframeLoad, iframeLoadTimeout = 5000, + isFullSnapshot = false, } = options; let { preserveWhiteSpace = true } = options; const _serializedNode = serializeNode(n, { @@ -691,7 +693,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) || @@ -749,6 +751,7 @@ export function serializeNodeWithId( onSerialize, onIframeLoad, iframeLoadTimeout, + isFullSnapshot, }; for (const childN of Array.from(n.childNodes)) { const serializedChildNode = serializeNodeWithId(childN, bypassOptions); @@ -908,6 +911,7 @@ function snapshot( onSerialize, onIframeLoad, iframeLoadTimeout, + isFullSnapshot: true, }), idNodeMap, ];