Skip to content

Commit 6b6d76c

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 c1c687a commit 6b6d76c

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
@@ -465,6 +465,7 @@ export function serializeNodeWithId(
465465
slimDOMOptions: SlimDOMOptions;
466466
recordCanvas?: boolean;
467467
preserveWhiteSpace?: boolean;
468+
isFullSnapshot?: boolean;
468469
},
469470
): serializedNodeWithId | null {
470471
const {
@@ -477,6 +478,7 @@ export function serializeNodeWithId(
477478
maskInputOptions = {},
478479
slimDOMOptions,
479480
recordCanvas = false,
481+
isFullSnapshot = false,
480482
} = options;
481483
let { preserveWhiteSpace = true } = options;
482484
const _serializedNode = serializeNode(n, {
@@ -495,7 +497,7 @@ export function serializeNodeWithId(
495497

496498
let id;
497499
// Try to reuse the previous id
498-
if ('__sn' in n) {
500+
if ('__sn' in n && !isFullSnapshot) {
499501
id = n.__sn.id;
500502
} else if (
501503
slimDOMExcluded(_serializedNode, slimDOMOptions) ||
@@ -545,6 +547,7 @@ export function serializeNodeWithId(
545547
slimDOMOptions,
546548
recordCanvas,
547549
preserveWhiteSpace,
550+
isFullSnapshot,
548551
});
549552
if (serializedChildNode) {
550553
serializedNode.childNodes.push(serializedChildNode);
@@ -625,6 +628,7 @@ function snapshot(
625628
maskInputOptions,
626629
slimDOMOptions,
627630
recordCanvas,
631+
isFullSnapshot: true,
628632
}),
629633
idNodeMap,
630634
];

0 commit comments

Comments
 (0)