instantsearch.js 4.40.4 → 4.40.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -47,10 +47,9 @@ declare class BrowserHistory<TRouteState> implements Router<TRouteState> {
47
47
  private writeTimer?;
48
48
  private _onPopState;
49
49
  /**
50
- * Indicates if history.pushState should be executed.
51
- * It needs to avoid pushing state to history in case of back/forward in browser
50
+ * Indicates if last action was back/forward in the browser.
52
51
  */
53
- private shouldPushState;
52
+ private inPopState;
54
53
  /**
55
54
  * Indicates whether the history router is disposed or not.
56
55
  */
@@ -92,6 +91,7 @@ declare class BrowserHistory<TRouteState> implements Router<TRouteState> {
92
91
  * Removes the event listener and cleans up the URL.
93
92
  */
94
93
  dispose(): void;
94
+ private shouldWrite;
95
95
  }
96
96
  export default function historyRouter<TRouteState = UiState>({ createURL, parseURL, writeDelay, windowTitle, getLocation, }?: Partial<BrowserHistoryArgs<TRouteState>>): BrowserHistory<TRouteState>;
97
97
  export {};
@@ -46,7 +46,7 @@ var BrowserHistory = /*#__PURE__*/function () {
46
46
 
47
47
  _defineProperty(this, "writeTimer", void 0);
48
48
 
49
- _defineProperty(this, "shouldPushState", true);
49
+ _defineProperty(this, "inPopState", false);
50
50
 
51
51
  _defineProperty(this, "isDisposed", false);
52
52
 
@@ -101,20 +101,14 @@ var BrowserHistory = /*#__PURE__*/function () {
101
101
  }
102
102
 
103
103
  _this2.writeTimer = setTimeout(function () {
104
- setWindowTitle(title); // We do want to `pushState` if:
105
- // - the router is not disposed, IS.js needs to update the URL
106
- // OR
107
- // - the last write was from InstantSearch.js
108
- // (unlike a SPA, where it would have last written)
104
+ setWindowTitle(title);
109
105
 
110
- var lastPushWasByISAfterDispose = !_this2.isDisposed || _this2.latestAcknowledgedHistory === window.history.length;
111
-
112
- if (_this2.shouldPushState && lastPushWasByISAfterDispose) {
106
+ if (_this2.shouldWrite(url)) {
113
107
  window.history.pushState(routeState, title || '', url);
114
108
  _this2.latestAcknowledgedHistory = window.history.length;
115
109
  }
116
110
 
117
- _this2.shouldPushState = true;
111
+ _this2.inPopState = false;
118
112
  _this2.writeTimer = undefined;
119
113
  }, _this2.writeDelay);
120
114
  });
@@ -135,7 +129,7 @@ var BrowserHistory = /*#__PURE__*/function () {
135
129
  _this3.writeTimer = undefined;
136
130
  }
137
131
 
138
- _this3.shouldPushState = false;
132
+ _this3.inPopState = true;
139
133
  var routeState = event.state; // At initial load, the state is read from the URL without update.
140
134
  // Therefore the state object is not available.
141
135
  // In this case, we fallback and read the URL.
@@ -193,18 +187,39 @@ var BrowserHistory = /*#__PURE__*/function () {
193
187
 
194
188
  this.write({});
195
189
  }
190
+ }, {
191
+ key: "shouldWrite",
192
+ value: function shouldWrite(url) {
193
+ var _this5 = this;
194
+
195
+ return safelyRunOnBrowser(function (_ref6) {
196
+ var window = _ref6.window;
197
+ // We do want to `pushState` if:
198
+ // - the router is not disposed, IS.js needs to update the URL
199
+ // OR
200
+ // - the last write was from InstantSearch.js
201
+ // (unlike a SPA, where it would have last written)
202
+ var lastPushWasByISAfterDispose = !(_this5.isDisposed && _this5.latestAcknowledgedHistory !== window.history.length);
203
+ return (// When the last state change was through popstate, the IS.js state changes,
204
+ // but that should not write the URL.
205
+ !_this5.inPopState && // When the previous pushState after dispose was by IS.js, we want to write the URL.
206
+ lastPushWasByISAfterDispose && // When the URL is the same as the current one, we do not want to write it.
207
+ url !== window.location.href
208
+ );
209
+ });
210
+ }
196
211
  }]);
197
212
 
198
213
  return BrowserHistory;
199
214
  }();
200
215
 
201
216
  export default function historyRouter() {
202
- var _ref6 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
203
- _ref6$createURL = _ref6.createURL,
204
- createURL = _ref6$createURL === void 0 ? function (_ref7) {
205
- var qsModule = _ref7.qsModule,
206
- routeState = _ref7.routeState,
207
- location = _ref7.location;
217
+ var _ref7 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
218
+ _ref7$createURL = _ref7.createURL,
219
+ createURL = _ref7$createURL === void 0 ? function (_ref8) {
220
+ var qsModule = _ref8.qsModule,
221
+ routeState = _ref8.routeState,
222
+ location = _ref8.location;
208
223
  var protocol = location.protocol,
209
224
  hostname = location.hostname,
210
225
  _location$port = location.port,
@@ -220,11 +235,11 @@ export default function historyRouter() {
220
235
  }
221
236
 
222
237
  return "".concat(protocol, "//").concat(hostname).concat(portWithPrefix).concat(pathname, "?").concat(queryString).concat(hash);
223
- } : _ref6$createURL,
224
- _ref6$parseURL = _ref6.parseURL,
225
- parseURL = _ref6$parseURL === void 0 ? function (_ref8) {
226
- var qsModule = _ref8.qsModule,
227
- location = _ref8.location;
238
+ } : _ref7$createURL,
239
+ _ref7$parseURL = _ref7.parseURL,
240
+ parseURL = _ref7$parseURL === void 0 ? function (_ref9) {
241
+ var qsModule = _ref9.qsModule,
242
+ location = _ref9.location;
228
243
  // `qs` by default converts arrays with more than 20 items to an object.
229
244
  // We want to avoid this because the data structure manipulated can therefore vary.
230
245
  // Setting the limit to `100` seems a good number because the engine's default is 100
@@ -238,21 +253,21 @@ export default function historyRouter() {
238
253
  return qsModule.parse(location.search.slice(1), {
239
254
  arrayLimit: 99
240
255
  });
241
- } : _ref6$parseURL,
242
- _ref6$writeDelay = _ref6.writeDelay,
243
- writeDelay = _ref6$writeDelay === void 0 ? 400 : _ref6$writeDelay,
244
- windowTitle = _ref6.windowTitle,
245
- _ref6$getLocation = _ref6.getLocation,
246
- getLocation = _ref6$getLocation === void 0 ? function () {
247
- return safelyRunOnBrowser(function (_ref9) {
248
- var window = _ref9.window;
256
+ } : _ref7$parseURL,
257
+ _ref7$writeDelay = _ref7.writeDelay,
258
+ writeDelay = _ref7$writeDelay === void 0 ? 400 : _ref7$writeDelay,
259
+ windowTitle = _ref7.windowTitle,
260
+ _ref7$getLocation = _ref7.getLocation,
261
+ getLocation = _ref7$getLocation === void 0 ? function () {
262
+ return safelyRunOnBrowser(function (_ref10) {
263
+ var window = _ref10.window;
249
264
  return window.location;
250
265
  }, {
251
266
  fallback: function fallback() {
252
267
  throw new Error('You need to provide `getLocation` to the `history` router in environments where `window` does not exist.');
253
268
  }
254
269
  });
255
- } : _ref6$getLocation;
270
+ } : _ref7$getLocation;
256
271
 
257
272
  return new BrowserHistory({
258
273
  createURL: createURL,
@@ -1,2 +1,2 @@
1
- declare const _default: "4.40.4";
1
+ declare const _default: "4.40.5";
2
2
  export default _default;
package/es/lib/version.js CHANGED
@@ -1 +1 @@
1
- export default '4.40.4';
1
+ export default '4.40.5';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instantsearch.js",
3
- "version": "4.40.4",
3
+ "version": "4.40.5",
4
4
  "description": "InstantSearch.js is a JavaScript library for building performant and instant search experiences with Algolia.",
5
5
  "homepage": "https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/js/",
6
6
  "types": "es/index.d.ts",