Update selected index after mutation
Dan Abramov committed
Apr 10, 2019 at 17:28 UTC
f1a8bd29235a2e267c88138a618d107cf5d4a9ea
1 file changed
+14
src/devtools/views/Components/TreeContext.js
+14
@@ -398,6 +398,20 @@ function reduceOwnersState(store: Store, state: State, action: Action): State {
398
ownerStackIndex = ownerStack.length - 1;
399
}
400
}
401
+ if (selectedElementID !== null) {
402
+ // Mutation might have caused the index of this ID to shift.
403
+ selectedElementIndex = _ownerFlatTree.indexOf(selectedElementID);
404
+ }
405
+ } else {
406
+ if (selectedElementID !== null) {
407
+ // Mutation might have caused the index of this ID to shift.
408
+ selectedElementIndex = store.getIndexOfElementID(selectedElementID);
409
+ }
410
+ }
411
+ if (selectedElementIndex === -1) {
412
+ // If we couldn't find this ID after mutation, unselect it.
413
+ selectedElementIndex = null;
414
+ selectedElementID = null;
415
}
416
break;
417
case 'RESET_OWNER_STACK':