Skip to content

Commit d5f3c50

Browse files
authored
chore[DevTools/Tree]: don't pre-select root element and remove unused code (facebook#32015)
In this PR: 1. Removed unused code in `Tree.js` 2. Removed logic for pre-selecting first element in the tree by default. This is a bit clowny, because it steals focus and resets scroll, when user attempts to expand / collapse some subtree. 3. Updated comments around facebook@1c381c5. To expand on 3-rd point, for someone who might be reading this in the future: We can't guarantee focus of RDT browser extension panels, because they are hosted in an `iframe`. Attempting to fire any events won't have any result, user action with the corresponding `iframe` is required in order for this `iframe` to obtain focus. The only reason why built-in Elements panel in Chrome works correctly is because it is supported natively somewhere in Chrome / Chrome DevTools. Also, when you select an element on the application page, Chrome will make sure that Elements panel opened, which technically guarantees focus inside DevTools window and Elements panel subview. As of today, we can't navigate user to third-party extensions panels, there is no API for this, hence no ability to guarantee focused RDT panels.
1 parent 79dcc47 commit d5f3c50

File tree

1 file changed

+5
-30
lines changed
  • packages/react-devtools-shared/src/devtools/views/Components

1 file changed

+5
-30
lines changed

packages/react-devtools-shared/src/devtools/views/Components/Tree.js

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,12 @@ import {logEvent} from 'react-devtools-shared/src/Logger';
4242
const DEFAULT_INDENTATION_SIZE = 12;
4343

4444
export type ItemData = {
45-
numElements: number,
4645
isNavigatingWithKeyboard: boolean,
47-
lastScrolledIDRef: {current: number | null, ...},
4846
onElementMouseEnter: (id: number) => void,
4947
treeFocused: boolean,
5048
};
5149

52-
type Props = {};
53-
54-
export default function Tree(props: Props): React.Node {
50+
export default function Tree(): React.Node {
5551
const dispatch = useContext(TreeDispatcherContext);
5652
const {
5753
numElements,
@@ -96,7 +92,8 @@ export default function Tree(props: Props): React.Node {
9692
);
9793

9894
// Picking an element in the inspector should put focus into the tree.
99-
// This ensures that keyboard navigation works right after picking a node.
95+
// If possible, navigation works right after picking a node.
96+
// NOTE: This is not guaranteed to work, because browser extension panels are hosted inside an iframe.
10097
useEffect(() => {
10198
function handleStopInspectingHost(didSelectNode: boolean) {
10299
if (didSelectNode && focusTargetRef.current !== null) {
@@ -112,11 +109,6 @@ export default function Tree(props: Props): React.Node {
112109
bridge.removeListener('stopInspectingHost', handleStopInspectingHost);
113110
}, [bridge]);
114111

115-
// This ref is passed down the context to elements.
116-
// It lets them avoid autoscrolling to the same item many times
117-
// when a selected virtual row goes in and out of the viewport.
118-
const lastScrolledIDRef = useRef<number | null>(null);
119-
120112
// Navigate the tree with up/down arrow keys.
121113
useEffect(() => {
122114
if (treeRef.current === null) {
@@ -214,16 +206,7 @@ export default function Tree(props: Props): React.Node {
214206

215207
// Focus management.
216208
const handleBlur = useCallback(() => setTreeFocused(false), []);
217-
const handleFocus = useCallback(() => {
218-
setTreeFocused(true);
219-
220-
if (selectedElementIndex === null && numElements > 0) {
221-
dispatch({
222-
type: 'SELECT_ELEMENT_AT_INDEX',
223-
payload: 0,
224-
});
225-
}
226-
}, [dispatch, numElements, selectedElementIndex]);
209+
const handleFocus = useCallback(() => setTreeFocused(true), []);
227210

228211
const handleKeyPress = useCallback(
229212
(event: $FlowFixMe) => {
@@ -294,19 +277,11 @@ export default function Tree(props: Props): React.Node {
294277
// This includes the owner context, since it controls a filtered view of the tree.
295278
const itemData = useMemo<ItemData>(
296279
() => ({
297-
numElements,
298280
isNavigatingWithKeyboard,
299281
onElementMouseEnter: handleElementMouseEnter,
300-
lastScrolledIDRef,
301282
treeFocused,
302283
}),
303-
[
304-
numElements,
305-
isNavigatingWithKeyboard,
306-
handleElementMouseEnter,
307-
lastScrolledIDRef,
308-
treeFocused,
309-
],
284+
[isNavigatingWithKeyboard, handleElementMouseEnter, treeFocused],
310285
);
311286

312287
const itemKey = useCallback(

0 commit comments

Comments
 (0)