-
Notifications
You must be signed in to change notification settings - Fork 739
Description
Problem
There's no way to optimistically update the UI when calling a reducer. The UI only updates after the WebSocket round-trip — the reducer runs on the server, the subscription fires, and setQueryData updates the cache. This creates a noticeable delay between user action and UI response.
Since the TanStack integration already wraps React Query, it would be natural to support optimistic updates the way React Query mutations do — immediately update the cache with the expected result, then reconcile when the server confirms.
Something like:
const addReducer = useReducer(reducers.add, {
optimistic: (args, currentData) => {
return [...currentData, { name: args.name }];
},
});or whatever your team prefers.
The SDK knows which tables a reducer modifies and already manages the React Query cache via setQueryData. It's in the best position to handle the optimistic update, rollback on error, and reconciliation when the real subscription update arrives.