Code Monkey home page Code Monkey logo

Comments (8)

SantoJambit avatar SantoJambit commented on May 19, 2024 2

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.

abettadapur avatar abettadapur commented on May 19, 2024 2

Published 5.0.2

from redux-dynamic-modules.

navneet-g avatar navneet-g commented on May 19, 2024

Thanks @colindcampbell , can you share a codesandbox with minimal repro?

from redux-dynamic-modules.

colindcampbell avatar colindcampbell commented on May 19, 2024

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.

colindcampbell avatar colindcampbell commented on May 19, 2024

@navneet-g Have you had any chance to look into this? Thanks

from redux-dynamic-modules.

navneet-g avatar navneet-g commented on May 19, 2024

@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.

chris-nolan avatar chris-nolan commented on May 19, 2024

@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.

navneet-g avatar navneet-g commented on May 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.