Skip to content

Commit

Permalink
fix(url-sync): adds indexName in the helper configuration
Browse files Browse the repository at this point in the history
This solves a bug found using safari and that may or may not
break an implementation based on InstantSearch.

Safari triggers a pop state event on load, which triggers a new
search. But at this point the index is not in the initial
configuration, so this search will fail with a 400, indexName not
valid.

With this fix the value for the index name is taken from the parameters
and its value is added to the initial search configuration.
  • Loading branch information
Alexandre Stanislawski committed Dec 10, 2015
1 parent b5db072 commit e50bafd
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/Hits.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Hits extends React.Component {
}

renderNoResults() {
let className = `${this.props.cssClasses.root} ${this.props.cssClasses.empty}`;
let className = this.props.cssClasses.root + ' ' + this.props.cssClasses.empty;
return (
<Template
cssClass={className}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/InstantSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Usage: instantsearch({
this.client = client;
this.helper = null;
this.indexName = indexName;
this.searchParameters = searchParameters || {};
this.searchParameters = {...searchParameters, index: indexName};
this.widgets = [];
this.templatesConfig = {
helpers: require('./helpers.js')({numberLocale}),
Expand Down
4 changes: 2 additions & 2 deletions src/lib/__tests__/InstantSearch-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('InstantSearch lifecycle', () => {
apiKey = 'apiKey';
indexName = 'lifeycle';

searchParameters = {some: 'configuration', values: [-2, -1], another: {config: 'parameter'}};
searchParameters = {some: 'configuration', values: [-2, -1], index: indexName, another: {config: 'parameter'}};

InstantSearch.__Rewire__('algoliasearch', algoliasearch);
InstantSearch.__Rewire__('algoliasearchHelper', algoliasearchHelper);
Expand Down Expand Up @@ -113,7 +113,7 @@ describe('InstantSearch lifecycle', () => {
.toEqual([
client,
indexName,
{some: 'modified', values: [-2, -1], another: {different: 'parameter', config: 'parameter'}}
{some: 'modified', values: [-2, -1], index: indexName, another: {different: 'parameter', config: 'parameter'}}
]);
});

Expand Down

0 comments on commit e50bafd

Please sign in to comment.