Skip to content

Commit 7eec766

Browse files
Bekibooclaude
andcommitted
fix(blabsy): treat Blab creation as canonical send, counters best-effort
Addresses review feedback: addDoc and the counter updates ran together in Promise.all, so if addDoc succeeded but manageTotalTweets/manageTotalPhotos rejected, the catch reported "Failed to send" even though the Blab was created — prompting a retry and duplicate Blabs while metrics drift. Await addDoc on its own as the canonical send, then run the counter/reply updates best-effort (logged, non-fatal). Also use tweetRef.id directly instead of an extra getDoc round-trip, removing another post-send failure point (and a read). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 8d402b7 commit 7eec766

1 file changed

Lines changed: 12 additions & 7 deletions

File tree

  • platforms/blabsy/client/src/components/input

platforms/blabsy/client/src/components/input/input.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useState, useEffect, useRef, useId } from 'react';
33
import { AnimatePresence, motion } from 'motion/react';
44
import cn from 'clsx';
55
import { toast } from 'react-hot-toast';
6-
import { addDoc, getDoc, serverTimestamp } from 'firebase/firestore';
6+
import { addDoc, serverTimestamp } from 'firebase/firestore';
77
import { tweetsCollection } from '@lib/firebase/collections';
88
import {
99
manageReply,
@@ -96,14 +96,19 @@ export function Input({
9696

9797
await sleep(500);
9898

99-
const [tweetRef] = await Promise.all([
100-
addDoc(tweetsCollection, tweetData),
99+
// Creating the Blab is the canonical "send" — its success defines
100+
// success. addDoc returns a ref whose id is available immediately.
101+
const tweetRef = await addDoc(tweetsCollection, tweetData);
102+
103+
// Counter/reply updates are secondary: a failure here must NOT report
104+
// the send as failed, or the user retries and duplicates the Blab.
105+
await Promise.all([
101106
manageTotalTweets('increment', userId),
102107
tweetData.images && manageTotalPhotos('increment', userId),
103108
isReplying && manageReply('increment', parent?.id as string)
104-
]);
105-
106-
const { id: tweetId } = await getDoc(tweetRef);
109+
]).catch((error) =>
110+
console.error('Blab sent, but a follow-up counter update failed:', error)
111+
);
107112

108113
if (!modal && !replyModal) {
109114
discardTweet();
@@ -117,7 +122,7 @@ export function Input({
117122
<span className='flex gap-2'>
118123
Your Blab was sent
119124
<Link
120-
href={`/tweet/${tweetId}`}
125+
href={`/tweet/${tweetRef.id}`}
121126
className='custom-underline font-bold'
122127
>
123128
View

0 commit comments

Comments
 (0)