Skip to content

Remove leave-convo suppression, use real optimistic update - #10834

Merged
mozzius merged 1 commit into
mainfrom
samuel/remove-leave-convo-suppression
Jun 10, 2026
Merged

mozzius merged 1 commit into
mainfrom
samuel/remove-leave-convo-suppression

Conversation

@mozzius

@mozzius mozzius commented Jun 10, 2026 •

Copy link
Copy Markdown
Member

Why

When you leave a chat, we currently suppress it from the frontend in a heavy-handed way: useLeftConvos() reads React Query mutation state (pending and success) and every list surface (ListConvosProvider, ChatList, Header, Inbox) filters those convo IDs out. This was a workaround for a slow backend leaveConvo query (30+ seconds, sometimes timing out), where the convo had to stay hidden long after refetches would have clobbered an optimistic cache edit.

The backend query is now fast, so this can all go.

The bug the workaround was hiding

useLeaveConvo's onMutate already attempted an optimistic update, but it called setQueryData([CONVO_LIST_KEY]) — an exact key match against just the root 'convo-list'. Real queries are keyed ['convo-list', 'accepted', ...], ['convo-list', 'request', ...], etc., so the update never matched anything and was a no-op. That's why the suppression layer was needed in the first place.

What changed

  • leave-conversation.ts:
    • onMutate now uses setQueriesData (prefix match) to optimistically remove the convo from all convo-list queries, and also from the requests cache (optimisticDelete from list-conversation-requests), which the old code never touched
    • snapshots both caches and restores them in onError, then invalidates both roots — same pattern as useAcceptConversation
    • deleted useLeftConvos()
  • list-conversations.tsx, ChatList.tsx, Inbox.tsx: removed the leftConvos filtering

No changes needed at the 8 useLeaveConvo call sites — the hook's signature is unchanged.

Test plan

  • pnpm typecheck, pnpm lint, pnpm test
  • Leave a 1:1 convo via the chat menu — disappears immediately, stays gone after refetch
  • Leave a group via conversation settings — navigates back, gone from list
  • Reject/delete an incoming request from the inbox — disappears from requests list
  • Failure case (offline/throttled): convo reappears in the correct list and error toast shows

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor
Old size New size Diff
7.73 MB 7.73 MB -1.56 KB (-0.02%)

useLeftConvos() filtered convos out of every list based on leave-mutation
state, working around a slow backend leaveConvo query. now that the
backend is fast, replace it with a working optimistic update: the old
onMutate used setQueryData with just the root key, which never matched
any real query, so it was a no-op. switch to setQueriesData (prefix
match) across both the convo-list and requests caches, with snapshot
rollback on error, mirroring useAcceptConversation.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@mozzius
mozzius force-pushed the samuel/remove-leave-convo-suppression branch from 6304647 to fce5402 Compare June 10, 2026 08:37
@arcalinea
arcalinea temporarily deployed to samuel/remove-leave-convo-suppression - social-app PR #10834 June 10, 2026 08:37 — with Render Destroyed
@mozzius
mozzius marked this pull request as ready for review June 10, 2026 08:54
@mozzius

mozzius commented Jun 10, 2026

Copy link
Copy Markdown
Member Author

@claude please review

@claude

claude Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @mozzius's task in 1m 56s —— View job


Review

The refactor is clean and the diagnosis is correct: the old setQueryData([CONVO_LIST_KEY], ...) was an exact-key match against just ['convo-list'], but the real query keys are ['convo-list', 'accepted', ...] etc. — so the optimistic update was a no-op and the useLeftConvos mutation-state filter was filling the gap. Switching to setQueriesData with a prefix match fixes it at the source, and the resulting pattern mirrors useAcceptConversation in accept-conversation.ts, which is a good consistency win.

A couple of small observations, no blockers:

1. Defensive guard asymmetry — src/state/queries/messages/leave-conversation.ts:55-80

The convo-list updater filters on convo.id !== convoId unconditionally, while the requests updater guards convoId ? optimisticDeleteRequest(convoId, old) : old. In practice this doesn't matter — mutationFn throws on undefined convoId so the mutation can never succeed — and convo.id !== undefined is always true so the convo-list filter is a harmless no-op. But the two paths read inconsistently. Easiest fix is to drop the convoId ? ternary on the requests side (the function already early-returns on missing data) for symmetry, or alternatively early-return from onMutate when !convoId.

2. Pending-refetch race window

The old suppression mechanism kept convos hidden even across refetches (useMutationState({status: 'success'}) lingers). The new code relies on onSuccess → invalidateQueries to fetch the now-authoritative server state. If a polling refetch fires between onMutate and the leave request completing (poll interval is 30s, see MESSAGE_SCREEN_POLL_INTERVAL), the convo can briefly reappear in the list. With the backend now fast this should be rare, but it's worth eyeballing in QA on a throttled connection — particularly the 4th manual test plan item.

3. Test plan

pnpm typecheck/lint/test is checked, but the four behavioral cases (leave 1:1, leave group, reject request, failure restore) are not. The failure case is the highest-risk one to manually verify since it now exercises a brand-new code path (restoring snapshots across multiple query variants + invalidating both roots).

4. Nit: backwards-compat type alias

type ConvoListQueryData declared locally at leave-conversation.ts:23-26 is identical to the inline type in accept-conversation.ts. If you wanted to fold it in later, list-conversations.tsx could export it next to ConvoRequestListQueryData and both files could share it. Not worth doing in this PR.

Overall: 👍 — this is a strict improvement: removes a wide-blast-radius workaround, fixes the underlying optimistic-update bug, and updates the requests cache too (which the old code didn't touch). I traced all 9 useLeaveConvo call sites to confirm the signature is unchanged and no stale useLeftConvos/leftConvos references remain.


  • Read PR context and changes
  • Read changed files
  • Verify the fix matches the description
  • Look for bugs, edge cases, and adherence to CLAUDE.md
  • Post review feedback
    • Branch: samuel/remove-leave-convo-suppression

@mozzius
mozzius merged commit 9a2e636 into main Jun 10, 2026
19 checks passed
estrattonbailey added a commit that referenced this pull request Jun 10, 2026
…uttons

* origin/main: (149 commits)
  Tweak spacing in invite link dialog (#10829)
  [Chat] Fix source of truth for group size limit (#10845)
  [Chat] Sync convo agent with shadow cache (#10827)
  [Chat] Some tweaks (#10840)
  [Chat] Fix optimistic updates by using partial keys (#10838)
  Remove leave-convo suppression, use real optimistic update (#10834)
  use opus 4.8 in github claude (#10837)
  [Chat] revalidate join links on leave (#10833)
  Clear search term after adding chat member (#10831)
  Support dim theme on join request landing page (#10832)
  Nightly source-language update
  bskyweb: meta noindex tag for non-indexable pages (#10803)
  Hide domain if matches handle, new Standard Site icon treatment (#10767)
  Fix image collapse in FF (#10826)
  Change Ignore to Reject for chat invites (#10825)
  [Chat] add lil gap between chats on web (#10821)
  Add list of mutual chats to block dialog (#10727)
  Address chat design nits (#10823)
  Fix link to profile from chat invite embed (#10822)
  [Chat] Show invite link label in chat list preview (#10811)
  ...

This branch was successfully deployed

No deployments
samuel/remove-leave-convo-suppression - social-app PR #10834 — fce5402e Deployed Jun 10, 2026 by arcalinea
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.

2 participants