Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
fix(ssr): fix missing scopedResults during render (#830)
Browse files Browse the repository at this point in the history
Fixes #829
  • Loading branch information
Yannick Croissant authored Aug 6, 2020
1 parent 1358b6a commit 74cf685
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/util/__tests__/createServerRootMixin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,13 @@ Array [
{
helper: expect.any(Object),
results: expect.any(Object),
scopedResults: expect.arrayContaining([
expect.objectContaining({
helper: expect.any(Object),
indexId: expect.any(String),
results: expect.any(Object),
}),
]),
state: expect.any(Object),
instantSearchInstance: expect.any(Object),
},
Expand All @@ -423,6 +430,13 @@ Object {
"helper": Any<Object>,
"instantSearchInstance": Any<Object>,
"results": Any<Object>,
"scopedResults": ArrayContaining [
ObjectContaining {
"helper": Any<Object>,
"indexId": Any<String>,
"results": Any<Object>,
},
],
"searchMetadata": Object {
"isSearchStalled": false,
},
Expand Down
18 changes: 18 additions & 0 deletions src/util/createServerRootMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,27 @@ function augmentInstantSearch(instantSearchOptions, searchClient, indexName) {
}, {}),
});

function resolveScopedResultsFromWidgets(widgets) {
const indexWidgets = widgets.filter(w => w.$$type === 'ais.index');

return indexWidgets.reduce(
(scopedResults, current) =>
scopedResults.concat(
{
indexId: current.getIndexId(),
results: search.__initialSearchResults[current.getIndexId()],
helper: current.getHelper(),
},
...resolveScopedResultsFromWidgets(current.getWidgets())
),
[]
);
}

widget.render({
helper: localHelper,
results,
scopedResults: resolveScopedResultsFromWidgets([parent]),
state,
templatesConfig: {},
createURL,
Expand Down

0 comments on commit 74cf685

Please sign in to comment.