microsoft / react-native-windows

A framework for building native Windows apps with React.
https://microsoft.github.io/react-native-windows/
Other
16.33k stars 1.14k forks source link

Dynamically add component from external source? #4764

Closed mjfusa closed 1 year ago

mjfusa commented 4 years ago

Since it looks like CodePush is not currently supporting RNW, is it possible in RNW to add a JS only component from an external source? Something like what they are doing here: Lazy Bundle Loading in React Native 🔥 - React Native Training - Medium. I need to modify the UI based on factors I won't know until first run of the app. The ideas is, I download the supporting components for the different scenarios I need to support.

chrisglein commented 4 years ago

@acoates-ms You had some comments/thoughts on this in another thread, can you reflect that in here?

chrisglein commented 4 years ago

If this works on RN core we should identify what's needed to make it possible here (we're not intentionally blocking it in RNW).

chrisglein commented 4 years ago

Linking CodePush issue: #2477

acoates-ms commented 4 years ago

I think the only thing really missing from RNW is the ability to tell an instance to load additional JS into an already running instance. -- The rest the app can build itself. In Office we use multiple bundles within an instance. -- But we provide those bundles at instance creation. So we will likely be exposing something here. But note that adding JS to the instance after instance creation has many more implications, that I dont think are very easily handled. (And I dont think the above article handles them either). For example the implementation in the above blog will not work with live reload, let alone fast refresh. -- You would severely affect your devX doing this.

asklar commented 4 years ago

@chrisglein I think we should reactivate this given other partners may need this Internal Task 29759475: Allow dynamically updating and loading a RNW bundle

chrisglein commented 4 years ago

For changing the bundle you should be able to point the instance uri to wherever your bundle is (where it comes from is up to the app). That should work.

Loading multiple bundles at a time is where the gap is. I hear that @vmoroz may be working on support for >1 bundle. Is that work tracked elsewhere? (should we use this issue, link to an existing issue, or create something new?)

acoates-ms commented 2 years ago

You can load additional bundles using JSI

winrt::Microsoft::ReactNative::ExecuteJsi(reactContext, [wkThis](facebook::jsi::Runtime& runtime) {​​​​​​​​​​​
  auto val = runtime.evaluateJavaScript(...);
}​​​​​​​​​

Note since this uses JSI, this is not compatible with webdebugging. But that is going away anyway.

chiaramooney commented 1 year ago

@acoates-ms Can I close this issue? Is the solution you gave above sufficient or are there RNW changes still needed?

acoates-ms commented 1 year ago

The runtime.evaluateJavaScript functionality provides all the necessary hooks to do this.