-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
RTKQ: Mutation gets stuck in 'Pending' despite rejection from the server. #1376
Comments
Could you try to create a reproduction for this? |
Thank you so much for such awesome package. I have used it inside my current app and I am literally enjoying this . One thing, I have been struggling with is the Pending state of mutation. I have a scenario where I have been using RTK mutation to fetch data from server on demand. However, when ever I get a 500 error, it gets logged to my middleware
but, the mutation is always in Pending state, not even giving any error state. As for now, I can see, that I will have to switch to the asyncThunk logic, and managing the state manually. Can you please provide me some reference to manually trigger the rejection of mutation. So, I can get through it. Thanks |
this applies here as well. without any code showing this in a reproducable way I have no idea what is going on. |
Thank you so much for such quick response. I have managed to resolve this issue by using custom base query (Axios Base query). This is how, I have achieved this,
Thank you |
@rana944 I need a CodeSandbox, git repository or something else that shows me the problem, not the workaround. But without a reproduction I have no idea what to look for. |
Hi, I'm currently facing the similar issue and have a reproducible repo here: https://github.com/polaroidkidd/librephotos-frontend/tree/feat/migrate-ts--auth-state I defined the request here and I'm using it on the signup page here. The successful query goes through as advertised, but when I try to sign up with the same user name twice, the api correctly returns 400 correctly and the rejected response is logged out here, but the status remains To get talking to the api you'd have to clone https://github.com/LibrePhotos/librephotos-docker, rename I'm fairly sure I've misconfigured something here somehwere since RTK-Query is still new to me, but seeing as there's already a ticket for it and you mention needing a reproducible example, I thought I'd throw my hat in the ring. |
I did some further digging and found a bug in my zod declarations, which stopped the mutation from entering the fulfilled state. It wasn't related to this after all. |
Got the same issue when i use GET request with Lazy Query and got 500 error from server, status stacked in "Pending" position... |
@nofear144 I can only quote myself from this issue:
|
Got the same issue when I use POST request and got success status from the server but the status was stuck in the "Pending" position. |
Cool. Because obviously we have never encountered this. We cannot help you otherwise. |
Thank you so much for your quick response! I am calling a POST API twice in a component using mutation |
I need a reproduction with code that I can run on my machine and see it for myself. That could be a GitHub repo, a CodeSandbix or a Replay recording. |
Same problem. I know that you're looking for a snippet to reproduce the error. But actually it seems to be random (I tried to create a code sandbox for you but the error disappeared there..) Till now, I've tried to change the API endpoint name and the tag and the issues seems to disappear for a while, but after some time it appears again. Could be something related to the cache? |
@v-x2 I really can't tell. I'd at least need a replay recording of this happening once. |
I encountered a similar problem, but it was probably just misusage from my side. For me the request kept hanging as pending because I had a request argument that depended on the current time, which of course changed with every execution. Something like this:
I resolved this by using the current date without time as a reference point, so If it is helpful to you, I can set up a repository reproducing this behavior as soon as I have the time. |
@dominikberse no need for a repo, that's really just misuse and nothing we could debug or fix on our side (as it could be intended just as well). But thanks a lot for sharing, maybe it helps someone here! |
i encountered similar issues but after removing the middleware am using, it worked as expected. /** Log a warning and show a notification! **/ |
@Geemarn yes, that middleware will stop the actions from ever reaching the reducer. /** Log a warning and show a notification! **/
const rtkQuerySuccessLogger =
(api: MiddlewareAPI) => (next: any) => (action: { meta: { arg: { type: string } } }) => {
if (isFulfilled(action)) {
if (action.meta.arg.type === 'mutation') {
+ next(action)
return message.success('Action Successful!');
}
}
return next(action);
}; You always have to call Generally I'd recommend you look at the Listener Middleware for something like that |
yeah, thanks..just observed it now |
I have the same issue and provide a codeSandBox for you guys. but I'm not sure if you can actually make a request to my server feel free to check out the code. |
@Abolfazl2647 your code just makes a new request every time the component rerenders. Every time the component rerenders, |
@phryneas thank you, I should see that sooner. |
codeSandBoxExample |
@axinvd : yeah, that's to be expected. If an error is thrown in the reducer, then the state never actually gets updated. |
i am getting the same error in Post Mutation , but the Args i passed is Successfully originated inside originalArgs!! what should i do now
//mutation code eventUser: builder.mutation({ originalArgs : 39 //response args
|
Hello! Why this issue is closed and how did you resolve this? |
@azad-source as you can read here, they had manual code in a reducer that was erroring. You likely have a different problem. Please open a new issue and provide a reproduction or a replay recording of the problem. |
@phryneas thanks! I'll try to hide my reducer's slice and I'll check if the problem goes away or not. May be I have the same reason. :) |
Hello everyone, I ran into this problem because I was doing a mutation call into a popup react component that is unmounted just after the mutation call :
Adding 'await' before the mutation call helps resolve this because the "res" variable is updated before the component is unmounted:
Hope it'll help someone :) |
Hi. I have same issue with ZOD & RTKQ. Can u explain how to resolve this? |
solved :) |
Hi,
On multiple places, since I've updated our package the mutation is stuck on 'Pending' even when an error is thrown.
See screenshot and code below.
The server returns 422, but the mutation doesn't get rejected.
It works with fulfilled mutation, but not rejected ones.
I have the issue in multiple places in my codebase and had to revert back to handling the state manually.
Any clues?
Thank you!
The text was updated successfully, but these errors were encountered: