Skip to content

Commit 6fe0e0e

Browse files
Dwiteclaude
andcommitted
fix(mobile): dictation review reads focus from the latest focus event
A transcript that landed between a focus event and the next render read the previous focus value and armed the review, which a later blur could reopen. The ref is now written where focus changes, not during render. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 4613358 commit 6fe0e0e

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎apps/mobile/src/features/threads/ThreadDetailScreen.tsx‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -402,21 +402,22 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
402402
const lastScrolledSubmittedMessageIdRef = useRef<MessageId | null>(null);
403403
const [composerExpanded, setComposerExpanded] = useState(false);
404404
const [composerFocused, setComposerFocused] = useState(false);
405-
const composerFocusedRef = useRef(composerFocused);
406-
composerFocusedRef.current = composerFocused;
405+
const composerFocusedRef = useRef(false);
407406
// A transcript dictated into the collapsed composer opens it for reading with the
408407
// keyboard down. Focusing the editor, tapping the feed, or sending ends the review.
409408
const [dictationReviewThreadKey, setDictationReviewThreadKey] = useState<string | null>(null);
410409
const isReviewingDictation =
411410
dictationReviewThreadKey === selectedThreadKey &&
412411
props.draftMessage.trim().length > 0 &&
413412
!composerFocused;
414-
// Dictation keeps the callback it started with, so focus is read when the transcript lands.
413+
// Dictation keeps the callback it started with, and a focus event may not have rendered
414+
// yet, so the ref carries the latest focus for the moment the transcript lands.
415415
const handleDictationComplete = useCallback(() => {
416416
if (!composerFocusedRef.current) setDictationReviewThreadKey(selectedThreadKey);
417417
}, [selectedThreadKey]);
418418
const handleComposerFocusChange = useCallback(
419419
(focused: boolean) => {
420+
composerFocusedRef.current = focused;
420421
if (focused) setDictationReviewThreadKey(null);
421422
setComposerFocused(focused);
422423
handleOwnedInputFocusChange(focused);
@@ -841,6 +842,7 @@ export const ThreadDetailScreen = memo(function ThreadDetailScreen(props: Thread
841842
useLayoutEffect(() => {
842843
selectedThreadKeyRef.current = selectedThreadKey;
843844
// A replaced or unmounted native editor may not emit a blur event.
845+
composerFocusedRef.current = false;
844846
setComposerFocused(false);
845847
}, [selectedThreadKey, showContent]);
846848

0 commit comments

Comments
 (0)