From 14dadb48ffece6bc2977e260bef77d87b1436966 Mon Sep 17 00:00:00 2001 From: Eoghan Murray Date: Mon, 9 Oct 2023 14:14:19 +0100 Subject: [PATCH] Fix a replay issue where the 500ms timeout was being hit - 3.7K nodes being inserted, with ~200 s as the root nodes making up the `resolveTrees` - each table row was dependent on the next, resulting in cascading failures; 19K repopulation of queue due to `nextNotInDOM`, and an additional cascading 350K repopulation of queue due to missing parent nodes --- packages/rrweb/src/utils.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/rrweb/src/utils.ts b/packages/rrweb/src/utils.ts index 604c8810e2..aee2e8757c 100644 --- a/packages/rrweb/src/utils.ts +++ b/packages/rrweb/src/utils.ts @@ -344,6 +344,7 @@ export function queueToResolveTrees(queue: addedNodeMutation[]): ResolveTree[] { queueNodeMap[m.node.id] = nodeInTree; return nodeInTree; }; + const rootNexts = new Set(); const queueNodeTrees: ResolveTree[] = []; for (const mutation of queue) { @@ -368,7 +369,16 @@ export function queueToResolveTrees(queue: addedNodeMutation[]): ResolveTree[] { parentInTree.children.push(putIntoMap(mutation, parentInTree)); continue; } - queueNodeTrees.push(putIntoMap(mutation, null)); + if (nextId) { + rootNexts.add(nextId); + } + const rootTree = putIntoMap(mutation, null); + if (rootNexts.has(mutation.node.id)) { + // some existing tree can't be inserted until this one is (nextNotInDOM check) + queueNodeTrees.unshift(rootTree); + } else { + queueNodeTrees.push(rootTree); + } } return queueNodeTrees;