Support codegen and "Native Modules 2.0" for Internal Modules
Even in an ideal world where we share component Javascript entirely with upstream, changes to the interfaces of native modules can and will break us. In the best case we noop for new APIs, but in the worst we do bad things at runtime. React Native is leaning more into code-generation to ensure type-safety. We've been following closely, but there is some extra work to get there for built-in components.
ReactUwp currently has a notion of core native modules (and default view managers in a seemingly misnamed CoreUIManagers.cpp file. These are not exposed outside of ReactUwp. Due to current dependency structure, we'd likely need to pull this further out into Microsoft.ReactNative to allow non-CxxModule native modules as the default.
Some built-in modules are included in low-level instance management code (see OInstance.cpp). This is currently the only place where we share built-in native modules between Office and RNW. Other built-in native modules for desktop live in DevMain Office, though should move these into RNW long-term.
Build logic for code-generation has been discussed in the context of standard React Native applications. This will naturally differ a bit compared to internal projects following a different structure.
We need to reconcile all of this so that we can use code-generation capabilities for these new modules for our existing ones. (Less certain of our story around ViewManagers).
Some other open questions:
- Will our code-gen tools be compatible with Facebook-style Flow specs? Sounded like there was good frontend backend division for code generation, so this should just work?
- Does this apply to ViewConfigs? My (limited) understanding is that FB checked in configs were gen'd from Native as the source of truth. Is that the long-term plan? (@acoates-ms would you be willing to share the video around this offline?)
@acoates-ms @vmoroz thoughts?
I almost like the idea of focusing on code-gen for internal modules before external, just because it would give us some real-world experience in what types of issues our consumers might see. It should also help a lot with catching API breaks and completion issues (e.g. I just discovered we've been missing some networking APIs added three years ago).
Yes we should enable and move to codegen-ing the built in native modules from facebook's flow files. That's currently largely blocked on enabling us to use the new Native Module system for our internal modules. -- Since I dont think its worth us writing codegen for the legacy cxxmodules.
Viewmanagers we probably wont get until we move to fabric but will eventually want to move to codegen too.
That makes sense. I left a bit of context on what might be needed to enable that in the issue description. I'm going to add the Deforking label back to this so I can keep an eye on it if time comes up. (Not technically deforking, but will help us keep working and consistent APIs)
We are going to address this issue as a part of the Microsoft.ReactNative DLL redesign.
Editing title to remove "View Managers" from this issue. Codegen for view managers is now tracked using #5273
We've started doing this for new internal modules, and have been slowly transitioning old modules away. Going to close this since we have the infrastructure in place. We should convert modules opportunistically when we touch them to NM2.