diff --git a/src/lib/__tests__/InstantSearch-test.js b/src/lib/__tests__/InstantSearch-test.js index 737bc19b15..b552c0532e 100644 --- a/src/lib/__tests__/InstantSearch-test.js +++ b/src/lib/__tests__/InstantSearch-test.js @@ -239,6 +239,24 @@ describe('InstantSearch', () => { expect(search.insightsClient).toBe(insightsClient); }); + + it("exposes helper's last results", async () => { + const searchClient = createSearchClient(); + + const search = new InstantSearch({ + indexName: 'indexName', + searchClient, + }); + + expect(search.helper).toBe(null); + + search.start(); + + await runAllMicroTasks(); + + // could be null if we don't pretend the main helper is the one who searched + expect(search.helper.lastResults).not.toBe(null); + }); }); describe('addWidget(s)', () => { diff --git a/src/widgets/index/index.ts b/src/widgets/index/index.ts index 5e6b81d0b4..2b1c245f7b 100644 --- a/src/widgets/index/index.ts +++ b/src/widgets/index/index.ts @@ -459,11 +459,17 @@ See https://www.algolia.com/doc/guides/building-search-ui/widgets/customize-an-e } }); - derivedHelper.on('result', () => { + derivedHelper.on('result', ({ results }) => { // The index does not render the results it schedules a new render // to let all the other indices emit their own results. It allows us to // run the render process in one pass. instantSearchInstance.scheduleRender(); + + // the derived helper is the one which actually searches, but the helper + // which is exposed e.g. via instance.helper, doesn't search, and thus + // does not have access to lastResults, which it used to in pre-federated + // search behavior. + helper!.lastResults = results; }); localWidgets.forEach(widget => {