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

fix(ssr): fix missing scopedResults during render #830

Merged
merged 1 commit into from
Aug 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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),
Copy link
Member

Choose a reason for hiding this comment

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

Why don't we assert actual values?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since most of the values are coming from the test itself or from mocks then we are just checking the shape of the RenderOptions object, not its actual values.

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