Replies: 3 comments
-
|
Two separate things going on here, and the React one is non-negotiable. You can't run two React versions in the same page and share components between them. Hooks resolve through a single module-level dispatcher, so the moment a component from remote A (React 18) renders inside host B (React 19), that dispatcher is wrong and you get "invalid hook call" and everything falls apart. No config makes that safe. Second thing: Rough shape: import { federation } from '@module-federation/vite'
federation({
name: 'host',
remotes: { /* ... */ },
shared: {
react: { singleton: true, requiredVersion: '19.0.0' },
'react-dom': { singleton: true, requiredVersion: '19.0.0' },
},
})On the TS types: pin one React version in the workspace root so every package resolves the same So: force one React version, mark it singleton, let the official plugin handle the sharing. "Multiple React versions live at once" isn't a thing worth chasing, that road only ends in broken hooks. |
Beta Was this translation helpful? Give feedback.
-
|
@apoorva-01 Great explanation on the singleton constraint! But this raises a deeper architectural question: What happens in this scenario? // Host App (React 19)
const RemoteA = React.lazy(() => import("remoteA/App")); // React 18
const RemoteB = React.lazy(() => import("remoteB/App")); // React 19
function Host() {
return (
<>
<RemoteA /> {/* Uses React 18 hooks dispatcher */}
<RemoteB /> {/* Uses React 19 hooks dispatcher */}
</>
);
}With
If we force singleton to React 19, RemoteA breaks because it expects React 18 API. If we force React 19, RemoteB can not use new features. The real question: Is there a viable strategy for gradual migration across micro-frontends where:
Or is the only answer: "upgrade everything at once, or dont bother with Module Federation"? Also, regarding |
Beta Was this translation helpful? Give feedback.
-
|
Coexistence problem: The issue isn't the React version itself, it's that and as JSX get reconciled by Host's React instance. That's baked into how JSX composition works — no config changes it. So singleton: true can't work across major versions, and without it you get the double-dispatcher crash. DOM mount isolation — remote exposes mount(container, props) / unmount(container), host calls it via useEffect, each remote runs its own ReactDOM.createRoot(). Fully separate React trees, communicate via props/callbacks or DOM events, not context. This is how single-spa handles it. Tradeoff: no shared Context/Suspense across remotes, no passing JSX children directly. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
I am building a micro-frontend architecture with Vite 8 and Module Federation. Different micro-apps use different versions of the same dependency.
Architecture
Host App with multiple Micro Apps, each potentially using different React versions.
Current approach
Using @originjs/vite-plugin-federation with shared dependencies.
Problems
What I tried
Questions
Environment
Any insights on micro-frontend architecture with Vite would be appreciated.
Beta Was this translation helpful? Give feedback.
All reactions