@@ -37,6 +37,7 @@ import styles from './Tree.css';
37
37
import ButtonIcon from '../ButtonIcon' ;
38
38
import Button from '../Button' ;
39
39
import { logEvent } from 'react-devtools-shared/src/Logger' ;
40
+ import { useExtensionComponentsPanelVisibility } from 'react-devtools-shared/src/frontend/hooks/useExtensionComponentsPanelVisibility' ;
40
41
41
42
// Never indent more than this number of pixels (even if we have the room).
42
43
const DEFAULT_INDENTATION_SIZE = 12 ;
@@ -78,36 +79,28 @@ export default function Tree(): React.Node {
78
79
const bridge = useContext ( BridgeContext ) ;
79
80
const store = useContext ( StoreContext ) ;
80
81
const { hideSettings} = useContext ( OptionsContext ) ;
82
+ const { lineHeight} = useContext ( SettingsContext ) ;
83
+
81
84
const [ isNavigatingWithKeyboard , setIsNavigatingWithKeyboard ] =
82
85
useState ( false ) ;
83
86
const { highlightHostInstance, clearHighlightHostInstance} =
84
87
useHighlightHostInstance ( ) ;
88
+ const [ treeFocused , setTreeFocused ] = useState < boolean > ( false ) ;
89
+ const componentsPanelVisible = useExtensionComponentsPanelVisibility ( bridge ) ;
90
+
85
91
const treeRef = useRef < HTMLDivElement | null > ( null ) ;
86
92
const focusTargetRef = useRef < HTMLDivElement | null > ( null ) ;
93
+ const listRef = useRef ( null ) ;
87
94
88
- const [ treeFocused , setTreeFocused ] = useState < boolean > ( false ) ;
89
-
90
- const { lineHeight} = useContext ( SettingsContext ) ;
95
+ useEffect ( ( ) => {
96
+ if ( ! componentsPanelVisible ) {
97
+ return ;
98
+ }
91
99
92
- // Make sure a newly selected element is visible in the list.
93
- // This is helpful for things like the owners list and search.
94
- //
95
- // TRICKY:
96
- // It's important to use a callback ref for this, rather than a ref object and an effect.
97
- // As an optimization, the AutoSizer component does not render children when their size would be 0.
98
- // This means that in some cases (if the browser panel size is initially really small),
99
- // the Tree component might render without rendering an inner List.
100
- // In this case, the list ref would be null on mount (when the scroll effect runs),
101
- // meaning the scroll action would be skipped (since ref updates don't re-run effects).
102
- // Using a callback ref accounts for this case...
103
- const listCallbackRef = useCallback (
104
- ( list : $FlowFixMe ) => {
105
- if ( list != null && inspectedElementIndex !== null ) {
106
- list . scrollToItem ( inspectedElementIndex , 'smart' ) ;
107
- }
108
- } ,
109
- [ inspectedElementIndex ] ,
110
- ) ;
100
+ if ( listRef . current != null && inspectedElementIndex !== null ) {
101
+ listRef . current . scrollToItem ( inspectedElementIndex , 'smart' ) ;
102
+ }
103
+ } , [ inspectedElementIndex , componentsPanelVisible ] ) ;
111
104
112
105
// Picking an element in the inspector should put focus into the tree.
113
106
// This ensures that keyboard navigation works right after picking a node.
@@ -449,7 +442,7 @@ export default function Tree(): React.Node {
449
442
itemData = { itemData }
450
443
itemKey = { itemKey }
451
444
itemSize = { lineHeight }
452
- ref = { listCallbackRef }
445
+ ref = { listRef }
453
446
width = { width } >
454
447
{ Element }
455
448
</ FixedSizeList >
0 commit comments