Content-Length: 237589 | pFad | http://github.com/facebook/react-native/pull/48942

3A Support for custom JavaScript runtimes for the new architecture in Android by lukaszkurantdev · Pull Request #48942 · facebook/react-native · GitHub
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

Support for custom JavaScript runtimes for the new architecture in Android #48942

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lukaszkurantdev
Copy link

Summary:

In the old architecture, we have the ability to easily change the JavaScript runtime on Android using the overridden getJavaScriptExecutorFactory function in the ReactNativeHost abstract class. This creates a new instance of the factory and an executor with assigned runtime. However, in the new architecture, engine selection occurs in the DefaultReactHost object and depends on the isHermesEnabled property of the ReactNativeHost class. This logic is limited to engine selection between Hermes and JSC and lacks the ability to easily override it (as is the case with iOS code).

This PR includes a modification of this mechanism so that the function responsible for selecting the Runtime is in the DefaultReactNativeHost object – this will allow it to be written from within the project's MainApplication class, e.g:

class MainApplication : Application(), ReactApplication {
  override val reactNativeHost: ReactNativeHost =
    object : DefaultReactNativeHost(this) {
       //...
       override fun getJSRuntimeFactory(): JSRuntimeFactory {
           return CustomJSInstance() // e.g. V8Instance
       }
    }

Exactly as was the case with the old architecture and function:

override fun getJavaScriptExecutorFactory(): JavaScriptExecutorFactory {
  return CustomJSExecutorFactory()
}

This is particularly important when using custom JS engines other than Hermes or JSC in a project, such as the V8 (https://github.com/Kudo/react-native-v8), or smaller engines tailored to selected devices or solutions.

Changelog:

[ANDROID] [CHANGED] - Moving the Javascript Runtime selection to the DefaultReactNativeHost object to allow selection of custom JS runtimes

Test Plan:

All tests were successfully completed.

@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. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. labels Jan 25, 2025
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. 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.

2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/facebook/react-native/pull/48942

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy