Skip to content

Commit

Permalink
Clean up old code for microtasks in Hermes
Browse files Browse the repository at this point in the history
Summary:
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.

Differential Revision: D57922076
  • Loading branch information
rubennorte authored and facebook-github-bot committed May 29, 2024
1 parent 3c31e9d commit 9657d3e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
15 changes: 5 additions & 10 deletions packages/react-native/Libraries/Core/setUpTimers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ export interface Spec extends TurboModule {
+queueMicrotask: (callback: () => mixed) => void;
}

export default (TurboModuleRegistry.get<Spec>('NativeMicrotasksCxx'): ?Spec);
export default (TurboModuleRegistry.getEnforcing<Spec>(
'NativeMicrotasksCxx',
): Spec);

0 comments on commit 9657d3e

Please sign in to comment.