@@ -14,7 +14,7 @@ import {
14
14
enableProfilerNestedUpdatePhase ,
15
15
enableProfilerTimer ,
16
16
} from 'shared/ReactFeatureFlags' ;
17
- import { Profiler } from './ReactWorkTags' ;
17
+ import { HostRoot , Profiler } from './ReactWorkTags' ;
18
18
19
19
// Intentionally not named imports because Rollup would use dynamic dispatch for
20
20
// CommonJS interop named imports.
@@ -140,13 +140,19 @@ function recordLayoutEffectDuration(fiber: Fiber): void {
140
140
141
141
layoutEffectStartTime = - 1 ;
142
142
143
- // Store duration on the next nearest Profiler ancestor.
143
+ // Store duration on the next nearest Profiler ancestor
144
+ // Or the root (for the DevTools Profiler to read)
144
145
let parentFiber = fiber . return ;
145
146
while ( parentFiber !== null ) {
146
- if ( parentFiber . tag === Profiler ) {
147
- const parentStateNode = parentFiber . stateNode ;
148
- parentStateNode . effectDuration += elapsedTime ;
149
- break ;
147
+ switch ( parentFiber . tag ) {
148
+ case HostRoot :
149
+ const root = parentFiber . stateNode ;
150
+ root . effectDuration += elapsedTime ;
151
+ return ;
152
+ case Profiler :
153
+ const parentStateNode = parentFiber . stateNode ;
154
+ parentStateNode . effectDuration += elapsedTime ;
155
+ return ;
150
156
}
151
157
parentFiber = parentFiber . return ;
152
158
}
@@ -163,18 +169,26 @@ function recordPassiveEffectDuration(fiber: Fiber): void {
163
169
164
170
passiveEffectStartTime = - 1 ;
165
171
166
- // Store duration on the next nearest Profiler ancestor.
172
+ // Store duration on the next nearest Profiler ancestor
173
+ // Or the root (for the DevTools Profiler to read)
167
174
let parentFiber = fiber . return ;
168
175
while ( parentFiber !== null ) {
169
- if ( parentFiber . tag === Profiler ) {
170
- const parentStateNode = parentFiber . stateNode ;
171
- if ( parentStateNode !== null ) {
172
- // Detached fibers have their state node cleared out.
173
- // In this case, the return pointer is also cleared out,
174
- // so we won't be able to report the time spent in this Profiler's subtree.
175
- parentStateNode . passiveEffectDuration += elapsedTime ;
176
- }
177
- break ;
176
+ switch ( parentFiber . tag ) {
177
+ case HostRoot :
178
+ const root = parentFiber . stateNode ;
179
+ if ( root !== null ) {
180
+ root . passiveEffectDuration += elapsedTime ;
181
+ }
182
+ return ;
183
+ case Profiler :
184
+ const parentStateNode = parentFiber . stateNode ;
185
+ if ( parentStateNode !== null ) {
186
+ // Detached fibers have their state node cleared out.
187
+ // In this case, the return pointer is also cleared out,
188
+ // so we won't be able to report the time spent in this Profiler's subtree.
189
+ parentStateNode . passiveEffectDuration += elapsedTime ;
190
+ }
191
+ return ;
178
192
}
179
193
parentFiber = parentFiber . return ;
180
194
}
0 commit comments