-
-
Notifications
You must be signed in to change notification settings - Fork 461
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
Optimistic responses and data invalidation not working as expected #1653
Comments
When you invalidate you delete data from the cache; hence an optimistic mutation can never invalidate data eagerly and expect a cached response for this data. Furthermore when the UI doesn't reflect the changes you've made then that means it's being forced to wait for the mutation to complete and it being able to send a request to the API because some of your data is missing. Most recent discussion with info on this is this one: #1645 Edit: Also I spotted another small thing. Invalidating is an explicit call to delete and invalidate data, like is said, and I spotted that you expect
|
I'm not sure I understand all the implication of your explanation.
Actually, the data of my My
I'm trying to imagine what's going on here :
Does it seem like that's what's going on ?
No, I actually expect project to never be null, as specified in the schema.
But why is it, then ? |
urql version & exchanges: 2.0.1, graphcache 4.0.0
I'm having two issues with optimistic responses and data invalidation. I don't know if they are related. To set up the stage, imagine having the following very simplified schema :
A contradiction is part of a project, and can be edited via
Mutation.editContradiction
. A project can be retrieved viaQuery.project
.Let's add the following (also very simplified) Urql client :
Here are my issues :
When I trigger
editContradiction
two times in a row, with the second one being triggered before the first had a chance to return from the server, the optimistic update is not applied for that second one. The UI is just frozen after that second trigger until the mutation actually completes.When invalidating the contradiction's
Project
inupdates
as shown in the code snippet above, the second trigger ofeditContradiction
causes myproject
data (from auseQuery
onQuery.project
) to be set tonull
for a brief period of time until it's refetched. This seems to happen after the first call ofeditContradiction
returned from the server although I'm not 100% sure. If I wait for eacheditContradiction
to finish and forQuery.project
to be called again as a result of the invalidation before calling anothereditContradiction
,Query.project
is never set tonull
. I absolutely don't know what's going on here.My workaround for the first issue is to store the
contradiction
state in a React state that can be updated immediately, and calleditContradiction
without an optimistic response as a side effect of those React state updates.But I don't have a workaround for the second issue, which currently breaks the UI (because
Query.user
being null not only violates the typing generated by codegen (which only allows for the actual data orundefined
), it also triggers the rendering of a big loader that unmounts the whole project UI). This is a problem for all users clicking fast on mutation buttons while having a slow internet.Thanks in advance for your help.
The text was updated successfully, but these errors were encountered: