-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
I’m having trouble implementing optimistic updates correctly.
I have a chat app that polls the server every 10 seconds to check for new messages. When new data is available, I invalidate the cache tags for both the messenger and the conversation so they can fetch the latest data.
When I send a message, I perform an optimistic update so the message appears immediately in the conversation. Once the request succeeds, I replace the optimistic message with the actual response from the server.
This works fine — except when an optimistic update happens at the same time the conversation data is invalidated by the polling process. In that case, the optimistic message never appears in the chat because the invalidation triggers a refetch before the optimistic update is applied.
Is there any way to add the optimistic update also during cache invalidation?