react-native icon indicating copy to clipboard operation
react-native copied to clipboard

proposal: RCTBundleConsumer interface

Open tjzel opened this issue 8 months ago • 0 comments

Summary:

With the development of react-native-worklets library I want to align it more with the tools inside React Native ecosystem and reduce the amount of hacks needed to provide multithreading JavaScript solutions. One of the steps there is to obtain multi-threading (byte)code via Metro, instead of Babel tricks and evalWithSourceMap. For this sake it would be very handy to have an interface a Turbo Module could implement, that would allow it to get the bundle and all hot-reload updates. This would also benefit other libraries that are featuring multi-threading JavaScript.

The changes in this PR are only to demonstrate the PoC of iOS RCTBundleConsumer (or any other name you'd find suitable). The real implementation should probably base on event handlers and more elaborate constructions instead of a simple property, to support hot-reloads and other cases.

Please let me know if this is a feature you find acceptable within the ecosystem or if such feature already exists in some form - I know there's [self.bundle.delegate loadBundleAtUrl:...] but I don't think it applies for this use case and if it's considered to be a part of the public API.

Changelog:

[GENERAL] [ADDED] - Add RCTBundleConsumer interface for TurboModules to access the JS bundle

Test Plan:

Implement a Turbo Module with @synthesize source = _source, use it in RNTester app and see that everything still works flawlessly.

tjzel avatar Apr 17 '25 16:04 tjzel