[react] a run that starts elsewhere moves focus from another text field into the composer
Summary
unstable_focusOnRunStart (default true; applies when autoFocus is on) focuses the thread composer on every run start, including runs not started from the composer: a queued message, a resume, or a programmatic append. A user typing in another text field on the page has their focus taken mid-typing.
Type Of Work In Progress
Found while model-checking assistant-ui's runtime with TLA+ and property tests (formal verification of the composer's keyboard, IME and focus handling); reproduced on real code with a failing vitest test.
Reproduction Steps
- Render a thread with
ComposerPrimitive.Input autoFocusand another<input>on the page. - Focus the other input and type.
- Start a run programmatically (for example
aui.thread.append(...)from a button handler, or a queued message). - Focus jumps to the composer.
Expected Behavior
Starting a run does not take focus from another text field the user is typing in.
Actual Behavior
The thread composer subscribes to thread.runStart and calls focus(), which checks only autoFocus and whether the composer is disabled, not where focus currently is.
Context
- Package(s): @assistant-ui/react 0.15.21
- Repository state: origin/main 96e11d9c0
- Code:
packages/react/src/primitives/composer/ComposerInput.tsx:318-325(focus),:337-346(run-start subscription) - Failing test:
K-5 leaves focus in another text field when a run starts elsewhere(repro test, not in a PR)
Decision needed
This is documented behaviour (the prop's JSDoc: "Whether to automatically focus the input when a new run starts"), so it is a policy question. WCAG 3.2.2 argues against moving focus away from text entry. Options: only move focus when it is on <body> or already inside the thread, only for runs started from the composer, or keep the current behaviour.
Source: assistant-ui/assistant-ui