zid
zid14mo ago

Optimistic Updates Support for paginated queries

Question about optimistic updates: are paginated queries supported for optimistic updates? my requirements are more complex than what's shown in the docs but should still be common enough. in short, im trying add the ability to "like" (react) to comments. These comments are paginated. Also, not sure exactly how much this will come into play but the realtime comments are separated from what's being shown in the UI using useBufferedPaginatedState.
5 Replies
zid
zidOP14mo ago
if its not supported, i wonder if passing in the realtime list as an argument could be used as the initial query rather than getQuery. So essentially, i'll be feeding in the realtime data from convex into withOptimisticUpdate. Then, I'll loop to get the comment in question, update the reaction, then use setQuery to update localStore. Not sure how rollbacks would work tho even if there was limited support, where i could pass in initial pagination options, i could keep a counter in state to help determine the number of i tems to fetch i suppose another way would be to manage all of this in local state rather than rely on optimistic updates... fingers crossed for paginated query support hmm, im going to try to add the optimistic update at the <Comment /> level, to bypass the need for paginated support.. doesnt seem ideal however from a cost perspective -- the fact that at the Comment level, I would have to fetch its own respective reactions with a separate read. hmm, going to first try using local state at the Comment level and initializing the values with the initially fetched data from convex
sshader
sshader14mo ago
I want to make sure I understand the set up here -- sounds like you have a paginated query that returns comments, and each returned comment has an array of "likes"? And then there is a mutation to like a comment, and you want to write an optimistic update that will update the paginated query for comments? (Please correct whatever I misunderstood)
zid
zidOP14mo ago
this part of my app is a reddit-clone. all im asking is if there is native support for paginated queries when using optimistic update api. for context and clarification: comments are fetched using useBufferedPaginatedState so realtime data is separated from UI layer. each comment has reactions on it: hearts, laughs, likes, dislikes when a user "reacts" to a comment, db updates as expected but, it doesn't update in the UI due to the architecture. I resolved the issue, or rather, made a pretty solid workaround. still, it would be great if there was native support for paginated queries when using optimistic update api. no need to resolve anything, just wanted to confirm that there's no native support.
sshader
sshader14mo ago
optimisticallyUpdateValueInPaginatedQuery might be interesting to you (https://github.com/get-convex/convex-js/blob/32ff1dc1190e35223bda44c41f51a237960da3e0/src/react/use_paginated_query.ts#L525) What is useBufferedPaginatedState ? (since I don't think it's a built in Convex hook)
GitHub
convex-js/src/react/use_paginated_query.ts at 32ff1dc1190e35223bda4...
TypeScript/JavaScript client library for Convex. Contribute to get-convex/convex-js development by creating an account on GitHub.
zid
zidOP14mo ago
No worries, i made a solution that works quite well. And useBufferedPaginatedState is a technique that Jamie came up with to separate the realtime data stream and the UI the user sees: https://stack.convex.dev/coping-with-the-web-s-looming-global-reactivity-crisis Thank yo ufor the help

Did you find this page helpful?