vite-plugin-federation icon indicating copy to clipboard operation
vite-plugin-federation copied to clipboard

Dev mode in the host

Open norman-ags opened this issue 1 year ago • 11 comments

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.

norman-ags avatar May 03 '23 11:05 norman-ags

@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.

mjangir avatar May 22 '23 12:05 mjangir

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

maxdreisbusch avatar May 24 '23 08:05 maxdreisbusch

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

norman-ags avatar May 24 '23 12:05 norman-ags

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

lasharela avatar May 24 '23 20:05 lasharela

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 avatar May 27 '23 01:05 ruleeeer

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 avatar May 27 '23 07:05 ruleeeer

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

ruleeeer avatar May 27 '23 07:05 ruleeeer

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

philals avatar May 31 '23 18:05 philals

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.

sayeed0209 avatar Apr 18 '24 15:04 sayeed0209

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

CosmeValera avatar May 30 '24 08:05 CosmeValera

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?

Waqqars987 avatar Jul 23 '24 10:07 Waqqars987