T
TanStack2y ago
rising-crimson

Invalidate during an action()

If you have an action attached to a form, and you call invalidate and await that, the rest of the action never runs.
const myAction = action(async ()=>{
/// do something
await queryClient.invalidateQueries();

console.log("foo");
return redirect('/home');
}
const myAction = action(async ()=>{
/// do something
await queryClient.invalidateQueries();

console.log("foo");
return redirect('/home');
}
"foo" never logs and things just get stuck where they are. If I don't await it works, but I think that is just luck of timing. What is the real deal here?
1 Reply
rising-crimson
rising-crimsonOP2y ago
It looks like these are not async functions, and just use promise structure. Other than maybe the background fetching. So the invalidation marking is immediate, and if you don't await that is guaranteed to happen, yes? So the await which is locking up isn't neccessary as the refetch will happen later and in time for any consumer. correct? Nope, it does do a race and loses.

Did you find this page helpful?