Skip to content

Tanstack Start: Optimistic update support for reducers #4442

@vaneworks

Description

@vaneworks

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.

Metadata

Metadata

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