feat(helper): support multifeed composition responses#6954
feat(helper): support multifeed composition responses#6954e-krebs wants to merge 7 commits intofeat/composition-multifeedfrom
Conversation
Compositions can return multiple result sets (feeds), each identified by a `feedID`. Previously, `_runComposition` spliced only 1 result per derived helper, discarding additional feeds. This changes `queriesCount` to `Infinity` so all feeds are captured, and builds a `_feedResults` map and `_feedOrder` array on the primary `SearchResults` for downstream consumption by `connectFeeds` (Layer 2). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 49 |
| Duplication | 22 |
TIP This summary will be updated as you push new changes. Give us feedback
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: |
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…Infinity Use undefined queriesCount to signal "take all results" in _dispatchAlgoliaResponse, avoiding the Infinity hack. When queriesCount is undefined (composition path), use results directly; when defined (regular search path), splice as before. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The feedID, _feedResults, and _feedOrder type definitions have no consumers yet. Defer the typing decision (interface vs class, naming) to Layer 2 when connectFeeds introduces the first consumer. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Haroenv
left a comment
There was a problem hiding this comment.
good start, of course pretty hypothetical still here
| helper.lastResults._feedResults = feedResults; | ||
| helper.lastResults._feedOrder = feedOrder; |
There was a problem hiding this comment.
I'm not overly sold on putting this behind _ keys that we then need to explicitly handle in the implementation. It's ok bu have you considered helper.feeds = feedResults (as an array) directly? then still setting lastResults to the main one. that way it feels like more of a proper implementation rather than an add on.
also why is there the results and the order needed separately? could it be just a single array that in case you have a feature of displaying just a single feed it just does find in the array.
There was a problem hiding this comment.
as discussed I went with helper.lastResults.feeds so that feeds are automatically serialised when SSR
There was a problem hiding this comment.
since its now one property only I added back feeds on to SearchResults (with dedicated extended typing).
let me know if that works for you
… map Replace _feedResults (Record<string, SearchResults>) and _feedOrder (string[]) with a single lastResults.feeds (CompositionSearchResults[]) ordered array. This simplifies the API and ensures feeds survive the SSR getInitialResults → JSON → hydration round-trip naturally. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
44d1552 to
46ee2b1
Compare
Haroenv
left a comment
There was a problem hiding this comment.
this works, thanks! let's merge it once all the PRs are ready though, in case we want to make changes when we implement the other parts
Create a separate SearchResults instance for lastResults instead of reusing feeds[0], which caused circular references during JSON.stringify (lastResults.feeds[0] === lastResults). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Haroen Viaene <hello@haroen.me>
Summary
queriesCountfrom composition state entries in_runComposition; in_dispatchAlgoliaResponse, useresultsdirectly whenqueriesCountisundefined(composition path) instead of splicinglastResults.feedsas an orderedCompositionSearchResults[]array in_dispatchAlgoliaResponsewhen the response containsfeedIDsCompositionSearchResultsinterface (extendsSearchResultswithfeedID: string) andfeeds?: CompositionSearchResults[]onSearchResultsclasslastResultspoints tofeeds[0]— feeds live onSearchResultsso they survive the SSRgetInitialResults→ JSON → hydration round-trip naturallyThis is Layer 1 of the multifeed composition RFC. Layer 2 (connector) will consume
results.feedsto route per-feed results to distinct widget trees.EMERCH-2612
Test plan
packages/algoliasearch-helper/test/spec/algoliasearch.helper/composition.js(8 tests)yarn workspace algoliasearch-helper test— 456 tests)yarn test)🤖 Generated with Claude Code