From 5635d5c0a31760baa5cc01d628ec35ebe92a74e1 Mon Sep 17 00:00:00 2001 From: Tim Yung Date: Fri, 7 Feb 2025 08:18:42 -0800 Subject: [PATCH] RN: Avoid Rejections in `InteractionManagerStub` (#49241) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/49241 In auditing differences between `InteractionManager` and `InteractionManagerStub` (used to evaluate to entirely remove the former all together), I noticed a behavioral disparity with how errors are handled. In `InteractionManager`, the promise that's returned is never rejected, whereas `InteractionManagerStub` propagates errors by rejecting the promise that's returned. This changes `InteractionManagerStub` to behave like `InteractionManager` for the purpose of comparing apples-to-apples. Changelog: [Internal] Reviewed By: javache Differential Revision: D69275495 fbshipit-source-id: 05439a0cadc1f76b34a3f1457f7db31d6bda2a90 --- .../Libraries/Interaction/InteractionManagerStub.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/react-native/Libraries/Interaction/InteractionManagerStub.js b/packages/react-native/Libraries/Interaction/InteractionManagerStub.js index 5b45d8bd76b..4e94dcf40ce 100644 --- a/packages/react-native/Libraries/Interaction/InteractionManagerStub.js +++ b/packages/react-native/Libraries/Interaction/InteractionManagerStub.js @@ -25,6 +25,14 @@ type Task = } | (() => void); +// NOTE: The original implementation of `InteractionManager` never rejected +// the returned promise. This preserves that behavior in the stub. +function reject(error: Error): void { + setTimeout(() => { + throw error; + }, 0); +} + /** * InteractionManager allows long-running work to be scheduled after any * interactions/animations have completed. In particular, this allows JavaScript @@ -97,7 +105,7 @@ const InteractionManagerStub = { ... } { let immediateID: ?$FlowIssue; - const promise = new Promise((resolve, reject) => { + const promise = new Promise(resolve => { immediateID = setImmediate(() => { if (typeof task === 'object' && task !== null) { if (typeof task.gen === 'function') {