You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to create a single store instance in the host application (federation_consumer) and use it in both the host and remote applications. However, I am experiencing an issue with infinite TypeScript type generation when using rsbuild with Module Federation v2.0.
This issue does NOT occur in Rsbuild v1.5.
It also does NOT occur in production mode (after the build is complete).
The problem seems to be related to the self-reference of the host in rsbuild.config.ts.
Steps to Reproduce
Configure rsbuild.config.ts in the host application:
importProviderButtonfrom'federation_provider/button';import{useAppStore}from'federation_consumer/store';// Importing store from self-referenceconstApp=()=>{const{ count, reset }=useAppStore();console.log(count);constonReset=()=>{reset();};return(<divclassName="content"><h1>Rsbuild with React</h1><p>Start building amazing things with Rsbuild.</p><buttononClick={onReset}>Reset</button><div><ProviderButton/></div></div>);};exportdefaultApp;
Why would you self reference, this will cause runtime errors in your application. The bundler runtime will collide with its remote counterpart as they both replace eachothers global callbacks
My colleagues and I also started our journey with module federation by using self-reference for a similar reason—to ensure that the states created in the root/shell MFE would remain singletons across the system. It even made it to production for a while, but we eventually had to find alternatives as other problems emerged from this arrangement.
To follow @ScriptedAlchemy advice and avoid self-reference, consider moving your stores outside the root MFE. You can either define them in a remote or create a shared package to house those global stores.
That said, while I don’t recommend this approach, disabling dts.generateTypes.extractRemoteTypes should prevent the recursive behavior in this particular case.
This seems like a common use case—defining a store in the root/ shell MFE and discovering that exposing it creates one instance for the app entry point and another for the expose in MF. Do you know of any better solutions than the ones I mentioned above?
Describe the bug
I'm trying to create a single store instance in the host application (federation_consumer) and use it in both the host and remote applications. However, I am experiencing an issue with infinite TypeScript type generation when using rsbuild with Module Federation v2.0.
The problem seems to be related to the self-reference of the host in rsbuild.config.ts.
Steps to Reproduce
Reproduction
https://github.com/Voloshch/rsbuildmfe
Used Package Manager
npm
System Info
Validations
The text was updated successfully, but these errors were encountered: