Comments (8)
We're having the issue as well. Not sure if the code by @denisborovnev fixes this entirely, as I tried patching the node_modules file and it didn't seem to work, but maybe I made a mistake.
Our current workaround is like this:
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Connect, connect } from 'react-redux';
import { ISagaModule } from 'redux-dynamic-modules-saga';
export function moduleConnect(module: ISagaModule<any>) {
const keys = module.reducerMap ? Object.keys(module.reducerMap) : [];
const connect2: Connect = (...args: any[]) => {
const newArgs = args.map((arg, index) => {
if (index === 0) {
return (...args2: any) => {
if (keys.every(key => !!args2[0][key])) {
return arg(...args2);
}
return {};
};
}
return arg;
});
// @ts-ignore
return connect(...newArgs);
};
return connect2;
}
// Elsewhere:
export default moduleConnect(myModule())(mapStateToProps)(MyComponent);
What this does (in a hacky way):
It wraps the mapStateToProps with a function that first checks if all keys in reducerMap are present and if not, it returns an empty object. Since the component itself is never rendered with this value, it should never be an issue (mapStateToProps gets called, but the result of it is never used).
Hoping for an official fix, so we can remove this hack.
Thanks for the great work btw, we love redux-dynamic-modules!
from redux-dynamic-modules.
Published 5.0.2
from redux-dynamic-modules.
Thanks @colindcampbell , can you share a codesandbox with minimal repro?
from redux-dynamic-modules.
Thanks for getting back. Here is the issue reproduced.
https://codesandbox.io/s/reactredux-uv4xm
The issue arises when you click the Page 2 link from Page 1. Both pages load fine individually and there is no issue going from Page 2 to Page 1
from redux-dynamic-modules.
@navneet-g Have you had any chance to look into this? Thanks
from redux-dynamic-modules.
@colindcampbell sorry I could not look at it as a bit busy in my day job. I will take a look but no promise. Can you upgrade to latest 4.x version and see if this still repros?
from redux-dynamic-modules.
@navneet-g I'm also seeing this. I'm not familiar enough with the code base but it looks like the DynamicModuleLoader might be unmounting before the child component (based on componentWillUnmount on the DML removing the modules which removes the state?), but I don't know if that is even possible. I'm using the saga extension; not sure if that is relevant but I didn't have this problem when using thunks....
Edit: having done a bit of reading I'm not sure this is entirely fixable as mapStateToProps will be called on any state change even when the connected component is unmounting (is my limited understanding!). I've fixed this by guarding my selectors to check for the existence of the correct 'tree' in the state and returning a dummy value if not.
from redux-dynamic-modules.
Thanks @zulu134 the state removal from the tree should be the very last thing happens, and by this time any children of DML should be already unmounted. Would you mind debugging and checking who is calling mapStateToProps after DML is unmounted?
from redux-dynamic-modules.
Related Issues (20)
- Is it possible to shave off React+ dependencies? HOT 1
- Could it be possible to provide simple Lit Element (Web Components) example
- support for nested reducers HOT 4
- Typing initialActions function
- [Examples] There is no 'enhancements' property
- [Examples] Unused argument 'getState'
- State and reducers are not removed when dynamic component unmounts HOT 2
- PENDING action is gone from sagas HOT 6
- remain module when component unmount HOT 2
- State lost, when moving from one module to another module HOT 1
- Remove module by id HOT 1
- modules are removed before useEffect cleanups are executed
- Update with React 16.x or 17.x
- takexxx saga(saga watched action) in different modules that have been loaded doesn't work in dynamic modules HOT 1
- Build pipeline failing for main
- Library abandoned? HOT 2
- TypeScript React: incorrect children props HOT 3
- This repo is missing important files HOT 3
- Module '"redux-dynamic-modules"' has no exported member 'IModule'.
- Any way to use the redux-toolkit with this lib? I have a code sample in the description..
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redux-dynamic-modules.