feat(chat): centralize AI mode entry points behind openChat helper#7036
Open
Haroenv wants to merge 2 commits into
Open
feat(chat): centralize AI mode entry points behind openChat helper#7036Haroenv wants to merge 2 commits into
Haroenv wants to merge 2 commits into
Conversation
Clicking the AI mode button multiple times sent the same query each time, even after a response had returned. Same for autocomplete prompt suggestions. Introduce `openChat` and `isChatBusy` in `lib/chat`. All AI-mode entry points in the searchbox and autocomplete (React + JS) now route through `openChat`, which opens the chat unconditionally, sends only when the message is non-empty and the chat is not already processing, and returns whether it sent so callers can clear their own input. The AI mode button is disabled while the chat is processing. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 2 |
TIP This summary will be updated as you push new changes.
More templates
algoliasearch-helper
instantsearch-ui-components
instantsearch.css
instantsearch.js
react-instantsearch
react-instantsearch-core
react-instantsearch-nextjs
react-instantsearch-router-nextjs
vue-instantsearch
commit: |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR centralizes all “AI mode” entry points behind a shared openChat helper to prevent duplicate chat submissions (especially from repeated clicks while a message is in flight), and propagates a disabled state to AI mode buttons based on chat busy status.
Changes:
- Added
openChat/isChatBusyhelpers to standardize “open + (conditionally) send” chat behavior and prevent re-sends while streaming/submitted. - Updated React InstantSearch and InstantSearch.js SearchBox/Autocomplete entry points to route through
openChat, and clear inputs only when a message is actually sent. - Added
aiModeButtonDisabledplumbing + UI tests to ensure AI mode buttons disable while chat is busy.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/react-instantsearch/src/widgets/SearchBox.tsx | Uses openChat for AI mode click behavior and wires aiModeButtonDisabled from isChatBusy. |
| packages/react-instantsearch/src/widgets/Autocomplete.tsx | Routes AI-mode button + prompt-suggestion selection through openChat, and propagates disabled state. |
| packages/react-instantsearch/src/ui/SearchBox.tsx | Adds aiModeButtonDisabled prop and applies it to the AI mode button. |
| packages/react-instantsearch/src/ui/tests/SearchBox.test.tsx | Adds UI coverage for rendering/disabling/click behavior of the AI mode button. |
| packages/react-instantsearch/src/components/AutocompleteSearch.tsx | Passes through the new aiModeButtonDisabled prop to shared UI component. |
| packages/instantsearch.js/src/widgets/search-box/search-box.tsx | Centralizes chat open/send via openChat and disables AI button using isChatBusy. |
| packages/instantsearch.js/src/widgets/autocomplete/autocomplete.tsx | Uses openChat for AI-mode and prompt suggestions; disables AI button while chat is busy. |
| packages/instantsearch.js/src/lib/chat/openChat.ts | Introduces shared openChat + isChatBusy helpers. |
| packages/instantsearch.js/src/lib/chat/index.ts | Re-exports openChat / isChatBusy and OpenChatOptions. |
| packages/instantsearch.js/src/lib/chat/tests/openChat.test.ts | Adds unit tests for open/send behavior and busy-state handling. |
| packages/instantsearch.js/src/components/SearchBox/SearchBox.tsx | Adds aiModeButtonDisabled prop and applies it to the Preact AI mode button. |
| packages/instantsearch-ui-components/src/components/autocomplete/AutocompleteSearch.tsx | Adds aiModeButtonDisabled prop and applies it to the AI mode button. |
| packages/instantsearch-ui-components/src/components/autocomplete/tests/AutocompleteSearch.test.tsx | Adds UI coverage for disabled AI mode button behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
`chatRenderState.sendMessage` is part of a `Partial<ChatRenderState>`, so it can be undefined. The previous code did `sendMessage?.(...)` and returned `true` unconditionally, which would cause callers to clear their input even though no message had actually been sent. Check for `sendMessage` before invoking and only return `true` when it ran. Also bump instantsearch.development.js bundlesize limit (262.25 → 262.5 kB) to accommodate the new openChat helper. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
openChathelper that all entry points route through, so duplicate sends are no longer possible.instantsearch.js/es/lib/chat:openChat(chatRenderState, { message? })— opens the chat unconditionally; sends only whenmessageis non-empty and the chat is not already processing; returnstruewhen a message was sent so callers can clear their input.isChatBusy(chatRenderState)— used to disable the AI mode button while a message is in flight.onSelectonSelectaiModeButtonDisabledis now a prop on the React SearchBox UI, the shared AutocompleteSearch UI, and the Preact SearchBox button.Why this matters
The original behavior was the combination of:
setOpen(true)+sendMessage({ text: query })with no in-flight guard.AbstractChat.sendMessageis queued in aSerialJobExecutor, so repeated clicks weren't dropped — they were queued, each producing its own assistant response. This PR fixes that.Vue InstantSearch doesn't yet expose AI mode, so nothing to mirror there. Any future entry point that has access to
chatRenderStatecan callopenChat({ message })and inherit the same behavior without needing to re-implement the open/send/busy logic.Test plan
yarn jest— 199 tests pass across modified packages, including 13 new tests foropenChat/isChatBusy(packages/instantsearch.js/src/lib/chat/__tests__/openChat.test.ts)aiModeButtonDisabledprop on the React SearchBox UI and on the shared AutocompleteSearchyarn type-check— clean on touched files🤖 Generated with Claude Code