Sometimes invalidate not work...
hello sometimes invalidate method does not work in
onSuccess
anyone same?
using NextJS, pnpm18 Replies
Im having this problem aswell, @melodyclue have you found a solution?
well, The problem is solved by writing an invalidate directly after the asynchronous process, instead of "onSuccess". We do not know why "onSuccess" does not work. In some cases it works, so I am confused.
are you still invalidating through useContext? but just after the async
yes I use
```
const utils = trpc.useContext()
...
onSuccess() {
utils. .... .invalidate()
}
Ahh, in my case onSuccess works all the time, but the utils...invalidate() doesnt.
How did you solve this?
cc @melodyclue
@David In fact, it has not been resolved.
It seems that invalidating within onSuccess does not execute. However, there are some that are executed and I am confused.
For now, directly in the function
await utils.project.getProject.invalidate({ project_id: projectId });
in the function for example, it seems to be executed.
Damn that is rough, thanks for the quick response!
A follow up question, do you happen to have 2
QueryClientProvider
s in your tree?@David 🧐 no, I dont use QueryClientProviders. instead I use
export default trpc.withTRPC(App)
I figured, thanks for the info!
It seems that doing this:
@David so useQueryClient is the key to solve this problrem? I will try !
Bit of a workaround
I had 2 queryClient providers thats why mine wasnt working 👍🏽
@David oh you are talking about v9. mine is v10 actually...
Nope, talking about v10 but later realized that also is not consistent it seems
@David I think
await queryClient.invalidateQueries(getQueryKey(trpc.path.to.query))
is the way how it works on v9 🤔It's just one of the standard react-query ways to do it
@David ok figured out! you're right David.
And this issue (invalidate not works) is fully resolved !!!
https://trpc.io/docs/client/react/getQueryKey
getQueryKey | tRPC
We provide a getQueryKey helper that accepts a router or procedure so that you can easily provide the native function the correct query key.