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

Ensure C++ default tmmd can access the CxxReactPackage #41673

Closed
wants to merge 3 commits into from

Conversation

RSNara
Copy link
Contributor

@RSNara RSNara commented Nov 28, 2023

Summary:

The Problem

The cxxReactPackage property isn't initialized by the time initHybrid was executed. So, initHybrid was being called with null as the cxxReactPackage.

Why;

  1. The default turbomodule manager delegate receives cxxReactPackage as a constructor param.
  2. Java then executes all the constructors of the class hierarchy. This executes initHybrid.
  3. Java finally initializes the properties of the derived class: default tmmd.cxxReactPackage (i.e: the parameter to initHybrid). This is too late

The Fix

Move init hybrid to a static method in default turbomodule manager. Call this static method with the passed in cxxreactpackage. And use the resultant HybridData to initialize the turbomodulemanager delegate hierarchy.

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D51550623

@facebook-github-bot facebook-github-bot added CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Facebook Partner: Facebook Partner labels Nov 28, 2023
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D51550623

RSNara added a commit to RSNara/react-native that referenced this pull request Nov 28, 2023
Summary:

## The Problem
The cxxReactPackage property isn't initialized by the time initHybrid was executed. So, initHybrid was being called with null as the cxxReactPackage.

Why;
1. The default turbomodule manager delegate receives cxxReactPackage as a constructor param.
2. Java then executes all the constructors of the class hierarchy. This executes initHybrid.
3. Java finally initializes the properties of the derived class: default tmmd.cxxReactPackage (i.e: the parameter to initHybrid). **This is too late**

## The Fix
Refactor the code such that hybrid data creation doesn't depend on property initialization:
1. Create a static initHybrid method in default tmmd.
2. Call this static method with the cxxReactPackage, and assign the resultant HybridData to mHybridData (in tmmd).


Changelog: [Internal]

Reviewed By: javache

Differential Revision: D51550623
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D51550623

RSNara added a commit to RSNara/react-native that referenced this pull request Nov 28, 2023
Summary:

## The Problem
The cxxReactPackage property isn't initialized by the time initHybrid was executed. So, initHybrid was being called with null as the cxxReactPackage.

Why;
1. The default turbomodule manager delegate receives cxxReactPackage as a constructor param.
2. Java then executes all the constructors of the class hierarchy. This executes initHybrid.
3. Java finally initializes the properties of the derived class: default tmmd.cxxReactPackage (i.e: the parameter to initHybrid). **This is too late**

## The Fix
Refactor the code such that hybrid data creation doesn't depend on property initialization:
1. Create a static initHybrid method in default tmmd.
2. Call this static method with the cxxReactPackage, and assign the resultant HybridData to mHybridData (in tmmd).


Changelog: [Internal]

Reviewed By: javache

Differential Revision: D51550623
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D51550623

RSNara added a commit to RSNara/react-native that referenced this pull request Nov 28, 2023
Summary:

## The Problem
The cxxReactPackage property isn't initialized by the time initHybrid was executed. So, initHybrid was being called with null as the cxxReactPackage.

Why;
1. The default turbomodule manager delegate receives cxxReactPackage as a constructor param.
2. Java then executes all the constructors of the class hierarchy. This executes initHybrid.
3. Java finally initializes the properties of the derived class: default tmmd.cxxReactPackage (i.e: the parameter to initHybrid). **This is too late**

## The Fix
Refactor the code such that hybrid data creation doesn't depend on property initialization:
1. Create a static initHybrid method in default tmmd.
2. Call this static method with the cxxReactPackage, and assign the resultant HybridData to mHybridData (in tmmd).


Changelog: [Internal]

Reviewed By: javache

Differential Revision: D51550623
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D51550623

RSNara added a commit to RSNara/react-native that referenced this pull request Nov 28, 2023
Summary:

## The Problem
The cxxReactPackage property isn't initialized by the time initHybrid was executed. So, initHybrid was being called with null as the cxxReactPackage.

Why;
1. The default turbomodule manager delegate receives cxxReactPackage as a constructor param.
2. Java then executes all the constructors of the class hierarchy. This executes initHybrid.
3. Java finally initializes the properties of the derived class: default tmmd.cxxReactPackage (i.e: the parameter to initHybrid). **This is too late**

## The Fix
Refactor the code such that hybrid data creation doesn't depend on property initialization:
1. Create a static initHybrid method in default tmmd.
2. Call this static method with the cxxReactPackage, and assign the resultant HybridData to mHybridData (in tmmd).


Changelog: [Internal]

Reviewed By: javache

Differential Revision: D51550623
Summary:

FBJni expects the HybridData object to exist on the mHybridData property of the java object. So, we have to call this propery mHybridData.

Otherwise, this fbjni class just won't work.

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D51550621
Summary:

The problem: The Java runtime couldn't find CatalystCxxReactPackage.initHybrid.

Why: I think is because CxxReactPackage loads CatalystCxxReactPackage's so in its constructor. This might be too late to load the derived class's so.

So, I just switched derived delegates to load the so in the static initializer (i.e: the recomended approch for so loading):

https://www.internalfb.com/code/fbsource/[91c4e41c49ed191ac864250ccaec52c01ddaeccc]/fbandroid/libraries/soloader/java/com/facebook/soloader/SoLoader.java?lines=52-54%2C60-61%2C63-67

This way:
1. The So's are loaded plenty early (the method not found error went away).
2. We don't create our own so loading infra, which complicates this abstraction, and makes it harder to work with, even more.

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D51550622
Summary:

## The Problem
The cxxReactPackage property isn't initialized by the time initHybrid was executed. So, initHybrid was being called with null as the cxxReactPackage.

Why;
1. The default turbomodule manager delegate receives cxxReactPackage as a constructor param.
2. Java then executes all the constructors of the class hierarchy. This executes initHybrid.
3. Java finally initializes the properties of the derived class: default tmmd.cxxReactPackage (i.e: the parameter to initHybrid). **This is too late**

## The Fix
Refactor the code such that hybrid data creation doesn't depend on property initialization:
1. Create a static initHybrid method in default tmmd.
2. Call this static method with the cxxReactPackage, and assign the resultant HybridData to mHybridData (in tmmd).


Changelog: [Internal]

Reviewed By: javache

Differential Revision: D51550623
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D51550623

RSNara added a commit to RSNara/react-native that referenced this pull request Nov 28, 2023
Summary:

## The Problem
The cxxReactPackage property isn't initialized by the time initHybrid was executed. So, initHybrid was being called with null as the cxxReactPackage.

Why;
1. The default turbomodule manager delegate receives cxxReactPackage as a constructor param.
2. Java then executes all the constructors of the class hierarchy. This executes initHybrid.
3. Java finally initializes the properties of the derived class: default tmmd.cxxReactPackage (i.e: the parameter to initHybrid). **This is too late**

## The Fix
Refactor the code such that hybrid data creation doesn't depend on property initialization:
1. Create a static initHybrid method in default tmmd.
2. Call this static method with the cxxReactPackage, and assign the resultant HybridData to mHybridData (in tmmd).


Changelog: [Internal]

Reviewed By: javache

Differential Revision: D51550623
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D51550623

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D51550623

@analysis-bot
Copy link

Platform Engine Arch Size (bytes) Diff
android hermes arm64-v8a 17,680,867 -3
android hermes armeabi-v7a n/a --
android hermes x86 n/a --
android hermes x86_64 n/a --
android jsc arm64-v8a 21,063,894 +0
android jsc armeabi-v7a n/a --
android jsc x86 n/a --
android jsc x86_64 n/a --

Base commit: a8fc206
Branch: main

@facebook-github-bot facebook-github-bot added the Merged This PR has been merged. label Nov 28, 2023
@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 129bd9d.

Othinn pushed a commit to Othinn/react-native that referenced this pull request Jan 9, 2024
Summary:
Pull Request resolved: facebook#41673

## The Problem
The cxxReactPackage property isn't initialized by the time initHybrid was executed. So, initHybrid was being called with null as the cxxReactPackage.

Why;
1. The default turbomodule manager delegate receives cxxReactPackage as a constructor param.
2. Java then executes all the constructors of the class hierarchy. This executes initHybrid.
3. Java finally initializes the properties of the derived class: default tmmd.cxxReactPackage (i.e: the parameter to initHybrid). **This is too late**

## The Fix
Refactor the code such that hybrid data creation doesn't depend on property initialization:
1. Create a static initHybrid method in default tmmd.
2. Call this static method with the cxxReactPackage, and assign the resultant HybridData to mHybridData (in tmmd).

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D51550623

fbshipit-source-id: ed2b7587351cfca408cda3c8cef4dcf7547e5f1e
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. p: Facebook Partner: Facebook Partner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants