Duplicate entries with optimistic mutations and subscriptions
See original GitHub issueWe have been trying to replicate the behaviour of the githunt sample implementing both optimistic updates and websocket subscriptions.
On some occasions, ie with a slow network, the order of the update changes and the store becomes corrupted and show duplicate entries. I could repro on githunt
Intended outcome:
No duplicate comments
Actual outcome:
Duplicate comments
How to reproduce the issue:
Go to http://www.githunt.com/, open chrome inspector and throttle network to Slow 3G
Submit a comment
In normal operations, the order of updates is optimistic mutation, real mutation, subscription. The problem happens when the subscription is triggered before the real mutation, ie: optimistic mutation, subscription, real mutation.
From what I can see, it’s related to the fact that subscribeToMore
’s updateQuery
is being passed the optimistic version of the query data, not the original.
Is there any reason for this? Retrieving the non optimistic with query solves the problem but I was not able to find a clean workaround.
Version
- apollo-client@2.2.5
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top GitHub Comments
I was still getting duplicates in the store in
v2.4.8
. It was not fixed bysubscribeToMore
’supdateQuery
having:It was fixed by the mutation
update
having:So the issue is closed now… what was the solution??