Skip to content

Commit 2bbb7be

Browse files
authored
[DevTools] Don't call Hooks conditionally (#34644)
1 parent dce1f6c commit 2bbb7be

File tree

2 files changed

+50
-40
lines changed

2 files changed

+50
-40
lines changed

packages/react-devtools-shared/src/devtools/views/Profiler/SidebarEventInfo.js

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
import type {SchedulingEvent} from 'react-devtools-timeline/src/types';
11+
import type {ReactFunctionLocation} from 'shared/ReactTypes';
1112

1213
import * as React from 'react';
1314
import Button from '../Button';
@@ -27,6 +28,28 @@ import styles from './SidebarEventInfo.css';
2728

2829
export type Props = {};
2930

31+
type FunctionLocationProps = {
32+
location: ReactFunctionLocation,
33+
displayName: string,
34+
};
35+
function FunctionLocation({location, displayName}: FunctionLocationProps) {
36+
// TODO: We should support symbolication here as well, but
37+
// symbolicating the whole stack can be expensive
38+
const [canViewSource, viewSource] = useOpenResource(location, null);
39+
return (
40+
<li>
41+
<Button
42+
className={
43+
canViewSource ? styles.ClickableSource : styles.UnclickableSource
44+
}
45+
disabled={!canViewSource}
46+
onClick={viewSource}>
47+
{displayName}
48+
</Button>
49+
</li>
50+
);
51+
}
52+
3053
type SchedulingEventProps = {
3154
eventInfo: SchedulingEvent,
3255
};
@@ -74,25 +97,12 @@ function SchedulingEventInfo({eventInfo}: SchedulingEventProps) {
7497
);
7598
}
7699

77-
// TODO: We should support symbolication here as well, but
78-
// symbolicating the whole stack can be expensive
79-
const [canViewSource, viewSource] = useOpenResource(
80-
location,
81-
null,
82-
);
83100
return (
84-
<li key={index}>
85-
<Button
86-
className={
87-
canViewSource
88-
? styles.ClickableSource
89-
: styles.UnclickableSource
90-
}
91-
disabled={!canViewSource}
92-
onClick={viewSource}>
93-
{displayName}
94-
</Button>
95-
</li>
101+
<FunctionLocation
102+
key={index}
103+
displayName={displayName}
104+
location={location}
105+
/>
96106
);
97107
},
98108
)}

packages/react-devtools-shared/src/devtools/views/SuspenseTab/SuspenseTimeline.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,6 @@ function SuspenseTimelineInput() {
3939
const min = 0;
4040
const max = timeline.length > 0 ? timeline.length - 1 : 0;
4141

42-
if (rootID === null) {
43-
return (
44-
<div className={styles.SuspenseTimelineInput}>No root selected.</div>
45-
);
46-
}
47-
48-
if (!store.supportsTogglingSuspense(rootID)) {
49-
return (
50-
<div className={styles.SuspenseTimelineInput}>
51-
Can't step through Suspense in production apps.
52-
</div>
53-
);
54-
}
55-
56-
if (timeline.length === 0) {
57-
return (
58-
<div className={styles.SuspenseTimelineInput}>
59-
Root contains no Suspense nodes.
60-
</div>
61-
);
62-
}
63-
6442
function switchSuspenseNode(nextTimelineIndex: number) {
6543
const nextSelectedSuspenseID = timeline[nextTimelineIndex];
6644
highlightHostInstance(nextSelectedSuspenseID);
@@ -175,6 +153,28 @@ function SuspenseTimelineInput() {
175153
};
176154
}, [playing]);
177155

156+
if (rootID === null) {
157+
return (
158+
<div className={styles.SuspenseTimelineInput}>No root selected.</div>
159+
);
160+
}
161+
162+
if (!store.supportsTogglingSuspense(rootID)) {
163+
return (
164+
<div className={styles.SuspenseTimelineInput}>
165+
Can't step through Suspense in production apps.
166+
</div>
167+
);
168+
}
169+
170+
if (timeline.length === 0) {
171+
return (
172+
<div className={styles.SuspenseTimelineInput}>
173+
Root contains no Suspense nodes.
174+
</div>
175+
);
176+
}
177+
178178
return (
179179
<>
180180
<Button

0 commit comments

Comments
 (0)