From bd2d0b28bd36cde5387fb88120a3f2e095ffd4a3 Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Fri, 13 May 2022 13:32:02 -0700 Subject: [PATCH] Patch loophole that caused some Animated instructions to be executed out of order Summary: This patches a loophole in the logic that caused some operations to execute immediately and some to be deferred, even within the same render loop. This caused the non-queued operations to be executed out of order. Instead, if an operation is created and a queued exists, we just push the operation to the end of the queue so ordering is preserved. Changelog: [Internal] Reviewed By: javache Differential Revision: D36379125 fbshipit-source-id: d9f63f4d47d8453d51add61763b7b9c74ffe9d88 --- Libraries/Animated/NativeAnimatedHelper.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Libraries/Animated/NativeAnimatedHelper.js b/Libraries/Animated/NativeAnimatedHelper.js index e97a10d262e..81ac2b35598 100644 --- a/Libraries/Animated/NativeAnimatedHelper.js +++ b/Libraries/Animated/NativeAnimatedHelper.js @@ -78,7 +78,10 @@ const API = { } }, queueOperation: (fn: () => void): void => { - if (queueOperations) { + // If queueing is explicitly on, *or* the queue has not yet + // been flushed, use the queue. This is to prevent operations + // from being executed out of order. + if (queueOperations || queue.length !== 0) { queue.push(fn); } else { fn();