GuillaumeCisco / redux-reducers-injector

Dynamically inject reducers in your react reduc app. HMR and SSR compatible.
32 stars 6 forks source link

withInjectedReducers not working with Module Federation (still seeing previous state) #22

Open nkalinov opened 2 years ago

nkalinov commented 2 years ago

Hi and thank you for your contributions to the open-source community!

I've tried this lib with react-redux^7.2.8 + withInjectedReducers HOC from the README.md and it works great. Under Module Federation though the same code doesn't work - the getState() call in withInjectedReducers is still seeing the previous state. I have a console.log at inject time and it's injected before the rendering occurs but still in the HOC injectedReducers doesn't have the newly added one. To note that I'm trying to import a lazy local file (not from a federated module!).

I've read https://github.com/reduxjs/react-redux/issues/1126 but I am out of ideas why that might occur. @ephem's solution is a bit different and it works I guess because the new slice is generated just in time instead of relying on getState() but I don't want to attach my reducers (or ducks) to a specific component but rather inject them at import time.

Any help appreciated.

GuillaumeCisco commented 2 years ago

Hello,

Ah this repository brings back memory. Currently I don't have much time to work on it. But back in the days, before all this mess about hooks, things were far easier.

I would need to dig a lot in the new code to understand what is going on.

Can you provide me some links about Module Federation please? I will have a quick look.

nkalinov commented 2 years ago

You can find plenty of info on Module Federation on internet. Otherwise here is a link to a concrete implementation by its initial creator: https://github.com/module-federation/module-federation-examples/tree/master/redux-reducer-injection but I don't (or didn't) want to inject my store as a prop. I think I'll go with this implementation though so feel free to close this issue if you feel like it.