Skip to content

How to handle optimistic updates during cache invalidation? #5103

@Brma1048

Description

@Brma1048

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions