Skip to content
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 runtime loaded #42

Closed
smelukov opened this issue Aug 9, 2024 · 15 comments
Closed

Multiple runtime loaded #42

smelukov opened this issue Aug 9, 2024 · 15 comments

Comments

@smelukov
Copy link
Contributor

smelukov commented Aug 9, 2024

Just use one https://github.com/module-federation/vite/tree/new-config/examples/vite as a host and one another as a remote. In this case, the module federation runtime chunk is loaded multiple times. Sometimes this leads to a race condition and error with the message "Call init first". If we have 10 vite remotes, then 10 runtime chunks will be loaded.
We need to load and use only one runtime, especially if we use different bundlers (e.g. webpack host, 2 vite remotes, 3 webpack remotes).

@zhangHongEn

image

@smelukov smelukov changed the title Multiple runtime Multiple runtime loaded Aug 9, 2024
@gioboa
Copy link
Collaborator

gioboa commented Aug 9, 2024

Thanks @smelukov for your feedback. Are you using the latest alpha version?

@smelukov
Copy link
Contributor Author

smelukov commented Aug 9, 2024

Are you using the latest alpha version?

yes

@zhangHongEn
Copy link
Contributor

zhangHongEn commented Aug 9, 2024

#39 Let me solve this more serious problem first, and then look at this。

@smelukov Does the "Call init first" error appear randomly after multiple refreshes, or does it appear once every time you start dev for the first time and disappear after a refresh?

@smelukov
Copy link
Contributor Author

@zhangHongEn It seems like "Call init first" appears on the first refresh after the build has started

@zhangHongEn
Copy link
Contributor

zhangHongEn commented Aug 10, 2024

OK, the dynamic module has a minor flaw when building in vite dev. You need to initiate a request first, that is, refresh the page once and it will be normal.
This does not affect build mode. Dev mode needs to refresh the page once, and the repair may be delayed in the future.

@zhangHongEn
Copy link
Contributor

Just use one https://github.com/module-federation/vite/tree/new-config/examples/vite as a host and one another as a remote. In this case, the module federation runtime chunk is loaded multiple times. Sometimes this leads to a race condition and error with the message "Call init first". If we have 10 vite remotes, then 10 runtime chunks will be loaded. We need to load and use only one runtime, especially if we use different bundlers (e.g. webpack host, 2 vite remotes, 3 webpack remotes).

@zhangHongEn

image

If these two @module-federation_runtime.js are on different ports, it is normal

@smelukov
Copy link
Contributor Author

Yes, these are on different ports, but the mf-runtime should be a singleton, so multiple runtimes break this behaviour. Isn't it?

@zhangHongEn
Copy link
Contributor

zhangHongEn commented Aug 10, 2024

@smelukov The only object that must be a singleton is the "shared" object. The host is the only one that will create the "shared" object, and the other remotes will receive it when they enter the init parameter.

async function init(shared = {}) {

@zhangHongEn
Copy link
Contributor

zhangHongEn commented Aug 10, 2024

If mf-runtime is a single instance, all remote modules' mf-runtime will be forced to use the host. It is possible that the remote uses a higher version of the mf-runtime api (such as runtime api), but the host mf-runtime version is too low. Therefore, mf-runtime is generally multi-instance.

@husayt
Copy link
Contributor

husayt commented Aug 11, 2024

I get this "Please call init first" error with latest 1.0.0-alpha-4a73cd4 all the time now. Even examples don't work anymore

@zhangHongEn
Copy link
Contributor

@husayt I'm not sure if the new pre-bunding shared solution is not compatible with Windows, because I can't reproduce it. Let me check it out.

@husayt
Copy link
Contributor

husayt commented Aug 11, 2024

@husayt I'm not sure if the new pre-bunding shared solution is not compatible with Windows, because I can't reproduce it. Let me check it out.

let me know if you need any more details from me. but latest cut breaks both host and remote for me. i have spend whole night trying to make it work

@zhangHongEn
Copy link
Contributor

@husayt Windows issues fixed

@husayt
Copy link
Contributor

husayt commented Aug 11, 2024

@zhangHongEn it indeed works finally. This is great. Thank you. @gioboa can we get it approved please.

Also, while you are on it I raised a PR with updated examples and dependencies
#50

@zhangHongEn one key problem (you can see in my examples) there is that seems images are not properly imported. I added an example of SASS with image background. When you run standalone remote it shows dark background, but when run from inside host it doesn't show image

@gioboa
Copy link
Collaborator

gioboa commented Aug 11, 2024

Closed by #48

@gioboa gioboa closed this as completed Aug 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants