Skip to content

Commit b0f0cf1

Browse files
authored
fix(urlSync): update url only after threshold (#1917)
Before this commit, our default implementation tried to update the url at every character. This led to many slowdown reports from users of the library. Now we only update the url after the threshold fixes #1856
1 parent 19756c3 commit b0f0cf1

File tree

1 file changed

+0
-19
lines changed

1 file changed

+0
-19
lines changed

src/lib/url-sync.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ function timerMaker(t0) {
2323
* @property {string} character the character used in the url
2424
* @property {function} onpopstate add an event listener for the URL change
2525
* @property {function} pushState creates a new entry in the browser history
26-
* @property {function} replaceState update the current entry of the browser history
2726
* @property {function} readUrl reads the query string of the parameters
2827
*/
2928

@@ -39,9 +38,6 @@ const hashUrlUtils = {
3938
pushState(qs) {
4039
window.location.assign(getFullURL(this.createURL(qs)));
4140
},
42-
replaceState(qs) {
43-
window.location.replace(getFullURL(this.createURL(qs)));
44-
},
4541
createURL(qs) {
4642
return window.location.search + this.character + qs;
4743
},
@@ -62,9 +58,6 @@ const modernUrlUtils = {
6258
pushState(qs, {getHistoryState}) {
6359
window.history.pushState(getHistoryState(), '', getFullURL(this.createURL(qs)));
6460
},
65-
replaceState(qs, {getHistoryState}) {
66-
window.history.replaceState(getHistoryState(), '', getFullURL(this.createURL(qs)));
67-
},
6861
createURL(qs) {
6962
return this.character + qs + document.location.hash;
7063
},
@@ -95,9 +88,6 @@ class URLSync {
9588
this.mapping = options.mapping || {};
9689
this.getHistoryState = options.getHistoryState || (() => null);
9790
this.threshold = options.threshold || 700;
98-
this.updateOnEveryKeyStroke = options.updateOnEveryKeyStroke !== undefined ?
99-
options.updateOnEveryKeyStroke :
100-
true;
10191
this.trackedParameters = options.trackedParameters || ['query', 'attribute:*', 'index', 'page', 'hitsPerPage'];
10292

10393
this.searchParametersFromUrl = AlgoliaSearchHelper
@@ -154,15 +144,6 @@ class URLSync {
154144
}
155145
);
156146

157-
if (this.updateOnEveryKeyStroke === true) {
158-
if (this.timer() < this.threshold) {
159-
this.urlUtils.replaceState(qs, {getHistoryState: this.getHistoryState});
160-
} else {
161-
this.urlUtils.pushState(qs, {getHistoryState: this.getHistoryState});
162-
}
163-
return;
164-
}
165-
166147
clearTimeout(this.urlUpdateTimeout);
167148
this.urlUpdateTimeout = setTimeout(() => {
168149
this.urlUtils.pushState(qs, {getHistoryState: this.getHistoryState});

0 commit comments

Comments
 (0)