From f1a8bd29235a2e267c88138a618d107cf5d4a9ea Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Wed, 10 Apr 2019 17:28:36 +0100 Subject: [PATCH] Update selected index after mutation --- src/devtools/views/Components/TreeContext.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/devtools/views/Components/TreeContext.js b/src/devtools/views/Components/TreeContext.js index 8e264f826f..a4ef1cfa23 100644 --- a/src/devtools/views/Components/TreeContext.js +++ b/src/devtools/views/Components/TreeContext.js @@ -398,6 +398,20 @@ function reduceOwnersState(store: Store, state: State, action: Action): State { ownerStackIndex = ownerStack.length - 1; } } + if (selectedElementID !== null) { + // Mutation might have caused the index of this ID to shift. + selectedElementIndex = _ownerFlatTree.indexOf(selectedElementID); + } + } else { + if (selectedElementID !== null) { + // Mutation might have caused the index of this ID to shift. + selectedElementIndex = store.getIndexOfElementID(selectedElementID); + } + } + if (selectedElementIndex === -1) { + // If we couldn't find this ID after mutation, unselect it. + selectedElementIndex = null; + selectedElementID = null; } break; case 'RESET_OWNER_STACK':