How bad it might be for performance to use multiple ReactDOM.render functions simultaneously? For example, up to 30+ ReactDOM.render calls.
I know it may sound strange. I'm currently working on a large web project that uses single ReactDOM.render function. One of the largest problems we've come up with was update to React 18. Since the project is pretty big and contains many legacy code there are many places where you can meet usage of legacy approaches that are not supported by the newest React version. I want to split one SPA on multiple independent subapplications (a.k.a. micro-frontends), but still use a single deployment build, have in-memory cache that can be shared across apps, keep SPA experience for users, etc. Yet, at the same time have the capability of gradual migration on a newer versions of React.
We've already managed to create a working proof of concept by refactoring two subapps. Currently the startup of every app looks somewhat like this:
// Subscribe on URL path change.
observer.on('changed', () => {
if (window.location.path.includes(targetPath)) {
ReactDOM.render(<App />, elementContainer);
} else {
ReactDOM.unmountComponentAtNode(elementContainer);
}
});
As you can see we don't start React immediately, unless we enter the specific route. But ideally I would prefer if application's entry point looked like this:
const AppEntryPoint = () => {
<Switch>
<Route path="...">
<App />
</Route>
<Route>{null}</Route>
</Switch>
};
ReactDOM.render(<AppEntryPoint />, elementContainer);
And the question is: how bad it may be at the startup with 30+ entry points like this? Are there any other serious issues that I didn't notice?