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

Ref and reactive not working in vite federated module

Open Dorkside opened this issue 2 years ago • 29 comments

Versions

  • vite-plugin-federation: v1.1.14
  • vite: 4.0.4

Reproduction

Reproduction repo : https://github.com/Dorkside/ref-reactive-federated

Steps to reproduce

npm run build:test-vue npm run preview:test-vue npm run dev:ui

What is Expected?

Have the ref and reactive variables increment every second

What is actually happening?

The ref and reactive variables seem to have NO reactivity.

This might be a limitation of the plugin, but it would be greatly appreciated not having to store every variable in pinia.

Dorkside avatar Jan 24 '23 08:01 Dorkside

Could also reproduce the issue, reactive variables does not seem to work

T0miii avatar Jan 24 '23 10:01 T0miii

I'm willing to lend a hand on this, but feel a little lost as to where to start.

I have been experimenting with other solutions, and it seems that the same thing happens through exporting a Vue app as a lib, and importing it with Systemjs at runtime.

Dorkside avatar Jan 30 '23 10:01 Dorkside

I've updated my reference repo for this, and it seems that the loaded plugin through vite-plugin-federation has no reference to the getCurrentInstance and does not trigger the onMounted event for the component.

Dorkside avatar Jan 30 '23 10:01 Dorkside

I'm willing to lend a hand on this, but feel a little lost as to where to start.

I have been experimenting with other solutions, and it seems that the same thing happens through exporting a Vue app as a lib, and importing it with Systemjs at runtime.

i wonder if it has to do something with vite 4, or if its some Vue internal change, cause i can remember that both reactivity and css leaking was not a problem in a previous version.

I also started parsing the library , so i can understand more what we are talking about here.

T0miii avatar Jan 30 '23 12:01 T0miii

I have managed to reproduce the issue with vue-cli that relies on webpack under the hood. So it doesn't seem to be a vite issue.

Do you remember which version of Vue it used to work with ?

Dorkside avatar Jan 30 '23 16:01 Dorkside

The initial judgment is that it is caused by the failure of shared, which actually loads two vue instances

ruleeeer avatar Jan 31 '23 02:01 ruleeeer

That could be a reason, I had a few difficulties in my webpack attempt as well in an error along those lines : "Shared module is not available for eager consumption: webpack/sharing/consume/default/vue/vue" when adding vue as a shared dep.

Dorkside avatar Jan 31 '23 07:01 Dorkside

I've been seeing something similar and reproducible with my personal shared library that is no longer being shared between my remote apps and the host app anymore after the version update. When I downgrade to 1.1.13, the shared import code is generated and referenced in the federated files, but it does not look like the same is happening as of 1.1.14. I narrowed it down to it working after I revert the buildStart & outputOptions in shared-production.ts, but I don't grasp it well enough to further elaborate

i downloaded your repo and downgraded to 1.1.13 and the counter is incrementing again

liu351 avatar Feb 02 '23 03:02 liu351

I have just tested with 1.1.13 and the increment still doesn't work in the host app. Will try with a few versions and see if one of them solves the issue.

Dorkside avatar Feb 06 '23 10:02 Dorkside

Even 1.0.0 and 0.0.1 present the same issue.

Dorkside avatar Feb 06 '23 10:02 Dorkside

Even 1.0.0 and 0.0.1 present the same issue.

Maybe it's not reflecting the older package if you check package lock or node modules. I didn't change anything else in your repo when I tested it 🤷‍♂️

liu351 avatar Feb 06 '23 13:02 liu351

the PR is already up, just need to be reviewed what i can tell.

T0miii avatar Feb 06 '23 14:02 T0miii

Even 1.0.0 and 0.0.1 present the same issue.

Maybe it's not reflecting the older package if you check package lock or node modules. I didn't change anything else in your repo when I tested it 🤷‍♂️

Well I did delete my lock and node_modules each time... Not sure why it would not be updated in my env

Dorkside avatar Feb 06 '23 15:02 Dorkside

Even 1.0.0 and 0.0.1 present the same issue.

Maybe it's not reflecting the older package if you check package lock or node modules. I didn't change anything else in your repo when I tested it 🤷‍♂️

I'm wondering which app did you test ? With default settings, the remote app runs on port 4173, whereas the host app runs on 5173. There is no issue with the remote in standalone. The issue that I am still facing is in the host app on 5173 where the counter does not increment (though there is a log in the console on each tick).

Dorkside avatar Feb 07 '23 07:02 Dorkside

Even 1.0.0 and 0.0.1 present the same issue.

Maybe it's not reflecting the older package if you check package lock or node modules. I didn't change anything else in your repo when I tested it 🤷‍♂️

I'm wondering which app did you test ? With default settings, the remote app runs on port 4173, whereas the host app runs on 5173. There is no issue with the remote in standalone. The issue that I am still facing is in the host app on 5173 where the counter does not increment (though there is a log in the console on each tick).

Yeah that's weird. I hit the host running on 5173. I updated both the package.json with the below and reran npm install "@originjs/vite-plugin-federation": "1.1.13"

image

liu351 avatar Feb 08 '23 15:02 liu351

PR has merged, I`ll check the status of this issue later after new release.

ruleeeer avatar Feb 11 '23 03:02 ruleeeer

Dorkside/ref-reactive-federated works in version 1.2.0 on my machine

ruleeeer avatar Feb 11 '23 06:02 ruleeeer

Can confirm this solved the issue on a new computer. Will try again on my work computer monday ;-).

Dorkside avatar Feb 12 '23 08:02 Dorkside

Back on my work computer and this seems still not to be working. Wondering if there are any globally installed packages that could affect this ?

Dorkside avatar Feb 14 '23 08:02 Dorkside

OK, found that by using same domain on the module and on the host makes if functional (as opposed to localhost for the module and default 127.0.0.1 for the host).

Dorkside avatar Feb 14 '23 08:02 Dorkside

This is potentially a problem, at least in my setup, as even on localhost using different virtual hosts (one per microfrontend), reactivity isn't working. Anything I might have misonfigured ?

Dorkside avatar Feb 16 '23 09:02 Dorkside

Might be a CORS issue?

T0miii avatar Feb 16 '23 09:02 T0miii

Don't think so as that would appear in the network tab right ?

Also works fine outside of dev mode.

Dorkside avatar Feb 16 '23 09:02 Dorkside

Was there ever a resolution to this issue? I'm hitting problems atm with getCurrentInstance()

blakerunyon09 avatar Mar 15 '23 21:03 blakerunyon09

Don't think so as that would appear in the network tab right ?

Also works fine outside of dev mode.

This problem only occurs in the development mode, right?

ruleeeer avatar Mar 22 '23 08:03 ruleeeer

Was there ever a resolution to this issue? I'm hitting problems atm with getCurrentInstance()

What do you mean? Is the responsiveness not working or the problem of the host domain?

ruleeeer avatar Mar 22 '23 08:03 ruleeeer

No this isn't working through build mode either. I spent the better part of last week finding a work around getting the composition API working.

I finally realized if I just export the bootstrap file, and mount the app somewhere on the host, that seems to work. But there is for sure an issue in here around Vue 2.7

blakerunyon09 avatar Mar 22 '23 17:03 blakerunyon09

I also have the similar issue: my host app uses a remote component, the component loses its reactivity when my host app runs in dev mode. While I build and run my host app, everything works fine.

I think it has something to do with multiple vue instances because I get the error"Invalid vnode types Symbol()..."from console when running in dev mode.

I have already set the "shared" config in both host app and remote app, still not working.

rudecigarette avatar Apr 28 '23 03:04 rudecigarette

I ran into this issue. I found out that using run dev will not update ref in ui, but using preview does.

package.json

{
  "name": "reactive-ref-federated",
  "version": "1.0.0",
  "scripts": {
    "dev:ui": "npm run dev --workspace=ui",
    "build:ui": "npm run build --workspace=ui",
    "build:test-vue": "npm run build --workspace=test-vue",
    "preview:test-vue": "npm run preview --workspace=test-vue",
    "preview:ui": "npm run preview --workspace=ui"
  },
  "workspaces": [
    "packages/ui",
    "packages/test-vue"
  ]
}

Terminal 1

npm run build:test-vue && npm run preview:test-vue

Terminal 2

npm run build:ui && npm run preview:ui

TDAK1509 avatar May 23 '23 04:05 TDAK1509