fix issue #19362 + test (#19412)
Robert Ferentz committed
Jul 24, 2020 at 21:34 UTC
b55f75d0a5383a60085e051d19b62ae68d71e366
2 files changed
+15
-1
packages/scheduler/src/Scheduler.js
+1
-1
@@ -177,7 +177,7 @@ function workLoop(hasTimeRemaining, initialTime) {
177
break;
178
}
179
const callback = currentTask.callback;
180
- if (callback !== null) {
180
+ if (typeof callback === 'function') {
181
currentTask.callback = null;
182
currentPriorityLevel = currentTask.priorityLevel;
183
const didUserCallbackTimeout = currentTask.expirationTime <= currentTime;
packages/scheduler/src/__tests__/Scheduler-test.js
+14
@@ -739,5 +739,19 @@ describe('Scheduler', () => {
739
// Only A should flush
740
expect(Scheduler).toFlushAndYield(['A']);
741
});
742
+
743
+ it('gracefully handles scheduled tasks that are not a function', () => {
744
+ scheduleCallback(ImmediatePriority, null);
745
+ expect(Scheduler).toFlushWithoutYielding();
746
+
747
+ scheduleCallback(ImmediatePriority, undefined);
748
+ expect(Scheduler).toFlushWithoutYielding();
749
+
750
+ scheduleCallback(ImmediatePriority, {});
751
+ expect(Scheduler).toFlushWithoutYielding();
752
+
753
+ scheduleCallback(ImmediatePriority, 42);
754
+ expect(Scheduler).toFlushWithoutYielding();
755
+ });
756
});
757
});