-
Notifications
You must be signed in to change notification settings - Fork 50.5k
[DevTools] Add React Element pane to browser Elements panel #35240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -206,6 +206,7 @@ function createBridgeAndStore() { | |
| bridge, | ||
| browserTheme: getBrowserTheme(), | ||
| componentsPortalContainer, | ||
| inspectedElementPortalContainer, | ||
| profilerPortalContainer, | ||
| editorPortalContainer, | ||
| currentSelectedSource, | ||
|
|
@@ -278,6 +279,46 @@ function createComponentsPanel() { | |
| ); | ||
| } | ||
|
|
||
| function createElementsInspectPanel() { | ||
| if (inspectedElementPortalContainer) { | ||
| // Panel is created and user opened it at least once | ||
| ensureInitialHTMLIsCleared(inspectedElementPortalContainer); | ||
| render(); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| if (inspectedElementPane) { | ||
| // Panel is created, but wasn't opened yet, so no document is present for it | ||
| return; | ||
| } | ||
|
|
||
| const elementsPanel = chrome.devtools.panels.elements; | ||
| if (!elementsPanel || !elementsPanel.createSidebarPane) { | ||
| // TODO: Does Firefox support elements panel extensions? | ||
| return; | ||
| } | ||
|
|
||
| elementsPanel.createSidebarPane('React Element ⚛', createdPane => { | ||
| inspectedElementPane = createdPane; | ||
|
|
||
| createdPane.setPage('panel.html'); | ||
| createdPane.setHeight('75px'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it used as a min-height or how does this work? Might be worth double-checking the case when an element has a long list of props or hooks.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was copied from the added sources pane. Though it's not supported in Firefox: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/panels/ExtensionSidebarPane#browser_compatibility I follow-up on this since whatever change we make, should affect all ExtensionSidebarPane.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually will do this now since I can't test Firefox otherwise.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do in a follow-up since Firefox support is blocked by https://bugzilla.mozilla.org/show_bug.cgi?id=2010549 |
||
|
|
||
| createdPane.onShown.addListener(portal => { | ||
| inspectedElementPortalContainer = portal.container; | ||
| if (inspectedElementPortalContainer != null && render) { | ||
| ensureInitialHTMLIsCleared(inspectedElementPortalContainer); | ||
|
|
||
| render(); | ||
| portal.injectStyles(cloneStyleTags); | ||
|
|
||
| logEvent({event_name: 'selected-inspected-element-pane'}); | ||
| } | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| function createProfilerPanel() { | ||
| if (profilerPortalContainer) { | ||
| // Panel is created and user opened it at least once | ||
|
|
@@ -508,6 +549,7 @@ function mountReactDevTools() { | |
| createComponentsPanel(); | ||
| createProfilerPanel(); | ||
| createSourcesEditorPanel(); | ||
| createElementsInspectPanel(); | ||
| // Suspense Tab is created via the hook | ||
| // TODO(enableSuspenseTab): Create eagerly once Suspense tab is stable | ||
| } | ||
|
|
@@ -556,10 +598,12 @@ let componentsPanel = null; | |
| let profilerPanel = null; | ||
| let suspensePanel = null; | ||
| let editorPane = null; | ||
| let inspectedElementPane = null; | ||
| let componentsPortalContainer = null; | ||
| let profilerPortalContainer = null; | ||
| let suspensePortalContainer = null; | ||
| let editorPortalContainer = null; | ||
| let inspectedElementPortalContainer = null; | ||
|
|
||
| let mostRecentOverrideTab = null; | ||
| let render = null; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| .InspectedElementPane, .InspectedElementPane * { | ||
| box-sizing: border-box; | ||
| -webkit-font-smoothing: var(--font-smoothing); | ||
| } | ||
|
|
||
| .InspectedElementPane { | ||
| position: relative; | ||
| width: 100%; | ||
| height: 100%; | ||
| display: flex; | ||
| flex-direction: row; | ||
| background-color: var(--color-background); | ||
| color: var(--color-text); | ||
| font-family: var(--font-family-sans); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /** | ||
| * 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 * as React from 'react'; | ||
| import {useContext} from 'react'; | ||
|
|
||
| import portaledContent from 'react-devtools-shared/src/devtools/views/portaledContent'; | ||
| import {OptionsContext} from 'react-devtools-shared/src/devtools/views/context'; | ||
| import InspectedElement from 'react-devtools-shared/src/devtools/views/Components/InspectedElement'; | ||
| import SettingsModal from 'react-devtools-shared/src/devtools/views/Settings/SettingsModal'; | ||
| import SettingsModalContextToggle from 'react-devtools-shared/src/devtools/views/Settings/SettingsModalContextToggle'; | ||
| import {SettingsModalContextController} from 'react-devtools-shared/src/devtools/views/Settings/SettingsModalContext'; | ||
| import styles from './InspectedElementPane.css'; | ||
|
|
||
| export type Props = {}; | ||
eps1lon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| function InspectedElementPane(_: Props) { | ||
eps1lon marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const {hideSettings} = useContext(OptionsContext); | ||
| return ( | ||
| <SettingsModalContextController> | ||
| <div className={styles.InspectedElementPane}> | ||
| <InspectedElement | ||
| actionButtons={!hideSettings && <SettingsModalContextToggle />} | ||
| /> | ||
| <SettingsModal /> | ||
| </div> | ||
| </SettingsModalContextController> | ||
| ); | ||
| } | ||
| export default (portaledContent(InspectedElementPane): component()); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, does it work on Firefox? It probably should - https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/panels/elements
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C&P from the added sources pane which isn't supported in Firefox. The right compat table is https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/devtools/panels/ElementsPanel/createSidebarPane. So we should still leave the check in case we ever distribute this for Safari.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the reminder. It actually doesn't work in Firefox due to https://bugzilla.mozilla.org/show_bug.cgi?id=2010549