@@ -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 ;
@@ -76,36 +77,28 @@ export default function Tree(): React.Node {
76
77
const bridge = useContext ( BridgeContext ) ;
77
78
const store = useContext ( StoreContext ) ;
78
79
const { hideSettings} = useContext ( OptionsContext ) ;
80
+ const { lineHeight} = useContext ( SettingsContext ) ;
81
+
79
82
const [ isNavigatingWithKeyboard , setIsNavigatingWithKeyboard ] =
80
83
useState ( false ) ;
81
84
const { highlightHostInstance, clearHighlightHostInstance} =
82
85
useHighlightHostInstance ( ) ;
86
+ const [ treeFocused , setTreeFocused ] = useState < boolean > ( false ) ;
87
+ const componentsPanelVisible = useExtensionComponentsPanelVisibility ( bridge ) ;
88
+
83
89
const treeRef = useRef < HTMLDivElement | null > ( null ) ;
84
90
const focusTargetRef = useRef < HTMLDivElement | null > ( null ) ;
91
+ const listRef = useRef ( null ) ;
85
92
86
- const [ treeFocused , setTreeFocused ] = useState < boolean > ( false ) ;
87
-
88
- const { lineHeight} = useContext ( SettingsContext ) ;
93
+ useEffect ( ( ) => {
94
+ if ( ! componentsPanelVisible ) {
95
+ return ;
96
+ }
89
97
90
- // Make sure a newly selected element is visible in the list.
91
- // This is helpful for things like the owners list and search.
92
- //
93
- // TRICKY:
94
- // It's important to use a callback ref for this, rather than a ref object and an effect.
95
- // As an optimization, the AutoSizer component does not render children when their size would be 0.
96
- // This means that in some cases (if the browser panel size is initially really small),
97
- // the Tree component might render without rendering an inner List.
98
- // In this case, the list ref would be null on mount (when the scroll effect runs),
99
- // meaning the scroll action would be skipped (since ref updates don't re-run effects).
100
- // Using a callback ref accounts for this case...
101
- const listCallbackRef = useCallback (
102
- ( list : $FlowFixMe ) => {
103
- if ( list != null && inspectedElementIndex !== null ) {
104
- list . scrollToItem ( inspectedElementIndex , 'smart' ) ;
105
- }
106
- } ,
107
- [ inspectedElementIndex ] ,
108
- ) ;
98
+ if ( listRef . current != null && inspectedElementIndex !== null ) {
99
+ listRef . current . scrollToItem ( inspectedElementIndex , 'smart' ) ;
100
+ }
101
+ } , [ inspectedElementIndex , componentsPanelVisible ] ) ;
109
102
110
103
// Picking an element in the inspector should put focus into the tree.
111
104
// If possible, navigation works right after picking a node.
@@ -426,7 +419,7 @@ export default function Tree(): React.Node {
426
419
itemData = { itemData }
427
420
itemKey = { itemKey }
428
421
itemSize = { lineHeight }
429
- ref = { listCallbackRef }
422
+ ref = { listRef }
430
423
width = { width } >
431
424
{ Element }
432
425
</ FixedSizeList >
0 commit comments