-
Notifications
You must be signed in to change notification settings - Fork 293
feat: cjs interop #720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: cjs interop #720
Conversation
We do it this way to prevent reloading a share scope module
| format: "esm" | "systemjs" | "var"; | ||
| from: "vite" | "webpack; | ||
| from: "vite" | "webpack"; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed a small typo here
| return import(/* @vite-ignore */ name).then(module => ()=> { | ||
| if (${REMOTE_FROM_PARAMETER} === 'webpack') { | ||
| if ((globalThis.__federation_shared_remote_from__ ?? ${REMOTE_FROM_PARAMETER}) === 'webpack') { | ||
| return Object.prototype.toString.call(module).indexOf('Module') > -1 && module.default ? module.default : module |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as per my PR description, if you think it's better to rebind the share scope instead of taking __federation_shared_remote_from__ to be the accepted remote from, let me know. This does have the downside of not allowing a merge in the case of a conflicting share scope format.
e7a4420 to
fad8803
Compare


Description
Hi. Love your package. In my team, we have a small issue where we are running a nested microfrontend setup with the inner most MFE being Webpack (var) and the other two being Vite (esm). When running the middle MFE with the nested MFE things are all fine, since the shared scope initialises as expected (var). However, when running all three together, the shared scope initialises as Vite (ESM) since that is what the middle MFE is running as. When the inner-most MFE goes to import modules, the
mergefunction call in /packages/lib/src/dev/remote-production.ts - Line 150 makes the assumption that the remote format/from is the same as what is already loaded intoglobalThis. However, in such as situation as I describe above, this is not the case!I acknowledge on the README there is the following point
... however, my PR aims to fix this issue by ensuring shared modules are seeded correctly even in cases of cross-runtime federation interoperability!
Additional context
My solution involves setting a global variable to the "remote from" of the share scope which is being loaded. Then in the
getcallback, we use this as a priority over the already-bound${REMOTE_FROM_PARAMETER}parameter (set when the outer-most app or host begins its share scope initialisation).I tried to curry the remote from into the
getcallback but since we rely on Webpack to actually call thegetfunction, I don't think this is possible without reinitialising the share scope (around wheregetModuleMarkeris called). This could be a viable solution but might slightly hurt performance. Thoughts welcome.Hugo
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123).