@@ -22,7 +22,7 @@ import type {ProfilingDataFrontend} from './types';
22
22
export type TabID = 'flame-chart' | 'ranked-chart' | 'interactions' ;
23
23
24
24
export type Context = { |
25
- // Which tab is selexted in the Profiler UI?
25
+ // Which tab is selected in the Profiler UI?
26
26
selectedTabID : TabID ,
27
27
selectTab ( id : TabID ) : void ,
28
28
@@ -129,6 +129,38 @@ function ProfilerContextController({children}: Props) {
129
129
setPrevProfilingData ,
130
130
] = useState < ProfilingDataFrontend | null > ( null ) ;
131
131
const [ rootID , setRootID ] = useState < number | null > ( null ) ;
132
+ const [ selectedFiberID , selectFiberID ] = useState < number | null > ( null ) ;
133
+ const [ selectedFiberName , selectFiberName ] = useState < string | null > ( null ) ;
134
+
135
+ const selectFiber = useCallback (
136
+ ( id : number | null , name : string | null ) => {
137
+ selectFiberID ( id ) ;
138
+ selectFiberName ( name ) ;
139
+
140
+ // Sync selection to the Components tab for convenience.
141
+ if ( id !== null ) {
142
+ const element = store . getElementByID ( id ) ;
143
+
144
+ // Keep in mind that profiling data may be from a previous session.
145
+ // In that case, IDs may match up arbitrarily; to be safe, compare both ID and display name.
146
+ if ( element !== null && element . displayName === name ) {
147
+ dispatch ( {
148
+ type : 'SELECT_ELEMENT_BY_ID' ,
149
+ payload : id ,
150
+ } ) ;
151
+ }
152
+ }
153
+ } ,
154
+ [ dispatch , selectFiberID , selectFiberName , store ] ,
155
+ ) ;
156
+
157
+ const setRootIDAndClearFiber = useCallback (
158
+ ( id : number | null ) => {
159
+ selectFiber ( null , null ) ;
160
+ setRootID ( id ) ;
161
+ } ,
162
+ [ setRootID , selectFiber ] ,
163
+ ) ;
132
164
133
165
if ( prevProfilingData !== profilingData ) {
134
166
batchedUpdates ( ( ) => {
@@ -150,9 +182,9 @@ function ProfilerContextController({children}: Props) {
150
182
selectedElementRootID !== null &&
151
183
dataForRoots . has ( selectedElementRootID )
152
184
) {
153
- setRootID ( selectedElementRootID ) ;
185
+ setRootIDAndClearFiber ( selectedElementRootID ) ;
154
186
} else {
155
- setRootID ( firstRootID ) ;
187
+ setRootIDAndClearFiber ( firstRootID ) ;
156
188
}
157
189
}
158
190
}
@@ -180,34 +212,10 @@ function ProfilerContextController({children}: Props) {
180
212
null ,
181
213
) ;
182
214
const [ selectedTabID , selectTab ] = useState < TabID > ( 'flame-chart' ) ;
183
- const [ selectedFiberID , selectFiberID ] = useState < number | null > ( null ) ;
184
- const [ selectedFiberName , selectFiberName ] = useState < string | null > ( null ) ;
185
215
const [ selectedInteractionID , selectInteraction ] = useState < number | null > (
186
216
null ,
187
217
) ;
188
218
189
- const selectFiber = useCallback (
190
- ( id : number | null , name : string | null ) => {
191
- selectFiberID ( id ) ;
192
- selectFiberName ( name ) ;
193
-
194
- // Sync selection to the Components tab for convenience.
195
- if ( id !== null ) {
196
- const element = store . getElementByID ( id ) ;
197
-
198
- // Keep in mind that profiling data may be from a previous session.
199
- // In that case, IDs may match up arbitrarily; to be safe, compare both ID and display name.
200
- if ( element !== null && element . displayName === name ) {
201
- dispatch ( {
202
- type : 'SELECT_ELEMENT_BY_ID' ,
203
- payload : id ,
204
- } ) ;
205
- }
206
- }
207
- } ,
208
- [ dispatch , selectFiberID , selectFiberName , store ] ,
209
- ) ;
210
-
211
219
if ( isProfiling ) {
212
220
batchedUpdates ( ( ) => {
213
221
if ( selectedCommitIndex !== null ) {
@@ -237,7 +245,7 @@ function ProfilerContextController({children}: Props) {
237
245
supportsProfiling,
238
246
239
247
rootID,
240
- setRootID,
248
+ setRootID : setRootIDAndClearFiber ,
241
249
242
250
isCommitFilterEnabled,
243
251
setIsCommitFilterEnabled,
@@ -268,6 +276,7 @@ function ProfilerContextController({children}: Props) {
268
276
269
277
rootID ,
270
278
setRootID ,
279
+ setRootIDAndClearFiber ,
271
280
272
281
isCommitFilterEnabled ,
273
282
setIsCommitFilterEnabled ,
0 commit comments