Skip to content

Commit 901139c

Browse files
authored
[scheduler][profiler] Start time of delayed tasks (#16809)
Fixes a bug in the Scheduler profiler where the start time of a delayed tasks is always 0.
1 parent f40ceb0 commit 901139c

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

packages/scheduler/src/Scheduler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function advanceTimers(currentTime) {
9191
timer.sortIndex = timer.expirationTime;
9292
push(taskQueue, timer);
9393
if (enableProfiling) {
94-
markTaskStart(timer);
94+
markTaskStart(timer, currentTime);
9595
timer.isQueued = true;
9696
}
9797
} else {

packages/scheduler/src/__tests__/SchedulerProfiling-test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,32 @@ Task 2 [Normal] │ ░░░░░░░░🡐 canceled
483483
);
484484
});
485485

486+
it('handles delayed tasks', () => {
487+
Scheduler.unstable_Profiling.startLoggingProfilingEvents();
488+
scheduleCallback(
489+
NormalPriority,
490+
() => {
491+
Scheduler.unstable_advanceTime(1000);
492+
Scheduler.unstable_yieldValue('A');
493+
},
494+
{
495+
delay: 1000,
496+
},
497+
);
498+
expect(Scheduler).toFlushWithoutYielding();
499+
500+
Scheduler.unstable_advanceTime(1000);
501+
502+
expect(Scheduler).toFlushAndYield(['A']);
503+
504+
expect(stopProfilingAndPrintFlamegraph()).toEqual(
505+
`
506+
!!! Main thread │████████████████████░░░░░░░░░░░░░░░░░░░░
507+
Task 1 [Normal] │ ████████████████████
508+
`,
509+
);
510+
});
511+
486512
it('handles cancelling a delayed task', () => {
487513
Scheduler.unstable_Profiling.startLoggingProfilingEvents();
488514
const task = scheduleCallback(

0 commit comments

Comments
 (0)