Repository navigation
fix(dictation): send a dictated message once its words land in a hidden chat - #51131
Conversation
…en chat Enter during dictation queues the send until the final words land. The queued send ran from a passive effect, which a chat hidden by React Activity does not run, so switching away before the transcript was ready held the message until the chat was shown again. Run it from an insertion effect, which still fires when the hidden chat commits the render with the landed words, and defer the send to a microtask since an insertion effect may not update state. The hidden chat also detaches its message list handle, so the scroll to the sent message did nothing. Keep that reveal pending while the handle is missing and run it when the chat is shown again; hiding drops it. Fixes #51066
|
No actionable comments were generated in the recent review. Walkthrough
Severity of issue fixed: Medium Merge Risk:
|
ELI5
If you press Enter while still dictating and then switch to another chat, your message should still go out as soon as your words finish arriving. Before this fix it sat there until you came back to that chat.
What Changed
use-dictation-queued-send.ts: the queued send ran from a passiveuseEffect. ReactActivitydoes not run passive effects in a hidden subtree, but the subtree still commits the render with the landed words, and insertion effects still run during that commit. The send now runs fromuseInsertionEffect, deferred withqueueMicrotaskbecause an insertion effect may not update state.use-native-chat-reveal-latest.ts: a hidden chat detaches its message list handle, sorevealLatestdid nothing. When the handle is missing, the reveal is stored. A layout effect (which Activity runs again when the chat is shown) then performs it. Hiding the chat clears any pending reveal, so it can never fire later than that.Why
The send should not depend on whether the chat is on screen. Other options were moving the send out of React into the dictation session, or keeping hidden chats' effects running. Both would be larger changes to shared lifecycle code. This fix keeps the existing queue-until-landed design and only changes which effect phase runs it.
Linked Issue
Fixes #51066
Reported by @StasPotapov
Visual Proof
N/A: the only change is when an already-queued send fires while its chat is hidden. Nothing on screen is drawn differently, and the timing is covered by the regression tests below. Each of those tests fails on
mainand passes on this branch.Testing
Repro (unit, React Activity): dictate, press Enter, hide the chat, then deliver the final words. On
main, nothing is sent until the chat is shown again. On this branch, the message is sent once as soon as the words land, and it is not sent a second time when the chat is shown.use-native-chat-reveal-latest.test.tsx: a send accepted while the chat is hidden reveals the latest message once when the chat is shown, and does not reveal it again after a later hide and show.Extra edge probes passed in both StrictMode and non-strict mode: a visible send fires once with the landed text; hiding and then showing the chat before the words land sends once; nothing is sent when nothing is queued; unmounting the composer while a send is queued neither sends nor crashes; several reveals queued while hidden collapse into one; a reveal requested while the list is absent does not fire later.
vitest --config config/vitest.config.tson the touched dictation and native-chat action tests passes. oxlint, oxfmt, the anti-slop and code-quality oxlint configs, ast-grep, and the changed-code quality gate all report 0 findings.Platforms: macOS, unit level. The change is renderer-only React effect logic with no platform-specific code.
Automated tests added/updated, or explained why not below
Every added test fails without this change and avoids the test anti-patterns
Performance
None. Both hooks are per-composer and per-chat, with no store subscriptions or selectors added. The insertion effect has the same deps (
landedTick,sendMessage) as the passive effect it replaces, so it runs the same number of times. The layout effect depends only on a stable callback, so it runs only on mount and on Activity show. With N=200 mounted chats, one chat's dictation update still runs 1 effect in that chat and 0 in the others, the same asmain. There is no new I/O, polling, or subprocess work.Risk
Level: Low
The riskiest part is running the send from an insertion effect. React guarantees that insertion effects run on every commit, including in hidden Activity subtrees, and the test in
use-dictation-queued-send.test.tsxchecks this so a React upgrade that changes it will fail the test. If something went wrong, a dictated send could go out twice or not at all. The tests cover both cases. Backing it out is a plain revert, and no saved data is involved.Agent skill upstream boundary