Skip to content

Add unit tests for RCTInstance eager main-queue module setup#56919

Closed
javache wants to merge 1 commit into
react:mainfrom
javache:export-D105953816
Closed

Add unit tests for RCTInstance eager main-queue module setup#56919
javache wants to merge 1 commit into
react:mainfrom
javache:export-D105953816

Conversation

@javache

@javache javache commented May 21, 2026

Copy link
Copy Markdown
Contributor

Summary:
There was no unit-test coverage for enableEagerMainQueueModulesOnIOS, the
runtime gate that lets selected native modules initialize on the main thread
during React Native init. These characterization tests pin down the behavior
end-to-end through the real production path:

  • With the flag off, RCTInstanceDelegate.unstableModulesRequiringMainQueueSetup
    is never consulted and no eager module is instantiated.
  • With the flag on, the delegate is consulted exactly once and each returned
    module name flows through RCTTurboModuleManager to a real -init on the
    main queue.
  • The JS thread that drives _loadScriptFromSource: blocks at the beforeLoad
    hook until the eager module setup completes. The bundle-load test runs init
    on a background queue, gates FakeEagerModule.init on a semaphore, and
    observes the RCTInstanceDidLoadBundle notification fired from afterLoad
    asserting that by the time the gate opens, the module's constructor has fully
    returned.

The tests exercise the real RCTModuleRegistry + RCTTurboModuleManager path
(no subclass shims, no KVC into private ivars). The fixture provides a minimal
FakeEagerModule conforming to <RCTBridgeModule, RCTTurboModule> so it
survives TMM's _shouldCreateObjCModule: filter when interop is off.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D105953816

Summary:
There was no unit-test coverage for `enableEagerMainQueueModulesOnIOS`, the
runtime gate that lets selected native modules initialize on the main thread
during React Native init. These characterization tests pin down the behavior
end-to-end through the real production path:

- With the flag off, `RCTInstanceDelegate.unstableModulesRequiringMainQueueSetup`
  is never consulted and no eager module is instantiated.
- With the flag on, the delegate is consulted exactly once and each returned
  module name flows through `RCTTurboModuleManager` to a real `-init` on the
  main queue.
- The JS thread that drives `_loadScriptFromSource:` blocks at the `beforeLoad`
  hook until the eager module setup completes. The bundle-load test runs init
  on a background queue, gates `FakeEagerModule.init` on a semaphore, and
  observes the `RCTInstanceDidLoadBundle` notification fired from `afterLoad` —
  asserting that by the time the gate opens, the module's constructor has fully
  returned.

The tests exercise the real `RCTModuleRegistry` + `RCTTurboModuleManager` path
(no subclass shims, no KVC into private ivars). The fixture provides a minimal
`FakeEagerModule` conforming to `<RCTBridgeModule, RCTTurboModule>` so it
survives TMM's `_shouldCreateObjCModule:` filter when interop is off.

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D105953816
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 21, 2026
@meta-codesync

meta-codesync Bot commented May 21, 2026

Copy link
Copy Markdown

@javache has exported this pull request. If you are a Meta employee, you can view the originating Diff in D105953816.

@meta-codesync meta-codesync Bot closed this in 5e0fd8e May 21, 2026
@facebook-github-tools facebook-github-tools Bot added the Merged This PR has been merged. label May 21, 2026
@react-native-bot

Copy link
Copy Markdown
Collaborator

This pull request was successfully merged by @javache in 5e0fd8e

When will my fix make it into a release? | How to file a pick request?

@meta-codesync

meta-codesync Bot commented May 21, 2026

Copy link
Copy Markdown

This pull request has been merged in 5e0fd8e.

@javache javache deleted the export-D105953816 branch May 22, 2026 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants