-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Problems with optimisticResponse and reducer updating a list query #1100
Comments
@codepunkt Thanks for the really thorough problem description! In short, what I read is that the following happens:
I'm not 100% sure about number 4. Does it stay in What you found sounds like it could be related to #1039, but in your case I'm 99% sure that the problem is due to some bug in Apollo Client. But just out of curiosity, could you try running your example with Is there any chance that you could make a small github repo with your reproduction? That would be super helpful, because I could then run it with a debugger and see what's really happening inside Apollo Client. |
@helfer Thanks for looking into this - very appreciated! It does not stay in Using You can find a repo with my reproduction at |
Couldn't solve this as of now. Anyone else got any ideas? |
Found the bug and I submit a PR to fix it. The PR explains the cause and solution: #1144 Haven’t addressed the tests yet, only got your failing case to work @codepunkt. May need to wait until next week to see this merged, but a solution is on the way 👍 |
I've tried to reduce my example to the minimum. Basically, i have this simple schema set up on the server side:
Item ids are auto-incremented integers. All items are displayed in a list, using the
item
query defined in the schema above to connect data. When theloading
field is set, a loader is displayed instead of the list. Also, a reducer is used to update the query result whenever a result fromaddItem
mutation is incoming:Right below the item list is a simple form used to add new items to the list. This
addItem
mutation invoked by this form is set up with anoptimisticReponse
that generates a temporary uuid as the items id (instead of the server generated auto-incrementing integers):To be able to test things out, i added an artificial delay of 5 seconds to the
addItem
mutation resolver on the server. When i add a single item, the optimisticResponse is immediately reflected in the item list and 5 seconds later, the server id replaces the generated temporary uuid.When i add another item while the first mutation is not resolved, things start going south. The list already has the (temporary optimisticResponse) first added item. Once the first mutation resolves, the list goes to a waiting state - and i don't know why.
I've added a short video of this with Apollo Dev Tools opened so you can follow my writings. Whatever happens triggers the
loading
field. In the store, the temporary item is replaced with the server-approved item once the mutation is resolved, but the ROOT_QUERY, which is inspected in the dev tools, somehow retains the old temporary item until all stacked/paralleloptimisticResponse
mutations are resolved. This is reproducible with more than 2 mutations in parallel aswell.Why? What i would've expected is each item being added to the list immediately in its temporary
optimisticResponse
version and being replaced after 5 seconds when the server resolved the mutation - not being affected by any other mutations.The text was updated successfully, but these errors were encountered: