Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] PoC: Use jsi::Value from prop directly #47717

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

hannojg
Copy link
Contributor

@hannojg hannojg commented Nov 19, 2024

Summary:

🚧 THIS PoC IS WORK IN PROGRESS

This PR highlights how we'd like to access the underlying jsi::Value directly to work with complex data types currently not supported for our Fabric Component Views.

The problem basically being that the jsi prop object we receive from JS in the FabricUIManager is converted to a RawProps type, which only allows us to access props via a .at method which returns a RawValue. This RawValue only supports folly::dynamic types (primitives, arrays and objects), to which we convert the original jsi::Value for every prop.

We'd like to pass complex types such as HostObjects or jsi::Objects with NativeState attached to our components.

The goal of this PoC PR is not to be merged to core but to discuss how we can make such a change happen.

Possible solutions

Expose jsi::Value and jsi::Runtime in RawProps

RawProps already holds the jsi::Object to the original prop object which we could simply expose to access the real underlying jsi::Value of a prop, which is what this PoC does:

https://github.com/hannojg/react-native/blob/e186024d43bb7f8ed70e73fe4ed334bc534eb9af/packages/react-native/ReactCommon/react/renderer/core/RawProps.h#L97-L101

and then when creating the props for our specific fabric component we can do:

https://github.com/hannojg/react-native/blob/e186024d43bb7f8ed70e73fe4ed334bc534eb9af/packages/rn-tester/ManualComponent/ManualFabricComponentView.mm#L27-L42

Have jsi::Value and jsi::Runtime in RawValue

We could have a pair of jsi::Value and jsi::Runtime in RawValue. Then for the prop implementation for a fabric native component view we could use this value during parsing to convert it to our desired complex type:

https://github.com/hannojg/react-native/blob/e186024d43bb7f8ed70e73fe4ed334bc534eb9af/packages/react-native/ReactCommon/react/renderer/core/RawValue.h#L75-L88

Problems:

  • I found it difficult to figure out in RawPropParser to decide when we should parse to folly::dynamic or when to use jsi::Value during parsing (here we'd need to decide whether to use a folly::dynamic arg or jsi::Value)

Make RawProps hybrid / generic

The actual answer seems to be to make the RawPropsParser generic. A PoC explanation can be found here:
#44966 (comment)

Alternative path to RawProps

In the UIManager add a second way here for example:

Where based on some criteria we wouldn't create RawProps but an alternative wrapper (that gives us access to the original jsi types)

Problems:

  • Not really a problem but it seems like we had to change a ton of places to account for that as RawProps are used / assumed in a lot of places

Changelog:

Test Plan:

@facebook-github-bot facebook-github-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 19, 2024
@react-native-bot
Copy link
Collaborator

react-native-bot commented Nov 19, 2024

Fails
🚫

📋 Verify Changelog Format - See Changelog format

Generated by 🚫 dangerJS against 7232c90

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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants