Skip to content

feat(helper): support multifeed composition responses#6954

Open
e-krebs wants to merge 7 commits intofeat/composition-multifeedfrom
feat/composition-multifeed-layer1-helper
Open

feat(helper): support multifeed composition responses#6954
e-krebs wants to merge 7 commits intofeat/composition-multifeedfrom
feat/composition-multifeed-layer1-helper

Conversation

@e-krebs
Copy link
Copy Markdown
Contributor

@e-krebs e-krebs commented Apr 8, 2026

Summary

  • Omit queriesCount from composition state entries in _runComposition; in _dispatchAlgoliaResponse, use results directly when queriesCount is undefined (composition path) instead of splicing
  • Build lastResults.feeds as an ordered CompositionSearchResults[] array in _dispatchAlgoliaResponse when the response contains feedIDs
  • Add CompositionSearchResults interface (extends SearchResults with feedID: string) and feeds?: CompositionSearchResults[] on SearchResults class
  • lastResults points to feeds[0] — feeds live on SearchResults so they survive the SSR getInitialResults → JSON → hydration round-trip naturally

This is Layer 1 of the multifeed composition RFC. Layer 2 (connector) will consume results.feeds to route per-feed results to distinct widget trees.
EMERCH-2612

Test plan

  • New unit tests in packages/algoliasearch-helper/test/spec/algoliasearch.helper/composition.js (8 tests)
  • Full helper test suite passes (yarn workspace algoliasearch-helper test — 456 tests)
  • Full monorepo test suite passes (yarn test)
  • No lint or type-check regressions in helper package

🤖 Generated with Claude Code

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>
@codacy-production
Copy link
Copy Markdown

codacy-production bot commented Apr 8, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 49 complexity · 22 duplication

Metric Results
Complexity 49
Duplication 22

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 8, 2026

More templates

algoliasearch-helper

npm i https://pkg.pr.new/algolia/instantsearch/algoliasearch-helper@6954

instantsearch-ui-components

npm i https://pkg.pr.new/algolia/instantsearch/instantsearch-ui-components@6954

instantsearch.css

npm i https://pkg.pr.new/algolia/instantsearch/instantsearch.css@6954

instantsearch.js

npm i https://pkg.pr.new/algolia/instantsearch/instantsearch.js@6954

react-instantsearch

npm i https://pkg.pr.new/algolia/instantsearch/react-instantsearch@6954

react-instantsearch-core

npm i https://pkg.pr.new/algolia/instantsearch/react-instantsearch-core@6954

react-instantsearch-nextjs

npm i https://pkg.pr.new/algolia/instantsearch/react-instantsearch-nextjs@6954

react-instantsearch-router-nextjs

npm i https://pkg.pr.new/algolia/instantsearch/react-instantsearch-router-nextjs@6954

vue-instantsearch

npm i https://pkg.pr.new/algolia/instantsearch/vue-instantsearch@6954

commit: ec3854e

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@e-krebs e-krebs requested review from a team, aymeric-giraudet and shaejaz and removed request for a team April 8, 2026 14:23
e-krebs and others added 2 commits April 8, 2026 18:40
…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>
@e-krebs e-krebs requested a review from Haroenv April 8, 2026 17:05
Copy link
Copy Markdown
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good start, of course pretty hypothetical still here

Comment on lines +1905 to +1906
helper.lastResults._feedResults = feedResults;
helper.lastResults._feedOrder = feedOrder;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed I went with helper.lastResults.feeds so that feeds are automatically serialised when SSR

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@e-krebs e-krebs force-pushed the feat/composition-multifeed-layer1-helper branch from 44d1552 to 46ee2b1 Compare April 9, 2026 10:05
Copy link
Copy Markdown
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Copy link
Copy Markdown
Contributor

@Haroenv Haroenv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Co-authored-by: Haroen Viaene <hello@haroen.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants