Skip to content

Commit 4a672ae

Browse files
author
vvo
committed
fix(urlSync): only start watching for changes at first render
Before this commit, if one of the widget was making helper changes in his init(), we would trigger a change event that would update the url. What we want is that everything done before the first render should be considered as start configuration and not synced into the url UNLESS there are new differences (user changes the query). It also fixed a nasty IE10/11 bug where the input event would be triggered as soon as a placeholder is set into the DOM or programmatically.
1 parent 22b5a83 commit 4a672ae

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

src/lib/InstantSearch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Usage: instantsearch({
135135

136136
if (this.urlSync) {
137137
helper.setState(enhanceConfiguration(helper.state, syncWidget));
138-
syncWidget.init({helper});
138+
this.widgets.push(syncWidget);
139139
}
140140

141141
helper.on('result', this._render.bind(this, helper));

src/lib/__tests__/InstantSearch-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('InstantSearch lifecycle', () => {
4343
createURL: sinon.spy(),
4444
onHistoryChange: () => {},
4545
getConfiguration: sinon.spy(),
46-
init: () => {}
46+
render: () => {}
4747
};
4848

4949
algoliasearch = sinon.stub().returns(client);

src/lib/url-sync.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import merge from 'lodash/object/merge';/**/
66

77
let AlgoliaSearchHelper = algoliasearchHelper.AlgoliaSearchHelper;
88
let majorVersionNumber = version.split('.')[0];
9+
let firstRender = true;
910

1011
function timerMaker(t0) {
1112
let t = t0;
@@ -103,11 +104,12 @@ class URLSync {
103104
return config;
104105
}
105106

106-
init({helper}) {
107-
helper.on('change', (state) => {
108-
this.renderURLFromState(state);
109-
});
110-
this.onHistoryChange(this.onPopState.bind(this, helper));
107+
render({helper}) {
108+
if (firstRender) {
109+
firstRender = false;
110+
this.onHistoryChange(this.onPopState.bind(this, helper));
111+
helper.on('change', state => this.renderURLFromState(state));
112+
}
111113
}
112114

113115
onPopState(helper, fullState) {

0 commit comments

Comments
 (0)