Skip to content

Commit 5c26751

Browse files
committed
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)
1 parent d9d3e54 commit 5c26751

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/snapshot.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,7 @@ export function serializeNodeWithId(
652652
onSerialize?: (n: INode) => unknown;
653653
onIframeLoad?: (iframeINode: INode, node: serializedNodeWithId) => unknown;
654654
iframeLoadTimeout?: number;
655+
isFullSnapshot?: boolean;
655656
},
656657
): serializedNodeWithId | null {
657658
const {
@@ -670,6 +671,7 @@ export function serializeNodeWithId(
670671
onSerialize,
671672
onIframeLoad,
672673
iframeLoadTimeout = 5000,
674+
isFullSnapshot = false,
673675
} = options;
674676
let { preserveWhiteSpace = true } = options;
675677
const _serializedNode = serializeNode(n, {
@@ -691,7 +693,7 @@ export function serializeNodeWithId(
691693

692694
let id;
693695
// Try to reuse the previous id
694-
if ('__sn' in n) {
696+
if ('__sn' in n && !isFullSnapshot) {
695697
id = n.__sn.id;
696698
} else if (
697699
slimDOMExcluded(_serializedNode, slimDOMOptions) ||
@@ -749,6 +751,7 @@ export function serializeNodeWithId(
749751
onSerialize,
750752
onIframeLoad,
751753
iframeLoadTimeout,
754+
isFullSnapshot,
752755
};
753756
for (const childN of Array.from(n.childNodes)) {
754757
const serializedChildNode = serializeNodeWithId(childN, bypassOptions);
@@ -908,6 +911,7 @@ function snapshot(
908911
onSerialize,
909912
onIframeLoad,
910913
iframeLoadTimeout,
914+
isFullSnapshot: true,
911915
}),
912916
idNodeMap,
913917
];

0 commit comments

Comments
 (0)