ghard1314
ghard1314
TtRPC
Created by cugs on 11/19/2023 in #❓-help
Multiple optimistic updates and old data from refetches
I think you were originally right about cancel stopping refetches from invalidate but thats not really helping you here when you have back to back mutations. Lets look at a quick timeline of whats happening here when you make 2 back to back delete mutations before the first one settles.
onMutate(exercise 1):
client -> server: delete exercise
client -> server: cancel all previous "all" queries (none happening right now)
client -> client: remove deleted exercise from cache // cache is now correct without exercise 1
onMutate(exercise 2):
client -> server: delete exercise
client -> server: cancel all previous "all" queries // still none happening here because exercise 1 hasn't settled yet
client -> client: remove deleted exercise from cache // cache is now correct without exercise 2
onSettled(exercise 1):
client -> server: cancel all previous "all" queries // still none happening here because exercise 2 hasn't settled yet
client -> server: get all exercises (invalidate) // this will return exercise list with exercise 2 still in it since second mutation hasnt settled yet <-----
onSettled(exercise 2):
client -> server: cancel all previous "all" queries // still none happening here because exercise 1 already finished settling
client -> server: get all exercises (invalidate) // this will return exercise list without exercise 1 or 2
onMutate(exercise 1):
client -> server: delete exercise
client -> server: cancel all previous "all" queries (none happening right now)
client -> client: remove deleted exercise from cache // cache is now correct without exercise 1
onMutate(exercise 2):
client -> server: delete exercise
client -> server: cancel all previous "all" queries // still none happening here because exercise 1 hasn't settled yet
client -> client: remove deleted exercise from cache // cache is now correct without exercise 2
onSettled(exercise 1):
client -> server: cancel all previous "all" queries // still none happening here because exercise 2 hasn't settled yet
client -> server: get all exercises (invalidate) // this will return exercise list with exercise 2 still in it since second mutation hasnt settled yet <-----
onSettled(exercise 2):
client -> server: cancel all previous "all" queries // still none happening here because exercise 1 already finished settling
client -> server: get all exercises (invalidate) // this will return exercise list without exercise 1 or 2
8 replies
TtRPC
Created by Nicolas on 11/17/2023 in #❓-help
Creating inner context for AWS Lambda Context Options
Also I dont think you should call one route from another. You should abstract out whatever logic you want to call into a separate function and call it directly from the server
5 replies
TtRPC
Created by Nicolas on 11/17/2023 in #❓-help
Creating inner context for AWS Lambda Context Options
If your goal is to tell if a user is present or not, you should do this through middleware. Here are the docs you want for this probabily https://trpc.io/docs/server/server-side-calls
5 replies
TtRPC
Created by cugs on 11/19/2023 in #❓-help
Multiple optimistic updates and old data from refetches
Another idea would be to put the refetch on a debounce that gets renewed anytime another delete action is taken. This way you still get fresh data eventually that should match your local cache, but it wont override many fast changes
8 replies
TtRPC
Created by cugs on 11/19/2023 in #❓-help
Multiple optimistic updates and old data from refetches
When you call invalidate that triggers a refetch from the server which is going to override any optimistic updates you made to your cache like you are seeing. There may be some ways to make this play nicely with your existing optimistic update, but my question is: do you really need to refetch data? Unless your expecting this data to change from another source beside this users interactions, there shouldnt really be a need to get fresh data from the server right?
8 replies