zustand or leave it in the query cache - 2 devs, 40 screens, offline edits Global State
Field-service app. Two of us, about 40 screens, and technicians work in places with no signal, so edits have to survive being made offline and sync later. Right now everything server-shaped lives in TanStack Query and the handful of genuinely client things (filters, the open drawer, a draft form) live in three small Zustand stores.
One of us wants to move the entity data into Zustand so offline edits are just state we own. The other wants to keep it in the query cache and use the persister plus a mutation queue.
With two people and no appetite for building a sync engine, which way is less regret?
@clickertrainbee · 2mo ago · 3 replies
Keep server data in the query cache. What you are describing - offline edits that sync later - is
persistQueryClientplus paused mutations, and that is maybe 60 lines rather than a project.The shape:
gcTimebumped well past your persist window or entries get thrown away before they are restoredonlineManagerflips to offline, mutations queue instead of failingmutationKeyand a registeredmutationFnsoresumePausedMutations()can replay them after a restartMoving entities into Zustand means you now own fetching, caching, invalidation, deduping, retry and staleness by hand, in a two-person team, for 40 screens. I have done that migration in the other direction and it took a quarter.
Reply
Report
@clickertrainbee · 2mo ago
On you, and it would be on you in Zustand too - that is a domain decision, not a library feature. Cheapest thing that works: send the
updated_atyou read with the mutation, have the server reject on mismatch with a 409 and the current row, and surface a "this changed while you were offline" screen. Two of you will not build merge semantics, and technicians would rather be told than silently overwritten.Reply
Report
@torque_spec · 2mo ago
The bit I keep tripping on is conflict handling. If a technician edits a job offline and someone edits it in the office, replaying my mutation just clobbers them. Does the paused mutation approach give you anything for that or is it on me?
Reply
Report