Skip to content

fix(dictation): send a dictated message once its words land in a hidden chat - #51131

Merged
nwparker merged 1 commit into
mainfrom
bugbash/issue-51066
Nov 27, 2026
Merged

nwparker merged 1 commit into
mainfrom
bugbash/issue-51066

Conversation

@nwparker

@nwparker nwparker commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

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.

Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​123 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​123
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​25 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​19

What Changed

  • Before: pressing Enter during dictation queues the send until the final transcript lands. If the chat was hidden (switched to another tab) before the words landed, the message was not sent until the chat was shown again. When it did send while hidden, the scroll to the new message was lost.
  • After: the queued send goes out as soon as the words land, even in a hidden chat, and the transcript scrolls to that message when the chat is shown again.
  • Mechanism:
    • use-dictation-queued-send.ts: the queued send ran from a passive useEffect. React Activity does 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 from useInsertionEffect, deferred with queueMicrotask because an insertion effect may not update state.
    • use-native-chat-reveal-latest.ts: a hidden chat detaches its message list handle, so revealLatest did 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 main and 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.ts on 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 as main. 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.tsx checks 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

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

…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
@coderabbitai

coderabbitai Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The dictation send hook now uses an insertion effect and schedules the pending send in a microtask. The reveal hook saves requests when the message-list handle is unavailable and replays them from a layout effect. Tests cover both behaviors across chat visibility changes.

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 689b3

This change makes dictation sends go through while the chat is hidden, and reveals the message when the chat is shown again. No actionable merge-blocking risk was identified. A rare edge case may leave the reveal unperformed, but the message still renders.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the fix (sending a dictated message once its words land in a hidden chat). It matches the main change: the queued send now runs from an insertion effect and the reveal is stored while …
Description check Passed The description follows the template. It has ELI5, What Changed (before/after and mechanism), Why (alternatives considered), Linked Issue (Fixes #51066), Visual Proof (N/A with reason), Testing (with …
Linked Issues check Passed Issue #51066 requires that a dictated send queued by Enter is delivered once, when the transcript lands, even if the chat is hidden. At head, use-dictation-queued-send.ts consumes the pending send in …
Out of Scope Changes check Passed The changed files are the dictation queued-send hook, its test, the native-chat reveal-latest hook, and its test. The queued-send change implements the #51066 requirement directly. The reveal-latest c…
Full details: Title check

Explanation

The title names the fix (sending a dictated message once its words land in a hidden chat). It matches the main change: the queued send now runs from an insertion effect and the reveal is stored while the chat is hidden. The title uses the conventional fix(scope) prefix and fits the 76-character length.

Full details: Description check

Explanation

The description follows the template. It has ELI5, What Changed (before/after and mechanism), Why (alternatives considered), Linked Issue (Fixes #51066), Visual Proof (N/A with reason), Testing (with checkboxes), Performance (filled in), Risk (Level: Low, with revert plan), Agent skill boundary, and checklist items. Minor gaps: the Risk section does not clearly say whether a revert would undo any state, the AI Disclosure section is absent, and the Notes/Checklist items are not ticked. These gaps are non-critical.

Full details: Linked Issues check

Explanation

Issue #51066 requires that a dictated send queued by Enter is delivered once, when the transcript lands, even if the chat is hidden. At head, use-dictation-queued-send.ts consumes the pending send in useInsertionEffect instead of a passive useEffect. The effect clears pendingRef before scheduling sendMessage in queueMicrotask, so a repeated effect run cannot send twice. The effect keeps the [landedTick, sendMessage] deps, so the send fires on the same commit that delivers the words. The PR description and the raw summary report a regression test in use-dictation-queued-send.test.tsx that checks a hidden Activity commit sends exactly once. I did not run that test. The dependency on React running insertion effects in hidden Activity subtrees is stated in the code comment and the PR, and I did not independently verify it against the React version in use. The reveal change in use-native-chat-reveal-latest.ts stores a reveal when the message-list handle is missing and performs it on show, which supports the same hidden-send flow. Requirements are coding requirements. No unmet requirement is shown in the code.

Full details: Out of Scope Changes check

Explanation

The changed files are the dictation queued-send hook, its test, the native-chat reveal-latest hook, and its test. The queued-send change implements the #51066 requirement directly. The reveal-latest change handles the case where a send accepted while the chat is hidden has no mounted message-list handle, so the transcript scroll is not lost when the chat is shown. This follows from the hidden-send path and is not unrelated work. The changes do not add unrelated features, dependencies, or refactors beyond the two hooks and their tests. The reveal change is a secondary supporting change, and the PR describes it as part of the same fix.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1b50832b-5758-4e50-a35f-fe87781fec9a
Commits

Reviewing files that changed from the base of the PR and between 3cc45b5 and 689b33e.

Files selected for processing: 4

  • src/renderer/src/components/dictation/use-dictation-queued-send.test.tsx
  • src/renderer/src/components/dictation/use-dictation-queued-send.ts
  • src/renderer/src/components/native-chat/messages/actions/use-native-chat-reveal-latest.test.tsx
  • src/renderer/src/components/native-chat/messages/actions/use-native-chat-reveal-latest.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.

@nwparker
nwparker merged commit 165212b into main Nov 27, 2026
54 checks passed
@nwparker
nwparker deleted the bugbash/issue-51066 branch November 27, 2026 20:24
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.

[Bug]: Dictated message waits until you return to the chat after pressing Enter

1 participant