fix(web): suppress global error toast on mutations that own their toast UX#1385
fix(web): suppress global error toast on mutations that own their toast UX#1385voidborne-d wants to merge 1 commit into
Conversation
…st UX Closes MODSetter#1371. `surfsense_web/lib/query-client/client.ts` configures a global `MutationCache.onError` that shows an error toast for every failed mutation unless `meta.suppressGlobalErrorToast` is set. The opt-out hook existed in the consumer but had zero producers — every mutation atom that already had its own `onError: toast.error(...)` was double-toasting on failure. Add `meta: { suppressGlobalErrorToast: true }` to the 30 mutations across 9 atom files that own their own error toast: - atoms/prompts/prompts-mutation.atoms.ts (4) - atoms/invites/invites-mutation.atoms.ts (4) - atoms/chat-comments/comments-mutation.atoms.ts (4) - atoms/new-llm-config/new-llm-config-mutation.atoms.ts (4) - atoms/members/members-mutation.atoms.ts (3) - atoms/roles/roles-mutation.atoms.ts (3) - atoms/image-gen-config/image-gen-config-mutation.atoms.ts (3) - atoms/vision-llm-config/vision-llm-config-mutation.atoms.ts (3) - atoms/public-chat-snapshots/public-chat-snapshots-mutation.atoms.ts (2) Atoms that rely on the global handler (no local `onError` toast) are left untouched: auth, user, search-spaces, logs, documents, connectors. TanStack Query v5 types `meta` as `Record<string, unknown> | undefined` so no module augmentation is needed; `tsc --noEmit` reports the same 48 pre-existing errors before and after this change (none in the touched files) and `biome check` on the 9 files passes clean. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
@voidborne-d is attempting to deploy a commit to the Rohan Verma's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (9)
📝 WalkthroughWalkthroughThis PR systematically adds ChangesGlobal Error Toast Suppression Across Mutation Atoms
Estimated Code Review Effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@voidborne-d Thanks. Please raise PR on |
|
Thanks @MODSetter — retargeted onto |
Closes #1371.
Summary
surfsense_web/lib/query-client/client.tsconfigures a globalMutationCache.onErrorthat callsshowErrorToast(error)for every failed mutation unlessmutation.meta?.suppressGlobalErrorToastis true. The opt-out hook was defined in the consumer but had zero producers anywhere in the codebase — every mutation atom that already had its ownonError: toast.error(...)was double-toasting on failure.This PR activates the seam: it adds
meta: { suppressGlobalErrorToast: true }to exactly the mutation atoms that own their own error toast, so the global handler skips them.Files touched (9 atom files, 30 mutations)
atoms/prompts/prompts-mutation.atoms.tsatoms/invites/invites-mutation.atoms.tsatoms/chat-comments/comments-mutation.atoms.tsatoms/new-llm-config/new-llm-config-mutation.atoms.tsatoms/members/members-mutation.atoms.tsatoms/roles/roles-mutation.atoms.tsatoms/image-gen-config/image-gen-config-mutation.atoms.tsatoms/vision-llm-config/vision-llm-config-mutation.atoms.tsatoms/public-chat-snapshots/public-chat-snapshots-mutation.atoms.tsTotal: +30/-0 across 9 files.
Atoms intentionally left alone
These mutation atoms don't have their own `onError` toast and continue to rely on the global handler — touching them would invert their UX:
Why no TypeScript module augmentation
The issue mentioned augmentation might be needed via TanStack Query's `Register.mutationMeta`. In v5 (`@tanstack/react-query@^5.90.7`), `meta` is typed as `Record<string, unknown> | undefined` by default, so the producer side compiles cleanly today. The consumer (`client.ts:18-22`) already uses optional chaining (`mutation.meta?.suppressGlobalErrorToast`) which is safe against the `unknown` value type.
Adding the module augmentation would tighten the contract on both sides but isn't required for this fix to work. Happy to layer it in as a follow-up if maintainers prefer that.
Local validation
`pnpm biome check` on the 9 touched files: clean (no fixes applied, 0 diagnostics).
`tsc --noEmit` baseline before this PR: 48 errors. After this PR: 48 errors. None of the 48 are in the touched files (all are pre-existing issues in blog/dashboard/components — unrelated). Zero new TypeScript errors introduced.
Each mutation now matches the canonical shape from issue Stop double-toasting on mutation errors: set
meta.suppressGlobalErrorToaston mutations with their ownonErrortoast #1371:```ts
export const createPromptMutationAtom = atomWithMutation(() => ({
mutationKey: ["prompts", "create"],
meta: { suppressGlobalErrorToast: true }, // <-- added
mutationFn: async (request: PromptCreateRequest) => promptsApiService.create(request),
onSuccess: () => { ... },
onError: (error: Error) => {
toast.error(error.message || "Failed to create prompt");
},
}));
```
Test plan
Notes
Co-authored-by: Claude Opus 4.7 (1M context) noreply@anthropic.com
High-level PR Summary
This PR fixes a double-toasting bug where mutation errors were being displayed twice: once from the global error handler and once from mutation-specific error handlers. The fix adds
meta: { suppressGlobalErrorToast: true }to 30 mutation atoms across 9 files that already have their ownonErrortoast handlers, activating an existing but unused opt-out mechanism in the global mutation cache. Mutations without their own error handlers continue to rely on the global handler as before.⏱️ Estimated Review Time: 5-15 minutes
💡 Review Order Suggestion
surfsense_web/atoms/prompts/prompts-mutation.atoms.tssurfsense_web/atoms/invites/invites-mutation.atoms.tssurfsense_web/atoms/chat-comments/comments-mutation.atoms.tssurfsense_web/atoms/members/members-mutation.atoms.tssurfsense_web/atoms/roles/roles-mutation.atoms.tssurfsense_web/atoms/public-chat-snapshots/public-chat-snapshots-mutation.atoms.tssurfsense_web/atoms/new-llm-config/new-llm-config-mutation.atoms.tssurfsense_web/atoms/image-gen-config/image-gen-config-mutation.atoms.tssurfsense_web/atoms/vision-llm-config/vision-llm-config-mutation.atoms.tsSummary by CodeRabbit