From f0c0029d27f3ca8cf9e4ca9c4c4eac5b2a295541 Mon Sep 17 00:00:00 2001 From: Rudy Fraser Date: Thu, 2 Jul 2026 19:08:36 -0400 Subject: [PATCH] fix(community-posts): make community post deletes idempotent and resilient The delete mutation threw when the appview returned PostNotFound (post already deleted by a prior partially-failed attempt) and when the PDS stub delete failed after a successful appview delete. Both stranded a completed delete behind an error toast with the post still rendered. Already-gone now counts as success and the stub delete is best-effort, so the tombstone shadow and success toast fire like the standard path. --- src/state/queries/post.ts | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/state/queries/post.ts b/src/state/queries/post.ts index feb9659c9..fed8ddcf4 100644 --- a/src/state/queries/post.ts +++ b/src/state/queries/post.ts @@ -364,16 +364,23 @@ export function usePostDeleteMutation() { 'community.blacksky.feed.deletePost', {body: {uri}}, ) + // A post already gone from the appview is a successful outcome — a + // retry after a partial failure must not surface as an error. if (!res.ok) { - const err = await res.json().catch(() => ({})) - throw new Error(err.message || `deletePost failed: ${res.status}`) + const err = (await res.json().catch(() => ({}))) as {error?: string} + if (err.error !== 'PostNotFound') { + throw new Error(err.error || `deletePost failed: ${res.status}`) + } } - // Also delete the stub record from PDS - await agent.com.atproto.repo.deleteRecord({ - repo: parsedUri.hostname, - collection: COMMUNITY_POST_COLLECTION, - rkey: parsedUri.rkey, - }) + // Best-effort: the appview is the source of truth for community + // post visibility; a failed stub delete must not strand the delete. + await agent.com.atproto.repo + .deleteRecord({ + repo: parsedUri.hostname, + collection: COMMUNITY_POST_COLLECTION, + rkey: parsedUri.rkey, + }) + .catch(() => {}) } else { await agent.deletePost(uri) } -- knotmirror 0.0.1