feat(chat): add Chat + ChatTrigger widgets to Vue (phase 1) - #7130
feat(chat): add Chat + ChatTrigger widgets to Vue (phase 1)#7130Haroenv wants to merge 2 commits into
Conversation
Ports the Chat and ChatTrigger widgets to vue-instantsearch, reusing the hook-based UI infrastructure (createHooksStore + renderReactCompat) and the Carousel from the recommend port. Infra: - `memo` on the hooks runtime (identity passthrough; the streaming-perf memo is a follow-up). - Function-ref support in the react-compat adapter (Vue 2 vnode hooks + Vue 3 function refs), for ChatPrompt's callback ref. - Extend AisCarousel with `headerComponent`/`showNavigation`/icon props for the chat tools. Widgets: - `AisChat` wraps connectChat, renders the shared Chat component with a Vue pragma (createElement/Fragment/memo/useState), drives streaming autoscroll via `createStickToBottom` with the Vue hooks, and maps the connector render state to the Chat props (header/messages/prompt/suggestions). - `AisChatTrigger` wraps connectChatTrigger (the `.ais-ChatToggleButton`). - Vue SearchIndexTool + DisplayResultsTool wrappers render results in `AisCarousel`; `createDefaultTools` maps the six tool types. Tests: component tests cover open-via-trigger, prompt submit -> sendMessage, message rendering, and the carousel tool. The shared common suite stays skipped pending an extension of its `vue` widgetParams variant (which must carry a `chat` instance + options). Validated on Vue 2 and Vue 3. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Not up to standards ⛔🔴 Issues
|
| Category | Results |
|---|---|
| Security | 1 critical |
🟢 Metrics 77 complexity
Metric Results Complexity 77
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: |
There was a problem hiding this comment.
Pull request overview
Ports the Chat and ChatTrigger widgets to vue-instantsearch, leveraging the existing Vue hook-runtime + react-compat infrastructure to render shared instantsearch-ui-components chat UI, and adds Vue-side tool renderers that reuse AisCarousel.
Changes:
- Export and implement
AisChatandAisChatTriggerin Vue, wiring them toconnectChat/connectChatTrigger. - Extend Vue react-compat + hooks runtime to support callback refs and a
memohook (identity passthrough for now). - Add Vue chat tool layout components (SearchIndex/Recommend carousel + DisplayResults) and component-level tests; adjust bundlesize thresholds.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/vue-instantsearch/src/widgets.js | Exposes AisChat / AisChatTrigger from the public Vue entrypoints. |
| packages/vue-instantsearch/src/util/vue-compat/index-vue3.js | Adds Vue 3 support for callback refs and mutable refs via toVueRef. |
| packages/vue-instantsearch/src/util/vue-compat/index-vue2.js | Adds Vue 2 support for callback refs via vnode lifecycle hooks. |
| packages/vue-instantsearch/src/util/hooks.js | Adds memo to the hooks runtime (identity passthrough). |
| packages/vue-instantsearch/src/components/ChatTrigger.js | Implements the Vue AisChatTrigger wrapper around the shared ChatToggleButton UI. |
| packages/vue-instantsearch/src/components/chat/tools/SearchIndexTool.js | Adds Vue carousel-based tool layout for search/recommend tool messages. |
| packages/vue-instantsearch/src/components/chat/tools/index.js | Defines Vue createDefaultTools mapping tool types to tool implementations. |
| packages/vue-instantsearch/src/components/chat/tools/DisplayResultsTool.js | Adds Vue layout for display-results tool messages (grouped carousels). |
| packages/vue-instantsearch/src/components/Chat.js | Implements the Vue AisChat widget wrapper (hooks-driven UI + stick-to-bottom). |
| packages/vue-instantsearch/src/components/Carousel.js | Extends Vue AisCarousel to accept header/navigation/icon overrides needed by chat tools. |
| packages/vue-instantsearch/src/components/tests/Chat.js | Adds component tests covering open-via-trigger, prompt submit, seeded messages, carousel rendering. |
| packages/vue-instantsearch/src/tests/index.js | Updates export validation and minimal-props mounting for new widgets. |
| packages/vue-instantsearch/src/tests/common-widgets.test.js | Adds Vue wiring for chat in common widgets harness while keeping the shared suite skipped. |
| bundlesize.config.json | Raises Vue bundlesize thresholds to account for chat UI additions. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return h(ChatToggleButton, { | ||
| open: this.state.open, | ||
| onClick: () => this.state.toggleOpen(), | ||
| classNames: rootClassName ? { root: rootClassName } : undefined, | ||
| }); |
There was a problem hiding this comment.
Done in c1c923c — passing the (connector-bound) toggleOpen directly.
— via Claude
| if ( | ||
| getSearchPageURL && | ||
| new URL(getSearchPageURL(params)).pathname !== | ||
| window.location.pathname | ||
| ) { | ||
| window.location.href = getSearchPageURL(params); | ||
| } |
There was a problem hiding this comment.
Done in c1c923c — getSearchPageURL(params) is now computed once and reused.
— via Claude
- SearchIndexTool: compute getSearchPageURL(params) once instead of twice. - ChatTrigger: pass the bound toggleOpen handler directly. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
CI notes
🤖 Generated with Claude Code |
Stacked on #7127 (base =
feat/vue-related-products) — it reuses that PR's hook-based infra +AisCarousel.What
Ports the Chat and ChatTrigger widgets to
vue-instantsearch— the last major widget missing from Vue. It reuses thecreateHooksStore+renderReactCompatinfrastructure andAisCarouselfrom the recommend port, and consumes the same framework-agnosticinstantsearch.jschat runtime (connectChat/connectChatTrigger,ai-lite) the React/JS widgets use — no new runtime deps.Infra
memoon the hooks runtime (identity passthrough — see follow-ups).ChatPrompt's callback ref.AisCarouselgainsheaderComponent/showNavigation/icon props for the chat tools.Widgets
AisChat— wrapsconnectChat, renders the sharedcreateChatComponentwith a Vue pragma (createElement/Fragment/memo/useState), drives streaming autoscroll viacreateStickToBottomwith the Vue hooks, and maps the connector render state to the Chat props.AisChatTrigger— wrapsconnectChatTrigger(.ais-ChatToggleButton).AisCarousel;createDefaultToolsmaps the six tool types.Test plan
components/__tests__/Chat.js): open-via-trigger, prompt submit →sendMessage, pre-seeded message rendering, and the search-tool carousel. Green on Vue 2 and Vue 3.AisChat/AisChatTrigger.vue-instantsearchsuite green on both versions; oxlint + prettier clean; Vue bundlesize thresholds bumped (Chat pulls in the chat UI +markdown-to-jsx, ~+30 kB UMD).Scope / follow-ups (phase 2)
vuewidgetParams variant isRecord<string, never>and the tests drive a test-ownedchatinstance that only reaches the JS/React widgets. Enabling it for Vue needs that variant extended to carry achatinstance + options — a change to the sharedtests/common/widgets/chat/*files. Component tests cover the core behavior in the meantime.memois an identity passthrough, so completed messages re-render on each streaming delta (correct output, not yet optimized). A real per-key memo is deferred.connectChatemits a runtime "Chat is not yet stable" warning — the API is explicitly unstable upstream.Draft, stacked.
🤖 Generated with Claude Code