Skip to content

Commit a447c58

Browse files
committed
Move onPostCommit to actual passive phase
Original PR: facebook#19862
1 parent 19269cf commit a447c58

File tree

3 files changed

+50
-91
lines changed

3 files changed

+50
-91
lines changed

packages/react-reconciler/src/ReactFiberBeginWork.new.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import {
5959
ContentReset,
6060
DidCapture,
6161
Update,
62+
Passive,
6263
Ref,
6364
Deletion,
6465
ChildDeletion,
@@ -673,7 +674,7 @@ function updateProfiler(
673674
renderLanes: Lanes,
674675
) {
675676
if (enableProfilerTimer) {
676-
workInProgress.flags |= Update;
677+
workInProgress.flags |= Update | Passive;
677678

678679
// Reset effect durations for the next eventual effect phase.
679680
// These are reset during render to allow the DevTools commit hook a chance to read them,
@@ -3099,7 +3100,7 @@ function beginWork(
30993100
workInProgress.childLanes,
31003101
);
31013102
if (hasChildWork) {
3102-
workInProgress.flags |= Update;
3103+
workInProgress.flags |= Update | Passive;
31033104
}
31043105

31053106
// Reset effect durations for the next eventual effect phase.

packages/react-reconciler/src/ReactFiberCommitWork.new.js

Lines changed: 47 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ import {
126126
captureCommitPhaseError,
127127
resolveRetryWakeable,
128128
markCommitTimeOfFallback,
129-
enqueuePendingPassiveProfilerEffect,
130129
} from './ReactFiberWorkLoop.new';
131130
import {
132131
NoFlags as NoHookEffect,
@@ -411,63 +410,6 @@ function commitHookEffectListMount(tag: number, finishedWork: Fiber) {
411410
}
412411
}
413412

414-
export function commitPassiveEffectDurations(
415-
finishedRoot: FiberRoot,
416-
finishedWork: Fiber,
417-
): void {
418-
if (enableProfilerTimer && enableProfilerCommitHooks) {
419-
// Only Profilers with work in their subtree will have an Update effect scheduled.
420-
if ((finishedWork.flags & Update) !== NoFlags) {
421-
switch (finishedWork.tag) {
422-
case Profiler: {
423-
const {passiveEffectDuration} = finishedWork.stateNode;
424-
const {id, onPostCommit} = finishedWork.memoizedProps;
425-
426-
// This value will still reflect the previous commit phase.
427-
// It does not get reset until the start of the next commit phase.
428-
const commitTime = getCommitTime();
429-
430-
let phase = finishedWork.alternate === null ? 'mount' : 'update';
431-
if (enableProfilerNestedUpdatePhase) {
432-
if (isCurrentUpdateNested()) {
433-
phase = 'nested-update';
434-
}
435-
}
436-
437-
if (typeof onPostCommit === 'function') {
438-
if (enableSchedulerTracing) {
439-
onPostCommit(
440-
id,
441-
phase,
442-
passiveEffectDuration,
443-
commitTime,
444-
finishedRoot.memoizedInteractions,
445-
);
446-
} else {
447-
onPostCommit(id, phase, passiveEffectDuration, commitTime);
448-
}
449-
}
450-
451-
// Bubble times to the next nearest ancestor Profiler.
452-
// After we process that Profiler, we'll bubble further up.
453-
let parentFiber = finishedWork.return;
454-
while (parentFiber !== null) {
455-
if (parentFiber.tag === Profiler) {
456-
const parentStateNode = parentFiber.stateNode;
457-
parentStateNode.passiveEffectDuration += passiveEffectDuration;
458-
break;
459-
}
460-
parentFiber = parentFiber.return;
461-
}
462-
break;
463-
}
464-
default:
465-
break;
466-
}
467-
}
468-
}
469-
}
470-
471413
function commitLifeCycles(
472414
finishedRoot: FiberRoot,
473415
current: Fiber | null,
@@ -749,11 +691,6 @@ function commitLifeCycles(
749691
}
750692
}
751693

752-
// Schedule a passive effect for this Profiler to call onPostCommit hooks.
753-
// This effect should be scheduled even if there is no onPostCommit callback for this Profiler,
754-
// because the effect is also where times bubble to parent Profilers.
755-
enqueuePendingPassiveProfilerEffect(finishedWork);
756-
757694
// Propagate layout effect durations to the next nearest Profiler ancestor.
758695
// Do not reset these values until the next render so DevTools has a chance to read them first.
759696
let parentFiber = finishedWork.return;
@@ -1888,6 +1825,53 @@ function commitPassiveMountOnFiber(
18881825
}
18891826
break;
18901827
}
1828+
case Profiler: {
1829+
if (enableProfilerTimer && enableProfilerCommitHooks) {
1830+
// Only Profilers with work in their subtree will have an Update effect scheduled.
1831+
if ((finishedWork.flags & Update) !== NoFlags) {
1832+
const {passiveEffectDuration} = finishedWork.stateNode;
1833+
const {id, onPostCommit} = finishedWork.memoizedProps;
1834+
1835+
// This value will still reflect the previous commit phase.
1836+
// It does not get reset until the start of the next commit phase.
1837+
const commitTime = getCommitTime();
1838+
1839+
let phase = finishedWork.alternate === null ? 'mount' : 'update';
1840+
if (enableProfilerNestedUpdatePhase) {
1841+
if (isCurrentUpdateNested()) {
1842+
phase = 'nested-update';
1843+
}
1844+
}
1845+
1846+
if (typeof onPostCommit === 'function') {
1847+
if (enableSchedulerTracing) {
1848+
onPostCommit(
1849+
id,
1850+
phase,
1851+
passiveEffectDuration,
1852+
commitTime,
1853+
finishedRoot.memoizedInteractions,
1854+
);
1855+
} else {
1856+
onPostCommit(id, phase, passiveEffectDuration, commitTime);
1857+
}
1858+
}
1859+
1860+
// Bubble times to the next nearest ancestor Profiler.
1861+
// After we process that Profiler, we'll bubble further up.
1862+
let parentFiber = finishedWork.return;
1863+
while (parentFiber !== null) {
1864+
if (parentFiber.tag === Profiler) {
1865+
const parentStateNode = parentFiber.stateNode;
1866+
parentStateNode.passiveEffectDuration += passiveEffectDuration;
1867+
break;
1868+
}
1869+
parentFiber = parentFiber.return;
1870+
}
1871+
}
1872+
}
1873+
break;
1874+
}
18911875
}
18921876
}
18931877

packages/react-reconciler/src/ReactFiberWorkLoop.new.js

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
enableSuspenseServerRenderer,
2222
replayFailedUnitOfWorkWithInvokeGuardedCallback,
2323
enableProfilerTimer,
24-
enableProfilerCommitHooks,
2524
enableProfilerNestedUpdatePhase,
2625
enableProfilerNestedUpdateScheduledHook,
2726
enableSchedulerTracing,
@@ -198,7 +197,6 @@ import {
198197
commitDeletion,
199198
commitDetachRef,
200199
commitAttachRef,
201-
commitPassiveEffectDurations,
202200
commitResetTextContent,
203201
isSuspenseBoundaryBeingHidden,
204202
commitPassiveMountEffects,
@@ -348,7 +346,6 @@ let rootDoesHavePassiveEffects: boolean = false;
348346
let rootWithPendingPassiveEffects: FiberRoot | null = null;
349347
let pendingPassiveEffectsRenderPriority: ReactPriorityLevel = NoSchedulerPriority;
350348
let pendingPassiveEffectsLanes: Lanes = NoLanes;
351-
let pendingPassiveProfilerEffects: Array<Fiber> = [];
352349

353350
let rootsWithPendingDiscreteUpdates: Set<FiberRoot> | null = null;
354351

@@ -2504,19 +2501,6 @@ export function flushPassiveEffects(): boolean {
25042501
return false;
25052502
}
25062503

2507-
export function enqueuePendingPassiveProfilerEffect(fiber: Fiber): void {
2508-
if (enableProfilerTimer && enableProfilerCommitHooks) {
2509-
pendingPassiveProfilerEffects.push(fiber);
2510-
if (!rootDoesHavePassiveEffects) {
2511-
rootDoesHavePassiveEffects = true;
2512-
scheduleCallback(NormalSchedulerPriority, () => {
2513-
flushPassiveEffects();
2514-
return null;
2515-
});
2516-
}
2517-
}
2518-
}
2519-
25202504
function flushPassiveEffectsImpl() {
25212505
if (rootWithPendingPassiveEffects === null) {
25222506
return false;
@@ -2553,16 +2537,6 @@ function flushPassiveEffectsImpl() {
25532537
commitPassiveUnmountEffects(root.current);
25542538
commitPassiveMountEffects(root, root.current);
25552539

2556-
// TODO: Move to commitPassiveMountEffects
2557-
if (enableProfilerTimer && enableProfilerCommitHooks) {
2558-
const profilerEffects = pendingPassiveProfilerEffects;
2559-
pendingPassiveProfilerEffects = [];
2560-
for (let i = 0; i < profilerEffects.length; i++) {
2561-
const fiber = ((profilerEffects[i]: any): Fiber);
2562-
commitPassiveEffectDurations(root, fiber);
2563-
}
2564-
}
2565-
25662540
if (enableSchedulerTracing) {
25672541
popInteractions(((prevInteractions: any): Set<Interaction>));
25682542
finishPendingInteractions(root, lanes);

0 commit comments

Comments
 (0)