fix(web): suppress global error toast on mutations that own their toast UX#1397
Conversation
…st UX Closes MODSetter#1371. Retarget of MODSetter#1385 onto dev per maintainer request. 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 intentionally left alone (no local onError, rely on global): auth, user, search-spaces, logs, documents, connectors. Local validation (against dev): pnpm biome check on the 9 touched files is clean; tsc --noEmit shows no new errors in the touched files (pre-existing errors elsewhere unrelated). 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. |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ 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 |
|
Thanks @MODSetter — clean apply on |
Closes #1371. Retarget of #1385 onto
devper @MODSetter's request (#1385 (comment)).Summary
surfsense_web/lib/query-client/client.tsconfigures a globalMutationCache.onErrorthat callsshowErrorToast(error)for every failed mutation unlessmutation.meta?.suppressGlobalErrorToastis true. Ondev(andmain) the opt-out hook is defined in the consumer but has zero producers anywhere in the codebase — every mutation atom that already has 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
onErrortoast and continue to rely on the global handler — touching them would invert their UX:atoms/auth/auth-mutation.atoms.tsatoms/user/user-mutation.atoms.tsatoms/search-spaces/search-space-mutation.atoms.tsatoms/logs/log-mutation.atoms.tsatoms/documents/document-mutation.atoms.tsatoms/connectors/connector-mutation.atoms.tsWhy 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),metais typed asRecord<string, unknown> | undefinedby default, so the producer side compiles cleanly today. The consumer (client.ts) already uses optional chaining (mutation.meta?.suppressGlobalErrorToast) which is safe against theunknownvalue 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.
Diff vs #1385
Identical patch (cherry-picked from
2a5dcf7onmain-based branch). Verified clean apply ondevHEADeea2d68. No conflicts; the 9 atom files have not diverged betweenmainanddevfor this surface.Local validation (on
dev)pnpm biome checkon the 9 touched files: clean (0 diagnostics).tsc --noEmitbaseline: pre-existing errors are unrelated; none of the touched files contribute new errors.Test plan
"Failed to create prompt") appears, not two.🤖 Generated with Claude Code
High-level PR Summary
This PR fixes a double-toasting bug where mutation errors were displayed twice: once from the global error handler in
client.tsand once from the mutation's ownonErrorcallback. The fix addsmeta: { suppressGlobalErrorToast: true }to 30 mutations across 9 atom files that already handle their own error toasts, preventing the global handler from firing redundantly. Six other atom files that don't define custom error handlers are intentionally left unchanged to continue using the global toast mechanism.⏱️ 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/roles/roles-mutation.atoms.tssurfsense_web/atoms/members/members-mutation.atoms.tssurfsense_web/atoms/chat-comments/comments-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/vision-llm-config/vision-llm-config-mutation.atoms.tssurfsense_web/atoms/image-gen-config/image-gen-config-mutation.atoms.ts