Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

commit is fired multiple times if other actions are dispatched during request #23

Closed
benvp opened this issue Mar 29, 2017 · 5 comments
Closed
Labels
Milestone

Comments

@benvp
Copy link
Contributor

benvp commented Mar 29, 2017

Following scenario (react-native, should apply to web, too):

During component mounting, I dispatch an action to be picked up by redux-offline. During the time the request is made, I dispatch some other actions, which should not be handled by redux-offline. However, these actions will be picked up by the middleware and will end in calling the commit handler multiple times for the amount of times of the actions, which have been dispatched during the time the request is made (or during the time the effect waits for promise resolve).

I hope you understand what I mean, it's not that simple to describe. My proposed solution to this would be to check in the middleware if an meta.offline key is present, otherwise just ignore the action.

What do you think?

@benvp benvp changed the title commit is fired multiple times if other actions are dispatched commit is fired multiple times if other actions are dispatched during request Mar 29, 2017
@jevakallio jevakallio added the bug label Mar 30, 2017
benvp pushed a commit to benvp/redux-offline that referenced this issue Apr 3, 2017
@benvp
Copy link
Contributor Author

benvp commented Apr 12, 2017

@jevakallio any ideas on this? This is making me a lot of trouble and I don't know how to get around this issue. Every time I dispatch some UI specific actions immediately after dispatching an action with an offline key, the reconciler is fired multiple times therefore creating duplicated entities in my backend.

Any idea how to solve it which points me into the right direction would be great and I'll submit another PR.

benvp pushed a commit to benvp/redux-offline that referenced this issue Apr 12, 2017
@dabit1
Copy link
Contributor

dabit1 commented Apr 13, 2017

I have the same problem. When my app starts dispatch an action that does not have meta and another that has meta, and the action with meta is dispatched twice. In my case, "persist/REHYDRATE" action causes that the action with meta be dispatched twice.

jevakallio added a commit that referenced this issue Apr 14, 2017
@jevakallio jevakallio added this to the v1.1.0 milestone Apr 14, 2017
@Noitidart
Copy link

I am still having this problem.

I am using redux thunk.

function push() {
    return (dispatch, getState) => {

        ////// start first dispatch
        dispatch({
            type: 'PUSH',
        })
        ////// start first dispatch

        ////// start second dispatch
        dispatch(apiCall(id));
        ////// end second dispatch
    }
}

function apiCall() {
    return (dispatch, getState) => {
        // this is really where second dispatch happens
        dispatch({
            type: 'API_CALL',
            meta: {
                offline: {
                    effect: getEffect(),
                    commit: { type:'API_DONE' },
                    rollback: { type:'API_FAIL' }
                }
            }
        })
        // end really dispatch second
    }
}

It seems if I dispatch a

sorodrigo added a commit to wacii/redux-offline that referenced this issue Sep 19, 2017
@bendelonlee
Copy link

bendelonlee commented Dec 21, 2020

Seem to be having a similar issue, using version 2.6.0

@sorodrigo
Copy link
Member

sorodrigo commented Jan 4, 2021

This is strange it shouldve been fixed a while back, could you share more info? Maybe a reproduction of the bug or a screenshot of the devtools logs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants