fix(playground): auto-focus chat input when active session changes#13310
fix(playground): auto-focus chat input when active session changes#13310keval718 wants to merge 2 commits into
Conversation
Previously the playground chat textarea stayed unfocused when a new session was created, when the user switched sessions from the sidebar, or on initial playground mount, forcing an extra click before typing. Subscribe ChatInput to ``useSessionManagerStore.activeSessionId`` and focus the textarea via ``requestAnimationFrame`` whenever that id changes. rAF defers focus past the AnimatePresence/motion mount transition so focus is not stolen back. Guarded with ``noInput`` (no textarea rendered in that branch). Cleanup cancels a pending rAF on unmount or before the next effect run. Adds ``__tests__/chat-input.test.tsx`` covering: no-session, initial mount with session, session change re-fires focus, noInput skip, unmount-before-rAF cancel, and same-id-no-refire. 6/6 green; wider playground jest suite 142/142.
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughChatInput component now auto-focuses its textarea input when the active session ID changes. The implementation uses ChangesAuto-focus on active session change
🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 8 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (8 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
✅ Test Coverage AdvisorNo source changes detected without accompanying tests. Thanks for keeping coverage up! 🎉
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## release-1.10.0 #13310 +/- ##
==================================================
+ Coverage 55.42% 55.69% +0.27%
==================================================
Files 2179 2179
Lines 205846 205924 +78
Branches 31073 29414 -1659
==================================================
+ Hits 114091 114691 +600
+ Misses 90427 89904 -523
- Partials 1328 1329 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/frontend/src/components/core/playgroundComponent/chat-view/chat-input/__tests__/chat-input.test.tsx (1)
64-83: ⚡ Quick winReduce core-component mocking in this suite.
Mocking
../components/input-wrapperhides real ref wiring and can let focus tests pass even if the actual wrapper breaks. Prefer keepingInputWrapperreal and spying on textarea focus (document.activeElementorHTMLTextAreaElement.prototype.focus) while only mocking external dependencies.As per coding guidelines, "Warn when mocks are used instead of testing real behavior and interactions, and suggest using real objects or test doubles when mocks become excessive" and "Ensure mocks are used appropriately for external dependencies only, not for core logic."
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/frontend/src/components/core/playgroundComponent/chat-view/chat-input/__tests__/chat-input.test.tsx` around lines 64 - 83, Remove the jest.mock for "../components/input-wrapper" and use the real InputWrapper in the chat-input.test.tsx suite; delete the focusMock and mocked default export, import the actual InputWrapper component instead, and replace assertions that relied on focusMock by spying on textarea focus behavior (e.g., using HTMLTextAreaElement.prototype.focus or checking document.activeElement) so tests verify real ref wiring and focus interactions rather than the mocked implementation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In
`@src/frontend/src/components/core/playgroundComponent/chat-view/chat-input/__tests__/chat-input.test.tsx`:
- Around line 64-83: Remove the jest.mock for "../components/input-wrapper" and
use the real InputWrapper in the chat-input.test.tsx suite; delete the focusMock
and mocked default export, import the actual InputWrapper component instead, and
replace assertions that relied on focusMock by spying on textarea focus behavior
(e.g., using HTMLTextAreaElement.prototype.focus or checking
document.activeElement) so tests verify real ref wiring and focus interactions
rather than the mocked implementation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: acf841ab-25af-41a5-8291-8715e150c47b
📒 Files selected for processing (2)
src/frontend/src/components/core/playgroundComponent/chat-view/chat-input/__tests__/chat-input.test.tsxsrc/frontend/src/components/core/playgroundComponent/chat-view/chat-input/chat-input.tsx
…electors Biome flagged six `lint/suspicious/noExplicitAny` errors in the new chat-input.test.tsx. Replace each store mock's `(selector: any)` with a generic `Selector<TState, TResult>` parameterised on the mock's concrete state shape. Replace `motion.div: (props: any)` with `React.HTMLAttributes<HTMLDivElement>`. Biome + tsc clean; 6/6 still green.
Summary
When a new playground session was created — or when the user switched between sessions in the sidebar, or simply opened the playground for the first time — the chat textarea did not receive focus. The cursor sat idle, forcing an extra click before the user could start typing. This PR removes that friction.
ChatInputnow subscribes touseSessionManagerStore.activeSessionIdand focuses the textarea whenever that id changes. The focus call is wrapped inrequestAnimationFrameso it runs after theAnimatePresence/motionmount transition settles — otherwise the framer-motion lifecycle would steal focus back. Cleanup cancels any pending rAF if the component unmounts or the effect re-runs before the frame fires.