Closed ScriptedAlchemy closed 2 years ago
@ScriptedAlchemy did you ever explored if it's possible to use MF with Remix?
Yeah it is. Jacob used to be on my platform team at lulu. Hems at remixx now. He knows MF better than anyone else outside of webpack, together we got MF working on next and in the process he prototyped it on remixx
The trick is you pretty much have a sidecar build (same as next) that's webpack based. So the remote entry and exposed modules go thru webpack. Then you can hook share scope up to ESM modules from esbuild.
Process is near the same for how we make it work in nextjs. Sometime in December we were planning to try and make something out of it.
Spoke with him about it last week actually so this is something we are actively thinking about
@ScriptedAlchemy do you know if there are any plans to add an example of this to the Module Federation examples on GitHub and/or release a plugin to facilitate this?
We already use Module Federation at work but are currently doing client-rendering which has obvious paint points. Ive wanted to move us to Next for some time now, but the ongoing lack of support for Module Federation means we would need to do some drastic reworking of our architecture that just wouldn't be worth it.
If Remix looks winds up with more realistic Module Federation support in the nearer future, then that's ultimately the path for our company to head down.
If Remix looks winds up with more realistic Module Federation support in the nearer future, then that's ultimately the path for our company to head down.
@lancej1022 I pretty much doubt Remix will adopt MF in near future. Reason is dead simple — Remix doesn't use Webpack.
Support for this is a must!
We appreciate everyone letting us know they’re looking for a solution here. However, we'd like to ask you to reserve comments for additional information to move this discussion forward. If you would like to show your support, please add a :thumbsup: emoji on the initial comment instead. Thank you.
Feature request
@Timer @rauchg @timneutkens In order to stop my "Twitter Driven Development" (still love that quote) I have updated the description of this issue to hopefully help move this challenge forwards.
Is your feature request related to a problem? Please describe.
Support Module Federation ability to share vendor code, like react
Describe the solution you'd like
import(./bootstrap)
method in order to allow webpack to figure out if react exists already or if it needs to go and download the chunk. Ideally, there should be only one entrypoint, then whatever else needs to happen is done so via code splitting and async imports.shared: {import:'react',eager:true}
work - this would force react to be loaded upfront - however it seems that react is included multiple times in each entrypoint - causing various multiple copies of react issues. If eager worked, I could at least share react and force the remote to always use the hosts copy of react (I think) - this would / should be okay since next mostly requires us to be on a somewhat consistent version of react. Like next 11 will use v17, since all my apps use the latest nextjs, they will be compliment with a v17 version of react.The bare minimum to get this working client or server-side would be to have some flag that changes how the client entrypoint gets started. If the
client.js
looked like this https://github.com/module-federation/module-federation-examples/blob/master/bi-directional/app1/src/index.js then there's a high likelihood we could hold up the application until whatever shared modules with static imports were ready before hydration begins.Current workaround
My workaround no longer works for SSR (since 10.x), but works for CSR - is to alias
react
as some external global https://github.com/module-federation/nextjs-mf/blob/main/react.js~I then
patchSharing
which is an ultra hack that literally inlines react into the head of_document
as ascript
https://github.com/module-federation/nextjs-mf/blob/main/patchSharing.js~ I useresolve.alias
againstreact$
to point react imports to my custom react file https://github.com/module-federation/nextjs-mf/blob/main/withModuleFederation.js#L27~This is not optimal for production-grade use but the limits of next give us little choice~ Seems okay for production grade apps
Even with Webpack 5, what we have done to get our federated AB testing, Tag manager, and AB testing engine to work with next is apply a shim that creates a fake sharing API that attaches react to share scope manually. This mechanism is the same one that I used a year ago when next was still webpack 4 based and I was using webpack 5 remotes against v4 hosts.