liyachun.L
Convex Community3y ago
5 replies
liyachun.

`_creationTime` issue for `withOptimisticUpdate`, and thoughts

Say I have a messages list to display and I need to show the _creationTime for each of the message
Once I have inserted a message and I want to show the message immediately instead of waiting for a api call.

1. withOptimisticUpdate is used on the api.messages.insert mutation, updating the api.messages.list query.
2. Inside withOptimisticUpdate, I have to set message._creationTime = clientSideNow(), and display the time.
3. Since the OptimisticLocalStore is fully clientSide and temporary, after the server have finished the real mutation, the newly inserted message will be updated to message._creationTime = serverSideNow().
4. If there is any network latency, the message list UI will experience an unexpected update because of the date change.
5. Same situation for message._id.

Workaround1: Add my custom message.localFirstCreationTime, which is generated and passed from client side.
Workaround2 as a feature request: allow overriding at least _creationTime?
Screenshot_2023-12-19_at_23.59.08.png
Was this page helpful?