diff --git a/src/devtools/views/Components/Element.js b/src/devtools/views/Components/Element.js index 5e5b52fe08..0fa93b40ac 100644 --- a/src/devtools/views/Components/Element.js +++ b/src/devtools/views/Components/Element.js @@ -13,7 +13,7 @@ import { ElementTypeClass, ElementTypeFunction } from 'src/devtools/types'; import Store from 'src/devtools/store'; import ButtonIcon from '../ButtonIcon'; import { createRegExp } from '../utils'; -import { TreeContext } from './TreeContext'; +import { TreeDispatcherContext, TreeStateContext } from './TreeContext'; import { StoreContext } from '../context'; import type { ItemData } from './Tree'; @@ -28,18 +28,21 @@ type Props = { }; export default function ElementView({ data, index, style }: Props) { - const [isHovered, setIsHovered] = useState(false); + const store = useContext(StoreContext); const { baseDepth, - getElementAtIndex, + ownerFlatTree, ownerStack, - selectOwner, selectedElementID, - selectElementByID, - } = useContext(TreeContext); - const store = useContext(StoreContext); + } = useContext(TreeStateContext); + const dispatch = useContext(TreeDispatcherContext); - const element = getElementAtIndex(index); + const element = + ownerFlatTree !== null + ? store.getElementByID(ownerFlatTree[index]) + : store.getElementAtIndex(index); + + const [isHovered, setIsHovered] = useState(false); const { lastScrolledIDRef, @@ -52,9 +55,9 @@ export default function ElementView({ data, index, style }: Props) { const handleDoubleClick = useCallback(() => { if (id !== null) { - selectOwner(id); + dispatch({ type: 'SELECT_OWNER', payload: id }); } - }, [id, selectOwner]); + }, [dispatch, id]); const scrollAnchorStartRef = useRef(null); const scrollAnchorEndRef = useRef(null); @@ -102,10 +105,13 @@ export default function ElementView({ data, index, style }: Props) { const handleMouseDown = useCallback( ({ metaKey }) => { if (id !== null) { - selectElementByID(metaKey ? null : id); + dispatch({ + type: 'SELECT_ELEMENT_BY_ID', + payload: metaKey ? null : id, + }); } }, - [id, selectElementByID] + [dispatch, id] ); const handleMouseEnter = useCallback(() => { @@ -234,7 +240,9 @@ type DisplayNameProps = {| |}; function DisplayName({ displayName, id }: DisplayNameProps) { - const { searchIndex, searchResults, searchText } = useContext(TreeContext); + const { searchIndex, searchResults, searchText } = useContext( + TreeStateContext + ); const isSearchResult = useMemo(() => { return searchResults.includes(id); }, [id, searchResults]); diff --git a/src/devtools/views/Components/InspectedElementContext.js b/src/devtools/views/Components/InspectedElementContext.js index 21c5aefb5f..fbbc572f7b 100644 --- a/src/devtools/views/Components/InspectedElementContext.js +++ b/src/devtools/views/Components/InspectedElementContext.js @@ -10,7 +10,7 @@ import React, { import { createResource } from '../../cache'; import { BridgeContext, StoreContext } from '../context'; import { hydrate } from 'src/hydration'; -import { TreeContext } from './TreeContext'; +import { TreeStateContext } from './TreeContext'; import type { DehydratedData, @@ -38,7 +38,7 @@ type Props = {| function InspectedElementContextController({ children }: Props) { const bridge = useContext(BridgeContext); const store = useContext(StoreContext); - const { inspectedElementID } = useContext(TreeContext); + const { inspectedElementID } = useContext(TreeStateContext); const [count, setCount] = useState(0); diff --git a/src/devtools/views/Components/OwnersStack.js b/src/devtools/views/Components/OwnersStack.js index 860514fc78..b2f0c3299d 100644 --- a/src/devtools/views/Components/OwnersStack.js +++ b/src/devtools/views/Components/OwnersStack.js @@ -11,7 +11,7 @@ import { Menu, MenuList, MenuButton, MenuItem } from '@reach/menu-button'; import Button from '../Button'; import ButtonIcon from '../ButtonIcon'; import Toggle from '../Toggle'; -import { TreeContext } from './TreeContext'; +import { TreeDispatcherContext, TreeStateContext } from './TreeContext'; import { StoreContext } from '../context'; import { useIsOverflowing } from '../hooks'; @@ -20,9 +20,8 @@ import type { Element } from './types'; import styles from './OwnersStack.css'; export default function OwnerStack() { - const { ownerStack, ownerStackIndex, resetOwnerStack } = useContext( - TreeContext - ); + const { ownerStack, ownerStackIndex } = useContext(TreeStateContext); + const dispatch = useContext(TreeDispatcherContext); const [elementsTotalWidth, setElementsTotalWidth] = useState(0); const elementsBarRef = useRef(null); @@ -73,7 +72,7 @@ export default function OwnerStack() {