Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit 17d5523

Browse files
authored
Disable props/state inspection for Profiler (#1260)
* Disable props/state inspection for Profiler * Expand Profiler props/state objects by default * Added comment about why props.inspect might be null
1 parent c684e69 commit 17d5523

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

agent/dehydrate.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
// unless the frontend explicitly requests it (e.g. a user clicks to expand a props object).
1616
// This value was originally set to 2, but we reduced it to improve performance:
1717
// see https://github.com/facebook/react-devtools/issues/1200
18+
// Note this value also indirectly determines how far props can be drilled into within the Profiler.
1819
const LEVEL_THRESHOLD = 1;
1920

2021
/**

frontend/DataView/DataView.js

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type ShowMenu = boolean | (e: DOMEvent, val: any, path: Array<string>, name: str
2626
type DataViewProps = {
2727
data: ?any,
2828
path: Array<string>,
29-
inspect: Inspect,
29+
inspect: Inspect | null,
3030
showMenu: ShowMenu,
3131
startOpen?: boolean,
3232
noSort?: boolean,
@@ -155,7 +155,7 @@ DataView.contextTypes = {
155155

156156
type Props = {
157157
path: Array<string>,
158-
inspect: Inspect,
158+
inspect: Inspect | null,
159159
showMenu: ShowMenu,
160160
startOpen?: boolean,
161161
noSort?: boolean,
@@ -195,25 +195,34 @@ class DataItem extends React.Component<Props, State> {
195195
}
196196

197197
inspect() {
198+
const inspect = this.props.inspect;
199+
if (inspect === null) {
200+
// The Profiler displays props/state for oudated Fibers.
201+
// These Fibers have already been mutated so they can't be inspected.
202+
return;
203+
}
204+
198205
this.setState({loading: true, open: true});
199-
this.props.inspect(this.props.path, () => {
206+
inspect(this.props.path, () => {
200207
this.setState({loading: false});
201208
});
202209
}
203210

204-
toggleOpen() {
211+
toggleOpen = () => {
205212
if (this.state.loading) {
206213
return;
207214
}
208-
if (this.props.value && this.props.value[consts.inspected] === false) {
215+
216+
const { value } = this.props;
217+
if (value && value[consts.inspected] === false) {
209218
this.inspect();
210219
return;
211220
}
212221

213222
this.setState({
214223
open: !this.state.open,
215224
});
216-
}
225+
};
217226

218227
toggleBooleanValue(e) {
219228
this.context.onChange(this.props.path, e.target.checked);
@@ -238,14 +247,14 @@ class DataItem extends React.Component<Props, State> {
238247
preview = previewComplex(data, theme);
239248
}
240249

241-
var inspectable = !data || !data[consts.meta] || !data[consts.meta].uninspectable;
242-
var open = inspectable && this.state.open && (!data || data[consts.inspected] !== false);
250+
var inspectable = typeof this.props.inspect === 'function' && (!data || !data[consts.meta] || !data[consts.meta].uninspectable);
251+
var open = this.state.open && (!data || data[consts.inspected] !== false);
243252
var opener = null;
244253

245254
if (complex && inspectable) {
246255
opener = (
247256
<div
248-
onClick={this.toggleOpen.bind(this)}
257+
onClick={this.toggleOpen}
249258
style={styles.opener}>
250259
{open ?
251260
<span style={expandedArrowStyle(theme)} /> :
@@ -292,8 +301,8 @@ class DataItem extends React.Component<Props, State> {
292301
{
293302
!this.props.hideName &&
294303
<div
295-
style={nameStyle(complex, theme)}
296-
onClick={inspectable && this.toggleOpen.bind(this)}
304+
style={nameStyle(complex, inspectable, theme)}
305+
onClick={inspectable ? this.toggleOpen : undefined}
297306
>
298307
{name}:
299308
</div>
@@ -330,8 +339,8 @@ function alphanumericSort(a: string, b: string): number {
330339
return (a < b) ? -1 : 1;
331340
}
332341

333-
const nameStyle = (isComplex: boolean, theme: Theme) => ({
334-
cursor: isComplex ? 'pointer' : 'default',
342+
const nameStyle = (isComplex: boolean, isInspectable: boolean, theme: Theme) => ({
343+
cursor: isComplex && isInspectable ? 'pointer' : 'default',
335344
color: theme.special03,
336345
margin: '0 0.25rem',
337346
});

plugins/Profiler/views/ProfilerFiberDetailPane.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,9 @@ const ProfilerFiberDetailPane = ({
114114
<DataView
115115
path={['props']}
116116
readOnly={true}
117-
inspect={emptyFunction}
117+
inspect={null}
118118
showMenu={emptyFunction}
119+
startOpen={true}
119120
data={snapshotFiber.get('props')}
120121
/>
121122
</DetailPaneSection>
@@ -124,8 +125,9 @@ const ProfilerFiberDetailPane = ({
124125
<DataView
125126
path={['state']}
126127
readOnly={true}
127-
inspect={emptyFunction}
128+
inspect={null}
128129
showMenu={emptyFunction}
130+
startOpen={true}
129131
data={snapshotFiber.get('state')}
130132
/>
131133
</DetailPaneSection>

0 commit comments

Comments
 (0)