Skip to content

Commit b932350

Browse files
authored
[DevTools] Throw an error when attempting to clone non-existent node (#35702)
There is an existing issue with serialisation logic for the traces from Profiler panel. I've discovered that `TREE_OPERATION_UPDATE_TREE_BASE_DURATION` operation for some reason appears earlier in a sequence of operations, before the `TREE_OPERATION_ADD` that registers the new node. It ends up cloning non-existent node, which just creates an empty object and adds it to the map of nodes. This change only adds additional layer of validation to cloning logic, so we don't swallow the error, if we attempt to clone non-existent node.
1 parent bb53387 commit b932350

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

packages/react-devtools-shared/src/devtools/views/Profiler/CommitTreeBuilder.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,14 @@ function updateTree(
160160

161161
// Clone nodes before mutating them so edits don't affect them.
162162
const getClonedNode = (id: number): CommitTreeNode => {
163-
// $FlowFixMe[prop-missing] - recommended fix is to use object spread operator
164-
const clonedNode = ((Object.assign(
165-
{},
166-
nodes.get(id),
167-
): any): CommitTreeNode);
163+
const existingNode = nodes.get(id);
164+
if (existingNode == null) {
165+
throw new Error(
166+
`Could not clone the node: commit tree does not contain fiber "${id}". This is a bug in React DevTools.`,
167+
);
168+
}
169+
170+
const clonedNode = {...existingNode};
168171
nodes.set(id, clonedNode);
169172
return clonedNode;
170173
};

0 commit comments

Comments
 (0)