-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Multiple Ember apps need to be namespaced. #17
Comments
I don't understand the description of this issue. Could you re-explain it to me, or provide a demonstration? I don't see how it's related to #3 and also don't understand what you changed in the single-spa-ember library or why. |
@joeldenning Sorry about the issue description, I should have explained it clearly.
Example reproduction here Ember.js namespacingWhen we load an Ember app in the browser there is a global window object window.Ember.VERSION => 3.4 When I load the planets mfe, my existing Ember version will be overridden with the new one, so now my ember version will be window.Ember.VERSION => 3.19 we need to come up with a namespacing mechanism to solve the above issue. require.entriesSimilar to the window.Ember object there is another one called window.require.entries The problem here is even if I restore the require.entries correctly back to the right mfe, my Ember app won't load, throwing an error that a particular module is not found. This is how I am doing the restore part with the Storing a reference in a namespace for Ember and require.entriesfunction unmount(opts) {
return Promise
.resolve()
.then(() => {
opts.applicationInstance.destroy();
opts.applicationInstance = null;
// Create a namespace in window object for the desk mfe
window.dcx.desk = window.dcx.desk || {};
// Store the Ember and require.entries into the same
window.dcx.desk = {
Ember: window.Ember,
entries: window.require.entries
}
// delete the current Ember object (may be not required I am not sure)
delete window.Ember;
});
} And during the function mount(opts) {
return Promise
.resolve()
.then(() => {
// First time there will be no namespace or find the existing name space
// dcx is the org and desk is the mfe
window.dcx.desk = window.dcx.desk || {};
// If there is an Ember object reference already stored, use that instead of the current window.Ember
// which may not be the right one
if(window.dcx.desk.Ember) {
const {Ember, entries} = window.dcx.desk;
window.Ember = Ember;
window.require.entries = entries;
}
opts.applicationInstance = opts.App.create(opts.createOpts);
})
} |
Thanks for the explanation. The single-spa-leaked-globals helper is designed to help with situations like these. A limitation of it is that the applications with global variable collisions cannot be mounted simultaneously. Is single-spa-leaked-globals enough to solve your issues here? Or is it more complex? |
single-spa-leaked-globals is really helpful to solve the global Ember object problem, but still I think there are some more complexity involved. I think the only option we now has to refresh the page for every Ember micro-frontend to load the app properly. With client side navigation it is not working at the moment. I have reached out to the Ember community for more help. Thanks a lot @joeldenning |
What are the other complexities? From your message it seems that storing the Ember and require.entries global variables would be enough? |
Even if we have populated the require.entries list with the respective modules for the current mfe, Ember is throwing error on
When it tries to redefine the |
Continuing the discussion with #3, I am able to somewhat bypass that with this hacky solution. But needed a better approach or refined one with the official library itself:
Still I am getting error when switching back to different Ember apps something like:
@joeldenning Please let me know your thoughts on this.
The text was updated successfully, but these errors were encountered: