[Scheduler][Bugfix] Multiple rAFs in same frame (#16184)
Always sets `isRAFLoopRunning` back to false when an animation frame is scheduled. Fixes a bug where two rAFs fire in the same frame, but the second one exits and fails to schedule a new rAF. Fixes bug observed in Safari.
Andrew Clark committed
Jul 23, 2019 at 10:44 UTC
bff7abf6ba2426b1172e6f1ccbecd40a478a2c49
1 file changed
+4
-3
packages/scheduler/src/forks/SchedulerHostConfig.default.js
+4
-3
@@ -229,9 +229,10 @@ if (
229
channel.port1.onmessage = performWorkUntilDeadline;
230
231
const onAnimationFrame = rAFTime => {
232
+ isRAFLoopRunning = false;
233
+
234
if (scheduledHostCallback === null) {
235
// No scheduled work. Exit.
234
- isRAFLoopRunning = false;
236
prevRAFTime = -1;
237
prevRAFInterval = -1;
238
return;
@@ -255,6 +256,7 @@ if (
256
// waited until the end of the frame to post the callback, we risk the
257
// browser skipping a frame and not firing the callback until the frame
258
// after that.
259
+ isRAFLoopRunning = true;
260
requestAnimationFrame(nextRAFTime => {
261
clearTimeout(rAFTimeoutID);
262
onAnimationFrame(nextRAFTime);
@@ -303,9 +305,8 @@ if (
305
requestHostCallback = function(callback) {
306
scheduledHostCallback = callback;
307
if (!isRAFLoopRunning) {
306
- isRAFLoopRunning = true;
307
-
308
// Start a rAF loop.
309
+ isRAFLoopRunning = true;
310
requestAnimationFrame(rAFTime => {
311
if (requestIdleCallbackBeforeFirstFrame) {
312
cancelIdleCallback(idleCallbackID);