-
Notifications
You must be signed in to change notification settings - Fork 47.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix[DevTools/Tree]: only scroll to item when panel is visible (#32018)
Stacked on #31968. See commit on top. Fixes an issue with bank tree view, when we are scrolling to an item while syncing user DOM selection. This should only have an effect on browser extension. Added events with `extension` prefix will only be emitted in browser extension implementation, for other implementations `useExtensionComponentsPanelVisibility` will return constant `true` value. Before: https://github.com/user-attachments/assets/82667c16-d495-4346-af0a-7ed22ff89cfc After: https://github.com/user-attachments/assets/a5d223fd-0328-44f0-af68-5c3863f1efee
- Loading branch information
Showing
4 changed files
with
62 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/react-devtools-shared/src/frontend/hooks/useExtensionComponentsPanelVisibility.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
import {useState, useEffect} from 'react'; | ||
import type {FrontendBridge} from 'react-devtools-shared/src/bridge'; | ||
|
||
// Events that are prefixed with `extension` will only be emitted for the browser extension implementation. | ||
// For other implementations, this hook will just return constant `true` value. | ||
export function useExtensionComponentsPanelVisibility( | ||
bridge: FrontendBridge, | ||
): boolean { | ||
const [isVisible, setIsVisible] = useState(true); | ||
|
||
useEffect(() => { | ||
function onPanelShown() { | ||
setIsVisible(true); | ||
} | ||
function onPanelHidden() { | ||
setIsVisible(false); | ||
} | ||
|
||
bridge.addListener('extensionComponentsPanelShown', onPanelShown); | ||
bridge.addListener('extensionComponentsPanelHidden', onPanelHidden); | ||
|
||
return () => { | ||
bridge.removeListener('extensionComponentsPanelShown', onPanelShown); | ||
bridge.removeListener('extensionComponentsPanelHidden', onPanelHidden); | ||
}; | ||
}, [bridge]); | ||
|
||
return isVisible; | ||
} |