From 5f581fdafa2a461c9dd4527378110d12a51cdc16 Mon Sep 17 00:00:00 2001 From: Angus MacDonald Date: Fri, 4 Dec 2020 15:14:48 -0600 Subject: [PATCH] Allow looping of Raf callbacks --- src/raf/raf.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/raf/raf.ts b/src/raf/raf.ts index e0ee75cf73..ccff4ab161 100644 --- a/src/raf/raf.ts +++ b/src/raf/raf.ts @@ -672,7 +672,7 @@ class RafRegistry { this.flushScheduled = true; requestAnimationFrame(()=> { this.runRaf(); - }) + }); } private runRaf() { @@ -697,6 +697,17 @@ class RafRegistry { RafRegistry.runRafCallbacks(this.postWrites); this.flushScheduled = false; + + // If more callbacks were scheduled for the next frame during this + // callback, start the process again + const remainingCallbackCount = + this.preReads.length + + this.reads.length + + this.writes.length + + this.postWrites.length; + if (remainingCallbackCount > 0) { + this.start(); + } } /**