From 552a5dadcfaee529b3ad8c8011c5d8f8f000ebf1 Mon Sep 17 00:00:00 2001 From: Ruslan Lesiutin <28902667+hoxyq@users.noreply.github.com> Date: Thu, 7 Aug 2025 14:05:56 +0100 Subject: [PATCH] [DevTools] fix: handle store mutations synchronously in TreeContext (#34119) If there is a commit that removes the currently inspected (selected) elements in the Components tree, we are going to kick off the transition to re-render the Tree. The elements will be re-rendered with the previous inspectedElementID, which was just removed and all consecutive calls to store object with this id would produce errors, since this element was just removed. We should handle store mutations synchronously. Doesn't make sense to start a transition in this case, because Elements depend on the TreeState and could make calls to store in render function. Before: Screenshot 2025-08-06 at 17 41 14 After: https://github.com/user-attachments/assets/3da36aff-6987-4b76-b741-ca59f829f8e6 --- .../src/devtools/views/Components/TreeContext.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react-devtools-shared/src/devtools/views/Components/TreeContext.js b/packages/react-devtools-shared/src/devtools/views/Components/TreeContext.js index 797ffcd0f6..f43ced8244 100644 --- a/packages/react-devtools-shared/src/devtools/views/Components/TreeContext.js +++ b/packages/react-devtools-shared/src/devtools/views/Components/TreeContext.js @@ -954,7 +954,7 @@ function TreeContextController({ Array, Map, ]) => { - transitionDispatch({ + dispatch({ type: 'HANDLE_STORE_MUTATION', payload: [addedElementIDs, removedElementIDs], }); @@ -965,7 +965,7 @@ function TreeContextController({ // At the moment, we can treat this as a mutation. // We don't know which Elements were newly added/removed, but that should be okay in this case. // It would only impact the search state, which is unlikely to exist yet at this point. - transitionDispatch({ + dispatch({ type: 'HANDLE_STORE_MUTATION', payload: [[], new Map()], });