Mutation Standardization
Objective
Move all write-side data changes behind mutation hooks and use one consistent cache-refresh strategy.Rules
- all writes belong in
hooks/mutations/ - no page or component should perform app-data writes with raw
fetch - every write should be wrapped by
useMutation - prefer
onSuccessplusinvalidateQueries - do not use
setQueryDataorsetQueriesDatafor this migration
Standard Pattern
Why We Are Avoiding setQueryData
This migration intentionally favors consistency over local cache patching:
- invalidation is easier to reason about across many domains
- invalidation is easier to audit in code review
- invalidation reduces drift between server truth and local cache assumptions
Required Refactors
Move writes out of components/pages
Any write-sidefetch in app/ or components/ should be moved into a descriptive mutation hook.
Examples:
hooks/mutations/use-update-account-type.tshooks/mutations/use-update-account-tax-treatment.tshooks/mutations/use-disconnect-account.tshooks/mutations/use-process-snaptrade-connection.ts
Update call sites
Pages/components should consume hook APIs only:Replace local cache writes
RemovequeryClient.setQueryData(...) and queryClient.setQueriesData(...) from the codebase and replace them with the standardized mutation + invalidation flow.
Review Checklist
- is the write implemented in
hooks/mutations/? - does the hook own the
fetchcall? - does
onSuccessinvalidate the narrowest correct key family? - did we remove any direct page/component
fetchwrite logic? - did we eliminate
setQueryDataorsetQueriesDatafrom the touched path?