Skip to content

Commit 9a05e0b

Browse files
author
Brian Vaughn
committed
Disable view-source button in standalone mode if no project roots are provided
1 parent 722d366 commit 9a05e0b

File tree

5 files changed

+28
-23
lines changed

5 files changed

+28
-23
lines changed

packages/react-devtools-core/src/standalone.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ function reload() {
8585
root.render(
8686
createElement(DevTools, {
8787
bridge: ((bridge: any): FrontendBridge),
88-
isBrowserMode: false,
8988
showTabBar: true,
9089
store: ((store: any): Store),
9190
warnIfLegacyBackendDetected: true,
@@ -172,7 +171,10 @@ function initialize(socket: WebSocket) {
172171
socket.close();
173172
});
174173

175-
store = new Store(bridge, { supportsNativeInspection: false });
174+
store = new Store(bridge, {
175+
supportsNativeInspection: false,
176+
supportsViewSource: projectRoots.length > 0,
177+
});
176178

177179
log('Connected');
178180
reload();

src/devtools/store.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type Config = {|
4949
supportsNativeInspection?: boolean,
5050
supportsReloadAndProfile?: boolean,
5151
supportsProfiling?: boolean,
52+
supportsViewSource?: boolean,
5253
|};
5354

5455
export type Capabilities = {|
@@ -124,6 +125,7 @@ export default class Store extends EventEmitter<{|
124125
_supportsNativeInspection: boolean = false;
125126
_supportsProfiling: boolean = false;
126127
_supportsReloadAndProfile: boolean = false;
128+
_supportsViewSource: boolean = true;
127129

128130
// Total number of visible elements (within all roots).
129131
// Used for windowing purposes.
@@ -155,13 +157,15 @@ export default class Store extends EventEmitter<{|
155157
supportsNativeInspection,
156158
supportsProfiling,
157159
supportsReloadAndProfile,
160+
supportsViewSource,
158161
} = config;
159162
if (supportsCaptureScreenshots) {
160163
this._supportsCaptureScreenshots = true;
161164
this._captureScreenshots =
162165
localStorageGetItem(LOCAL_STORAGE_CAPTURE_SCREENSHOTS_KEY) === 'true';
163166
}
164167
this._supportsNativeInspection = supportsNativeInspection !== false;
168+
this._supportsViewSource = supportsViewSource !== false;
165169
if (supportsProfiling) {
166170
this._supportsProfiling = true;
167171
}
@@ -361,6 +365,10 @@ export default class Store extends EventEmitter<{|
361365
return this._supportsReloadAndProfile && this._isBackendStorageAPISupported;
362366
}
363367

368+
get supportsViewSource(): boolean {
369+
return this._supportsViewSource;
370+
}
371+
364372
containsElement(id: number): boolean {
365373
return this._idToElement.get(id) != null;
366374
}

src/devtools/views/Components/Components.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { SettingsModalContextController } from 'src/devtools/views/Settings/Sett
1313

1414
import styles from './Components.css';
1515

16-
function Components({ isBrowserMode }: {| isBrowserMode?: boolean |}) {
16+
function Components(_: {||}) {
1717
// TODO Flex wrappers below should be user resizable.
1818
return (
1919
<SettingsModalContextController>
@@ -26,7 +26,7 @@ function Components({ isBrowserMode }: {| isBrowserMode?: boolean |}) {
2626
<div className={styles.SelectedElementWrapper}>
2727
<NativeStyleContextController>
2828
<Suspense fallback={<Loading />}>
29-
<SelectedElement isBrowserMode={isBrowserMode} />
29+
<SelectedElement />
3030
</Suspense>
3131
</NativeStyleContextController>
3232
</div>

src/devtools/views/Components/SelectedElement.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ import type { GetInspectedElementPath } from './InspectedElementContext';
3030
import type { Element, InspectedElement } from './types';
3131
import type { ElementType } from 'src/types';
3232

33-
export type Props = {|
34-
isBrowserMode?: boolean,
35-
|};
33+
export type Props = {||};
3634

37-
export default function SelectedElement({ isBrowserMode }: Props) {
35+
export default function SelectedElement(_: Props) {
3836
const { inspectedElementID } = useContext(TreeStateContext);
3937
const dispatch = useContext(TreeDispatcherContext);
4038
const { isFileLocationRequired, viewElementSourceFunction } = useContext(
@@ -188,7 +186,7 @@ export default function SelectedElement({ isBrowserMode }: Props) {
188186
<ButtonIcon type="suspend" />
189187
</Toggle>
190188
)}
191-
{isBrowserMode && (
189+
{store.supportsNativeInspection && (
192190
<Button
193191
className={styles.IconButton}
194192
onClick={highlightElement}
@@ -204,14 +202,16 @@ export default function SelectedElement({ isBrowserMode }: Props) {
204202
>
205203
<ButtonIcon type="log-data" />
206204
</Button>
207-
<Button
208-
className={styles.IconButton}
209-
disabled={!canViewSource}
210-
onClick={viewSource}
211-
title="View source for this element"
212-
>
213-
<ButtonIcon type="view-source" />
214-
</Button>
205+
{store.supportsViewSource && (
206+
<Button
207+
className={styles.IconButton}
208+
disabled={!canViewSource}
209+
onClick={viewSource}
210+
title="View source for this element"
211+
>
212+
<ButtonIcon type="view-source" />
213+
</Button>
214+
)}
215215
</div>
216216

217217
{inspectedElement === null && (

src/devtools/views/DevTools.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export type Props = {|
3737
bridge: FrontendBridge,
3838
browserTheme?: BrowserTheme,
3939
defaultTab?: TabID,
40-
isBrowserMode?: boolean,
4140
showTabBar?: boolean,
4241
store: Store,
4342
warnIfLegacyBackendDetected?: boolean,
@@ -78,7 +77,6 @@ export default function DevTools({
7877
browserTheme = 'light',
7978
defaultTab = 'components',
8079
componentsPortalContainer,
81-
isBrowserMode = true,
8280
overrideTab,
8381
profilerPortalContainer,
8482
settingsPortalContainer,
@@ -135,10 +133,7 @@ export default function DevTools({
135133
className={styles.TabContent}
136134
hidden={tab !== 'components'}
137135
>
138-
<Components
139-
isBrowserMode={isBrowserMode}
140-
portalContainer={componentsPortalContainer}
141-
/>
136+
<Components portalContainer={componentsPortalContainer} />
142137
</div>
143138
<div
144139
className={styles.TabContent}

0 commit comments

Comments
 (0)