-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Do optimistic updates respect array ordering? #1271
Comments
@rgovindji Can you share code of the mutation? Are you returning correct id of object that contains the list in optimistic update, so it knows which list to update? Wrong shape or missing id in optimistic update are my usual suspects for such behavior :-). |
Here's what I'm doing. The only ID I see on the array is a field named dataID is that what I'm supposed to add to the optimistic update?
|
@rgovindji I meant whole mutation, that could give more clues. I don't see any obvious issue with this.. |
On the other hand I have not used optimistic updates with connections, just lists. So wondering if its also important to copy edge cursors so it gets applied in store. |
@jardakotesovec Here's the whole mutation. I'll try adding the cursor for each edge in the response to see if that works.
|
I'd expect this to work, so the likely issue here is that your optimistic response isn't quite right. Relay applies the optimistic response in a "best-effort" kind of way which means it basically never throws any errors to help figure out why it's not doing what you expect it to (which can be frustrating, I'm sure). In this case, I suspect that the lack of cursors on your edge objects fools Relay's client-side type inference into treating this response as some kind of unknown list, and therefore doesn't update your connection like you hope it will. Adding cursors is probably the best bet, let us know if that doesn't help. In general my advice for applying an optimistic response is to copy the "real" server response and then gradually delete fields from it and test to make sure it still updates your UI like you want it to. Once you remove enough fields to get an object you are confident you can generate client-side, write the code to do that. |
Adding cursors to the edges didn't work for me but I removed optimistic updates from my code for the moment. I like your suggestion of copying the real response and trimming the data down, I'll give that a shot when I have time. I'm going to close the issue for now until I'm certain it's not a fault in my code. |
I have an array of movies that are ordered by user rating. When the user changes the rating of one movie the ordering of the list is also changed. I created an optimistic update which re-orders the list appropriately but even tho Relay shows the optimistic response is in the correct order, in componentWillReceiveProps the order of the array remains the same even tho the rating ( 3 stars updated to 5 stars) has correctly changed. When the server replies back with the updated array, I see my listview refresh in the correct order.
How do I make sure that componentWillReceiveProps gets the ordered array that I generated in my optimistic update?
The text was updated successfully, but these errors were encountered: