Comments (16)
@anilanar thanks for reporting, Can you give a codesandbox with repro?
from redux-dynamic-modules.
https://codesandbox.io/s/8kx2jr7762
This behaviour is expected. If you do the following, Comp
will mount twice because React re-creates the whole element tree if the root's type is different than before.
let count = 0;
const App = () => (
if (count++) return <div><Comp /></div>;
else return <Comp />;
);
from redux-dynamic-modules.
Sorry I didn't get a chance to look at it yet. I will take a look this week and get back to you.
from redux-dynamic-modules.
@anilanar I am not able to open the sandbox, I get following error. I will try again later today
from redux-dynamic-modules.
Perhaps codesandbox had problems when you tried it, I can open it.
from redux-dynamic-modules.
I can repro this and this is what I see, the storeState changes and thus React rerenders children
We need to debug more to see why the storeState is not upto date in first render after the module is loaded. Most probabbly this is another side effect of React's new context API, but for sure this is not a bug in redux-dynamic-modules
. It takes a long time to debug react, I will give it a try later in the week if I get sometime.
from redux-dynamic-modules.
I have this trouble too. This issue blocks releasing our app (
from redux-dynamic-modules.
@navneet-g State not being up to date after store is updated (by redux-dynamic-modules
) is not a bug in redux-dynamic-modules
. But using two different component roots (to overcome aforementioned problem) is a bug in redux-dynamic-modules
.
from redux-dynamic-modules.
@shockk in our app we are using following version of react-redux, and redux and don't see this issue. We are using it with React 16.8. Please try these versions for now to unblock the release.
react-redux": "^5.1.1",
"redux": "^4.0.0",
from redux-dynamic-modules.
@anilanar which two different component roots are you mentioning? Please elaborate.
from redux-dynamic-modules.
First the following:
and
_getLatestState
will be true on the first render and will be false on the second render. Thus, on the first render, it will render something like:
<ReactReduxContext.Provider ...>
{children}
</ReactReduxContext.Provider>
On the second render, it will just render the {children}
. Because the root of the component changes from ReactReduxContext.Provider
to children
's root component, whatever is inside {children}
will mount twice no matter what.
In my fork, I removed _getLatestState
and unconditionally call _renderWithReactReduxContext
which works for the first render and also for subsequent renders without a problem.
from redux-dynamic-modules.
Thanks @anilanar ... @abettadapur can you take a look?
from redux-dynamic-modules.
@anilanar @shockk Sorry for the delay here. Could you guys try this version of the package and let me know if you still have issues?
from redux-dynamic-modules.
@abettadapur It works. To understand the effects of strictMode
, I created the following sandbox with bunch of console.logs, checking state update order of connected components inside and outside DynamicModuleLoader
and also assigning ref
s to DynamicModuleLoader
's children from outside.
https://codesandbox.io/s/73r20x4jzj
I think there's a difference only when mounting and not during updates. strictMode
changes the order of state updates when mounting. When it's turned off, DynamicModuleLoader
s children's connected state updates before anyone else.
from redux-dynamic-modules.
correct, the only difference should be at mount time. I don't think we can get around this for strict
consumers. Thanks for verifying and the example!
@navneet-g Let's move to publish the new version
from redux-dynamic-modules.
Thanks @anilanar and @abettadapur .
@abettadapur I left a comment on your PR, let me know you want to address before merging or in a separate PR.
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.