reduxjs / redux-toolkit

The official, opinionated, batteries-included toolset for efficient Redux development
https://redux-toolkit.js.org
MIT License
10.64k stars 1.15k forks source link

Mutation get stuck in pending state #4447

Open LucasHimelfarb opened 3 months ago

LucasHimelfarb commented 3 months ago

In my React Native application, I implement React Navigation and have two stack navigators... After replacing one with the other, a screen is rendered that will make two requests using RTK Query. The first is a simple query to obtain some authorization tokens, which resolves without any issues. The second is a mutation that implements a queryFn...

Screenshot 2024-06-06 at 2 17 26 PM

and those queries called in my screen:

Screenshot 2024-06-06 at 2 19 10 PM

But the getCredits mutation never resolve with success even if the requests defined in queryFn was resolved, the data value is unfilled in the screen side and the flag isLoading is always true.

All works fine when the replace of stack navigators never happens

phryneas commented 3 months ago

I fear this is way too specific for any of us to reproduce and look at - if you can build some more generic reproduction that we can actually run, we could take a look, but like this I'm not sure we can help you, sorry :/

LucasHimelfarb commented 3 months ago

@phryneas It s a company project so is hard to share a reproducible case for u. But I swear my implementation is so simple like that. May be is useful look my root navigator:

Screenshot 2024-06-06 at 5 34 21 PM
LucasHimelfarb commented 3 months ago

@phryneas and funny fact: if I remove all code lines on queryFn and just return an empty array the problem persist

aryaemami59 commented 3 months ago

Can you tell us what version of Redux-toolkit, React-Redux, React-Native and React you're running? Maybe that'll give some sort of clue as to where the issue is coming from.

LucasHimelfarb commented 3 months ago

@aryaemami59 of course...

"@reduxjs/toolkit": "2.2.5"
"react-redux": "9.1.0",
"react-native": "0.73.5",
"react": "18.2.0",
LucasHimelfarb commented 3 months ago

after many hours trying different approaches I can't get it... I think it is a bug related between RTKQuery and react-navigation/native

aryaemami59 commented 3 months ago

@LucasHimelfarb Can you add this to your package.json's dependencies and try again?

"@reduxjs/toolkit": "https://pkg.csb.dev/reduxjs/redux-toolkit/commit/d86ec94b/@reduxjs/toolkit",
LucasHimelfarb commented 3 months ago

Thanks for u suggest @aryaemami59

Getting the same behavior :/

aryaemami59 commented 3 months ago

@LucasHimelfarb this is a longshot, but can you also try with the most recent React-Redux version?

LucasHimelfarb commented 3 months ago

@aryaemami59 I tried it together with the last thing you shared with me and with the latest version of react-redux (9.1.2) and I get the same behavior

aryaemami59 commented 3 months ago

@LucasHimelfarb Then in that case, I think our best bet is if you put together a small repro, I understand it's probably time consuming, but it's very difficult to tell what's going on without having a sample of the problem to look at.

Almada2021 commented 3 months ago

Hello when a navigator stack is replaced, is it possible that the mutation state is lost or reset ?

LucasHimelfarb commented 3 months ago

@aryaemami59 In this week I can't build a repo to reproduce the error because my job... but I'll try to do it on the weekend.... @Almada2021 I think no, I don't see any repeat log or actions dispatched twice

aryaemami59 commented 2 months ago

@LucasHimelfarb Awesome. Let me know when you do so I can take a look.

teaglebuilt commented 2 months ago

I am facing this same issue. I will also note that uninitialized is true. @LucasHimelfarb if you console.log isUninitialized, is it true? You can export if from your mutation dict along with isLoading, isError, etc...

david10sing commented 2 months ago

Might this be related? I would try rolling back to v2.2.3 to confirm that v2.2.4 changes is the cause if the issue here.

https://github.com/reduxjs/redux-toolkit/issues/4449

LucasHimelfarb commented 2 months ago

@aryaemami59 new update: this happened only with queryFn thats not return a string as a data

aryaemami59 commented 2 months ago

@LucasHimelfarb sorry you said this only happens if queryFn returns something other than a string? Do you have a small example or maybe even a code snippet? I can take a closer look, I just need to know what to look for.