@@ -39,7 +39,7 @@ import {
3939 startTransition ,
4040} from 'react' ;
4141import { createRegExp } from '../utils' ;
42- import { BridgeContext , StoreContext } from '../context' ;
42+ import { StoreContext } from '../context' ;
4343import Store from '../../store' ;
4444
4545import type { Element } from 'react-devtools-shared/src/frontend/types' ;
@@ -836,7 +836,6 @@ function TreeContextController({
836836 defaultSelectedElementID,
837837 defaultSelectedElementIndex,
838838} : Props ) : React . Node {
839- const bridge = useContext ( BridgeContext ) ;
840839 const store = useContext ( StoreContext ) ;
841840
842841 const initialRevision = useMemo ( ( ) => store . revision , [ store ] ) ;
@@ -899,9 +898,15 @@ function TreeContextController({
899898 numElements : store . numElements ,
900899 ownerSubtreeLeafElementID : null ,
901900 selectedElementID :
902- defaultSelectedElementID == null ? null : defaultSelectedElementID ,
901+ defaultSelectedElementID != null
902+ ? defaultSelectedElementID
903+ : store . lastSelectedHostInstanceElementId ,
903904 selectedElementIndex :
904- defaultSelectedElementIndex == null ? null : defaultSelectedElementIndex ,
905+ defaultSelectedElementIndex != null
906+ ? defaultSelectedElementIndex
907+ : store . lastSelectedHostInstanceElementId
908+ ? store . getIndexOfElementID ( store . lastSelectedHostInstanceElementId )
909+ : null ,
905910
906911 // Search
907912 searchIndex : null ,
@@ -914,7 +919,9 @@ function TreeContextController({
914919
915920 // Inspection element panel
916921 inspectedElementID :
917- defaultInspectedElementID == null ? null : defaultInspectedElementID ,
922+ defaultInspectedElementID != null
923+ ? defaultInspectedElementID
924+ : store . lastSelectedHostInstanceElementId ,
918925 } ) ;
919926
920927 const dispatchWrapper = useCallback (
@@ -929,11 +936,12 @@ function TreeContextController({
929936
930937 // Listen for host element selections.
931938 useEffect ( ( ) => {
932- const handleSelectElement = ( id : number ) =>
939+ const handler = ( id : Element [ 'id' ] ) =>
933940 dispatchWrapper ( { type : 'SELECT_ELEMENT_BY_ID' , payload : id } ) ;
934- bridge . addListener ( 'selectElement' , handleSelectElement ) ;
935- return ( ) => bridge . removeListener ( 'selectElement' , handleSelectElement ) ;
936- } , [ bridge , dispatchWrapper ] ) ;
941+
942+ store . addListener ( 'hostInstanceSelected' , handler ) ;
943+ return ( ) => store . removeListener ( 'hostInstanceSelected' , handler ) ;
944+ } , [ store , dispatchWrapper ] ) ;
937945
938946 // If a newly-selected search result or inspection selection is inside of a collapsed subtree, auto expand it.
939947 // This needs to be a layout effect to avoid temporarily flashing an incorrect selection.
0 commit comments