From e91a5772625e8687d72b7e9e436672d0001d3f2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Thu, 30 May 2024 04:22:50 -0700 Subject: [PATCH] Clean up old code for microtasks in Hermes (#44708) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/44708 Changelog: [internal] We had a fallback to use a Hermes internal API if the native module exposing `queueMicrotask` wasn't available. This is no longer necessary as the module is available everywhere we enable the event loop, so we can remove it. Reviewed By: christophpurrer Differential Revision: D57922076 fbshipit-source-id: 0ca48abacd77a75ce8559db08f55c78a3e0ec815 --- .../react-native/Libraries/Core/setUpTimers.js | 15 +++++---------- .../webapis/microtasks/specs/NativeMicrotasks.js | 4 +++- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/packages/react-native/Libraries/Core/setUpTimers.js b/packages/react-native/Libraries/Core/setUpTimers.js index db0ac5dc1e7..f4bc4360ab9 100644 --- a/packages/react-native/Libraries/Core/setUpTimers.js +++ b/packages/react-native/Libraries/Core/setUpTimers.js @@ -63,17 +63,12 @@ if ( // mechanism to pass feature flags from RN to React in OSS. global.RN$enableMicrotasksInReact = true; - polyfillGlobal('queueMicrotask', () => { - const nativeQueueMicrotask = + polyfillGlobal( + 'queueMicrotask', + () => require('../../src/private/webapis/microtasks/specs/NativeMicrotasks') - .default?.queueMicrotask; - if (nativeQueueMicrotask) { - return nativeQueueMicrotask; - } else { - // For backwards-compatibility - return global.HermesInternal?.enqueueJob; - } - }); + .default.queueMicrotask, + ); // We shim the immediate APIs via `queueMicrotask` to maintain the backward // compatibility. diff --git a/packages/react-native/src/private/webapis/microtasks/specs/NativeMicrotasks.js b/packages/react-native/src/private/webapis/microtasks/specs/NativeMicrotasks.js index 5fa44e54803..4f07158ad6b 100644 --- a/packages/react-native/src/private/webapis/microtasks/specs/NativeMicrotasks.js +++ b/packages/react-native/src/private/webapis/microtasks/specs/NativeMicrotasks.js @@ -16,4 +16,6 @@ export interface Spec extends TurboModule { +queueMicrotask: (callback: () => mixed) => void; } -export default (TurboModuleRegistry.get('NativeMicrotasksCxx'): ?Spec); +export default (TurboModuleRegistry.getEnforcing( + 'NativeMicrotasksCxx', +): Spec);