Skip to content

refactor(frontend): use client.mutate where useMutation result is unused#2338

Merged
gregberge merged 1 commit into
mainfrom
greg/refactor-usemutation-to-client-mutate
Jul 7, 2026
Merged

refactor(frontend): use client.mutate where useMutation result is unused#2338
gregberge merged 1 commit into
mainfrom
greg/refactor-usemutation-to-client-mutate

Conversation

@gregberge

Copy link
Copy Markdown
Member

Summary

Follow-up cleanup from #2336: eliminate the useMutation-without-result anti-pattern across the frontend.

useMutation subscribes the component to the mutation's own loading/data/error state and re-renders it while the request is in flight even when that state is never read. Where a call site only needs to fire the mutation (it tracks pending itself, or not at all), that's wasted work. Those are replaced with useApolloClient().mutate(), which doesn't subscribe.

This is the guideline documented in apps/frontend/AGENTS.md (added in #2336).

Scope

31 call sites across 19 files converted — behavior preserved:

  • Call-site variables / optimisticResponse / update / context folded into the single client.mutate({ mutation, ... }) object.
  • DeleteAutomation and the useCreateBuildReviewMutation hook: onCompleted.then().
  • BuildReviewAction no longer returns its unused mutation result (its one caller already destructured it away).

Areas touched: auth disconnects (GitHub/GitLab/Google), Slack, GitRepository (unlink), SAMLSSO, contributor/member level selects, InvitesList, IgnoreButton, DeleteAutomation, comment composers (AddCommentForm, CommentCard, ScreenshotCommentLayer, DiffCommentLayer), optimistic toggles (CommentReactions, ReviewActivitySection subscribe, ReviewersSection request), and the review-action hook.

Left as-is: the 25 useMutation usages that genuinely render from loading/data/error (dialogs with spinners, invite/verify screens, etc.).

Verification

  • pnpm check-types — 0 errors
  • pnpm lint — clean
  • pnpm check-format — clean
  • Every remaining useMutation( call reads its result state (verified by grep).

🤖 Generated with Claude Code

useMutation subscribes the component to the mutation's loading/data/error and
re-renders it while the request is in flight even when that state is never read.
Replace those call sites with useApolloClient().mutate(), which doesn't — the
guideline documented in apps/frontend/AGENTS.md.

Converted 31 call sites across 19 files (auth disconnects, level selects,
invites, ignore/unignore, comment composers, optimistic toggles, the review
action hook, …). Call-site variables/optimisticResponse/update/context move
into the single client.mutate({...}) call; DeleteAutomation's and the review
hook's onCompleted become .then(); BuildReviewAction stops returning its unused
mutation result (its one caller already ignored it).

The 25 useMutation usages that actually render from loading/data/error are left
as-is.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gregberge gregberge requested a review from jsfez July 6, 2026 08:39
@argos-ci

argos-ci Bot commented Jul 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
argos/default (Inspect) ✅ No changes detected - Jul 6, 2026, 8:41 AM
storybook/default (Inspect) ✅ No changes detected - Jul 6, 2026, 8:40 AM
Deployment Status Branch Updated (UTC)
storybook/preview (Open) Ready greg/refactor-usemutation-to-client-mutate Jul 6, 2026, 8:39 AM

@gregberge gregberge merged commit d445c76 into main Jul 7, 2026
14 checks passed
@gregberge gregberge deleted the greg/refactor-usemutation-to-client-mutate branch July 7, 2026 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant