Pinia with microfrontends #1968
Replies: 5 comments
-
are you trying to access state from one apps to another apps? i think thats not possible since pinia only work within an apps |
Beta Was this translation helpful? Give feedback.
-
did you fix it? |
Beta Was this translation helpful? Give feedback.
-
You seem to have multiple instances of the library pinia being used. Make sure vue, pinia, and other libraries are not inlined in your final bundles so they don't get duplicated |
Beta Was this translation helpful? Give feedback.
-
In the same app, components share state by referring to the same Pinia instance, which is registered during the initialization of the Vue app. However, an error occurs in a micro-frontend (MF) setup when you attempt to share the Pinia state across multiple apps. A potential solution is to manually pass your Pinia instance into the hook, like this: const shareStore = useShareStore(pinia) I’m currently using this approach. While it feels a bit unconventional to me, I haven’t noticed any issues so far. I’d love to hear your thoughts or suggestions for improvement! |
Beta Was this translation helpful? Give feedback.
-
This is an old question and it mentions webpack. Currently we have module federation for vite and it is based on MF2 which is bundler agnostic. So if you are using Pinia with MF would be best to share the same instance of pinia across all remotes. This is the very thing MF can help you with, just declare pinia a shared singleton see here |
Beta Was this translation helpful? Give feedback.
-
How Pinia store should be implemented for microfrontends using ModuleFederationPlugin with webpack? Pinia works separetly in both apps but when I run wrapper with micro frontend inside I have below error and component inside is not rendered:
I tried multiple times but I failed anyway. I need some guidance how to fix it.
Beta Was this translation helpful? Give feedback.
All reactions