Skip to content

Commit

Permalink
fix(ssr): correctly pass scopedResults.results (algolia/vue-instantse…
Browse files Browse the repository at this point in the history
…arch#943)

* fix(ssr): correctly pass scopedResults.results

We retrieve the scoped results from the parent index in the initial render on server & client, however since the index widget doesn't have its results from a search query yet, `getResults` (used inside getScopedResults) will be `null` (derivedHelper && derivedHelper.lastResults).

The solution is to augment the retrieved scoped results with the actual search results from __initialResults, like done for `results`.

fixes algolia/vue-instantsearch#940

* compat
  • Loading branch information
Haroenv authored Mar 31, 2021
1 parent af77426 commit 387fd31
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -718,35 +718,35 @@ Array [

expect(renderArgs).toMatchInlineSnapshot(
{
helper: expect.any(Object),
results: expect.any(Object),
helper: expect.anything(),
results: expect.anything(),
scopedResults: expect.arrayContaining([
expect.objectContaining({
helper: expect.any(Object),
helper: expect.anything(),
indexId: expect.any(String),
results: expect.any(Object),
results: expect.anything(),
}),
]),
state: expect.any(Object),
instantSearchInstance: expect.any(Object),
state: expect.anything(),
instantSearchInstance: expect.anything(),
},
`
Object {
"createURL": [Function],
"helper": Any<Object>,
"instantSearchInstance": Any<Object>,
"results": Any<Object>,
"helper": Anything,
"instantSearchInstance": Anything,
"results": Anything,
"scopedResults": ArrayContaining [
ObjectContaining {
"helper": Any<Object>,
"helper": Anything,
"indexId": Any<String>,
"results": Any<Object>,
"results": Anything,
},
],
"searchMetadata": Object {
"isSearchStalled": false,
},
"state": Any<Object>,
"state": Anything,
"templatesConfig": Object {},
}
`
Expand Down
6 changes: 5 additions & 1 deletion packages/vue-instantsearch/src/util/createServerRootMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ function augmentInstantSearch(
widget.render({
helper: localHelper,
results,
scopedResults: parent.getScopedResults(),
scopedResults: parent.getScopedResults().map(result =>
Object.assign(result, {
results: search.__initialSearchResults[result.indexId],
})
),
state,
templatesConfig: {},
createURL: parent.createURL,
Expand Down

0 comments on commit 387fd31

Please sign in to comment.