Module Fedaration support for Uniwind #612
dlebedynskyi
started this conversation in
Ideas
Replies: 2 comments
It wasn't requested before, and we don't really use module federation inside our own projects.
I don't have a better solution in mind right now
Could you open PR with just adding a new |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Support for Module Federation (multiple remotes sharing one Uniwind runtime)
I'd like to open a discussion about first-class support for Module Federation in Uniwind — specifically, letting multiple independently-built remotes share a single
Uniwind runtime on both web and native without their styles colliding.
Today Uniwind works great in a single-bundle app. But in a Module Federation setup, a host loads several remotes that were each built separately (often by different teams,
on different release cadences) and may be present on screen at the same time. In that world, a few of Uniwind's current assumptions break down.
Metro now fully supports MF 2.0, and we're starting to use it for our app(s) — so this isn't hypothetical need for us and, if this does not land, we probably would have to fork or patch. However, I believe that problem is better solved at lib level.
Refs:
I don't have a fully-formed solution to propose yet — I want to align on whether this is in scope, and on the shape of the problems. I've done some exploration and I'll show how it could potentially be made possible.
Concrete problems
Web
.bg-surface,.flex) and theme variables into the shared document. Two remotes built independently can generatethe same class name with different definitions, so which one "wins" depends on load order — a non-deterministic styling bug.
From what I've gathered, on web we're effectively using a single
documentas the root for the CSS stylesheets. This works as long as classes and vars don't collide.Potentially we could use Tailwind's
prefixto resolve collisions while keeping the same root. Alternatives like aShadowRootper remote are possible to isolate stylesheets, but IMO more complex.Refs:
prefixShadowRoot+ rendering React into a ShadowRoot viacreatePortal(React 18+)Native
reinit). When a remote loads, it can wipe the styles registered by the host or an earlier remote.Potentially we could merge if we can avoid name collisions (via the Tailwind v4
prefix), or we move the store from a singleton into React Context to allow overrides at a remote boundary.What is the minimal set of changes?
At the very least we'd need to support merging styles instead of a whole
reinit. That alone lets consumers useprefixexplicitly to avoid collisions.Is there a better way?
We could make it an opt-in build option, following the existing pattern of wrapping Metro with
withUniwind. This probably works better — we can tell the build "this bundle is a remote: use these common classes (Preflight / other host-provided commons), and prefix everything else."Properties of this approach:
Questions
Happy to prototype and contribute a PR if there's appetite.
All reactions