Skip to content

Add InstanceHandle::createOpaque for non-JSI Fabric hosts - #60393

Open
birkskyum wants to merge 1 commit into
react:mainfrom
birkskyum:opaque-instance-handle
Open

birkskyum wants to merge 1 commit into
react:mainfrom
birkskyum:opaque-instance-handle

Conversation

@birkskyum

@birkskyum birkskyum commented Nov 30, 2026 •

Copy link
Copy Markdown

Summary:

InstanceHandle currently requires (jsi::Runtime&, const jsi::Value&, Tag) and always holds a jsi::WeakObject. Non-React Fabric hosts that track shadow nodes by an integer ID (context in RFC #1041) end up allocating a dummy JS object per node and having to tear down all shadow nodes before Hermes shuts down so those WeakObjects do not outlive the runtime.

This changes InstanceHandle to store std::variant<jsi::WeakObject, uint64_t> and adds InstanceHandle::createOpaque(Tag, uint64_t) along with getOpaqueHostNodeId() on InstanceHandle and EventTarget. For opaque handles, getInstanceHandle(runtime) returns jsi::Value::null() (matching existing null checks in EventTarget, ShadowNodeFamily, NativeDOM, and UIManagerBinding) and destruction does not touch JSI.

Updates the C++ API snapshots under scripts/cxx-api/api-snapshots/.

Changelog:

[General] [Added] - Add InstanceHandle::createOpaque and getOpaqueHostNodeId for non-JSI Fabric hosts

Test Plan:

Added unit tests in packages/react-native/ReactCommon/react/renderer/core/tests/EventTargetTests.cpp covering JSI vs opaque handles, EventTarget forwarding, and destroying opaque handles and targets after runtime teardown.

Compiled locally with clang++ (-std=c++20, -fno-exceptions, and ASan/UBSan with a mock runtime), formatted with clang-format, and checked the ReactCommonDebug snapshot via scripts.cxx-api.parser.

@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 Nov 30, 2026
@github-actions github-actions Bot added the Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. label Nov 30, 2026
birkskyum added a commit to birkskyum/discussions-and-proposals that referenced this pull request Nov 30, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Nov 30, 2026
@birkskyum birkskyum changed the title Add opaque InstanceHandle::createOpaque for non-JSI Fabric hosts Add InstanceHandle::createOpaque for non-JSI Fabric hosts Nov 30, 2026

This branch has not been deployed

No deployments
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. Meta Review Required This PR is considered risky and requires Meta to import it to do more testing before merging. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant