Skip to content

Commit

Permalink
Don't reuse ids when taking a full snapshot; as we are pausing mutati…
Browse files Browse the repository at this point in the history
…ons 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)
  • Loading branch information
eoghanmurray committed Jun 15, 2021
1 parent d9d3e54 commit 5c26751
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,7 @@ export function serializeNodeWithId(
onSerialize?: (n: INode) => unknown;
onIframeLoad?: (iframeINode: INode, node: serializedNodeWithId) => unknown;
iframeLoadTimeout?: number;
isFullSnapshot?: boolean;
},
): serializedNodeWithId | null {
const {
Expand All @@ -670,6 +671,7 @@ export function serializeNodeWithId(
onSerialize,
onIframeLoad,
iframeLoadTimeout = 5000,
isFullSnapshot = false,
} = options;
let { preserveWhiteSpace = true } = options;
const _serializedNode = serializeNode(n, {
Expand All @@ -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) ||
Expand Down Expand Up @@ -749,6 +751,7 @@ export function serializeNodeWithId(
onSerialize,
onIframeLoad,
iframeLoadTimeout,
isFullSnapshot,
};
for (const childN of Array.from(n.childNodes)) {
const serializedChildNode = serializeNodeWithId(childN, bypassOptions);
Expand Down Expand Up @@ -908,6 +911,7 @@ function snapshot(
onSerialize,
onIframeLoad,
iframeLoadTimeout,
isFullSnapshot: true,
}),
idNodeMap,
];
Expand Down

0 comments on commit 5c26751

Please sign in to comment.