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

Dev mode in the host #410

Open
norman-ags opened this issue May 3, 2023 · 12 comments
Open

Dev mode in the host #410

norman-ags opened this issue May 3, 2023 · 12 comments
Labels
bug Something isn't working

Comments

@norman-ags
Copy link

Versions

  • vite-plugin-federation: 1.2.1
  • vite: 4.2.0

Hi! I'm trying to run this demo of Jack in dev mode: https://youtu.be/t-nchkL9yIg but it failed to work.

The readme of this project says:
Only the Host side supports dev mode, the Remote side requires the RemoteEntry.js package to be generated using vite build. This is because Vite Dev mode is Bundleless and you can use vite build --watch to achieve a hot update effect.

Reproduction

This repo from Jack
https://github.com/jherr/vite-mod-fed

Steps to reproduce

In the host:

  1. Run dev

In the remote:

  1. Run build
  2. Run preview

What is Expected?

Should not break the host app and the microfrontend should load.

What is actually happening?

From what I understand in the README, dev mode should work fine in the host, but I'm getting an error in the browser console:

Warning: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.

And the whole app breaks.

@mjangir
Copy link

mjangir commented May 22, 2023

@norman-ags Did you find a solution to this as I'm also having the same issue. One thing I noticed is, it is working fine in localhost but not in 127.0.0.1.

@maxdreisbusch
Copy link

@mjangir @norman-ags did you already find a solution?

@norman-ags
Copy link
Author

No. ATM it's fine for us to run all in preview. For dev mode, we run each microfrontend independently.

@lasharela
Copy link

this is weird. 127.0.0.1 is failing, localhost is working.

@ruleeeer
Copy link
Collaborator

I tried the latest version v1.2.3 and indeed encountered the issue. It works fine when I use localhost, but there are problems when I switch to 127.0.0.1.

@ruleeeer ruleeeer added the bug Something isn't working label May 27, 2023
@ruleeeer
Copy link
Collaborator

Tried it out and it's strange that when not using server:{host: 127.0.0.1} to bind the host to 127.0.0.1, accessing 127.0.0.1 directly will be refused.

@ruleeeer
Copy link
Collaborator

Dependent on this PR, both 127.0.0.1 and localhost can be used normally after configuring server:{host:127.0.0.1}. The latest Release does not yet contain this part of the code, which makes it impossible to use server:{host:127.0.0.1} directly even if it is configured 127.0.0.1 access

@philals
Copy link

philals commented May 31, 2023

For some reason I had server:{host:127.0.0.1} configured. Changing it to server:{host:"localhost"} fixed it. Thanks

@sayeed0209
Copy link

It would be immensely beneficial if we could resolve this issue, enabling real-time updates to be visible from the host when working with the MF architecture.

@CosmeValera
Copy link

It would be immensely beneficial if we could resolve this issue, enabling real-time updates to be visible from the host when working with the MF architecture.

That's exactly also what I want. The best I've been able to get is to have the vite build and preview in one command, to enable module federation, with this:

"preview:watch": "concurrently \"vite preview --port 4001 -l silent\" \"vite build --watch\""

But it does not have HMR, nor does it can have.

So there's where having the module federation vite plugin should allow to create the remoteEntry.js with dev mode would be really helpful. This way we could have HMR with VITE when using MF. Hopefully some day we will have it as an option to enable

@Waqqars987
Copy link

It would be immensely beneficial if we could resolve this issue, enabling real-time updates to be visible from the host when working with the MF architecture.

That's exactly also what I want. The best I've been able to get is to have the vite build and preview in one command, to enable module federation, with this:

"preview:watch": "concurrently \"vite preview --port 4001 -l silent\" \"vite build --watch\""

But it does not have HMR, nor does it can have.

So there's where having the module federation vite plugin should allow to create the remoteEntry.js with dev mode would be really helpful. This way we could have HMR with VITE when using MF. Hopefully some day we will have it as an option to enable

Somtimes, the preview command finishes ealier than the build watch command which fails the ouput of the preview command. Is there a way make the preview command run only after the build watch command?

@ApenasGabs
Copy link

Any temporary solution or workaround? I'm going through the same thing 🙁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

10 participants