instantsearch.js 4.38.0 → 4.38.1

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.
@@ -51,6 +51,17 @@ declare class BrowserHistory<TRouteState> implements Router<TRouteState> {
51
51
  * It needs to avoid pushing state to history in case of back/forward in browser
52
52
  */
53
53
  private shouldPushState;
54
+ /**
55
+ * Indicates whether the history router is disposed or not.
56
+ */
57
+ private isDisposed;
58
+ /**
59
+ * Indicates the window.history.length before the last call to
60
+ * window.history.pushState (called in `write`).
61
+ * It allows to determine if a `pushState` has been triggered elsewhere,
62
+ * and thus to prevent the `write` method from calling `pushState`.
63
+ */
64
+ private latestAcknowledgedHistory;
54
65
  /**
55
66
  * Initializes a new storage provider that syncs the search state to the URL
56
67
  * using web APIs (`window.location.pushState` and `onpopstate` event).
@@ -48,16 +48,23 @@ var BrowserHistory = /*#__PURE__*/function () {
48
48
 
49
49
  _defineProperty(this, "shouldPushState", true);
50
50
 
51
+ _defineProperty(this, "isDisposed", false);
52
+
53
+ _defineProperty(this, "latestAcknowledgedHistory", 0);
54
+
51
55
  this.windowTitle = windowTitle;
52
56
  this.writeTimer = undefined;
53
57
  this.writeDelay = writeDelay;
54
58
  this._createURL = createURL;
55
59
  this.parseURL = parseURL;
56
60
  this.getLocation = getLocation;
57
- safelyRunOnBrowser(function () {
61
+ safelyRunOnBrowser(function (_ref2) {
62
+ var window = _ref2.window;
63
+
58
64
  var title = _this.windowTitle && _this.windowTitle(_this.read());
59
65
 
60
66
  setWindowTitle(title);
67
+ _this.latestAcknowledgedHistory = window.history.length;
61
68
  });
62
69
  }
63
70
  /**
@@ -82,8 +89,8 @@ var BrowserHistory = /*#__PURE__*/function () {
82
89
  value: function write(routeState) {
83
90
  var _this2 = this;
84
91
 
85
- safelyRunOnBrowser(function (_ref2) {
86
- var window = _ref2.window;
92
+ safelyRunOnBrowser(function (_ref3) {
93
+ var window = _ref3.window;
87
94
 
88
95
  var url = _this2.createURL(routeState);
89
96
 
@@ -94,10 +101,17 @@ var BrowserHistory = /*#__PURE__*/function () {
94
101
  }
95
102
 
96
103
  _this2.writeTimer = setTimeout(function () {
97
- setWindowTitle(title);
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)
109
+
110
+ var lastPushWasByISAfterDispose = !_this2.isDisposed || _this2.latestAcknowledgedHistory === window.history.length;
98
111
 
99
- if (_this2.shouldPushState) {
112
+ if (_this2.shouldPushState && lastPushWasByISAfterDispose) {
100
113
  window.history.pushState(routeState, title || '', url);
114
+ _this2.latestAcknowledgedHistory = window.history.length;
101
115
  }
102
116
 
103
117
  _this2.shouldPushState = true;
@@ -133,8 +147,8 @@ var BrowserHistory = /*#__PURE__*/function () {
133
147
  }
134
148
  };
135
149
 
136
- safelyRunOnBrowser(function (_ref3) {
137
- var window = _ref3.window;
150
+ safelyRunOnBrowser(function (_ref4) {
151
+ var window = _ref4.window;
138
152
  window.addEventListener('popstate', _this3._onPopState);
139
153
  });
140
154
  }
@@ -164,8 +178,9 @@ var BrowserHistory = /*#__PURE__*/function () {
164
178
  value: function dispose() {
165
179
  var _this4 = this;
166
180
 
167
- safelyRunOnBrowser(function (_ref4) {
168
- var window = _ref4.window;
181
+ this.isDisposed = true;
182
+ safelyRunOnBrowser(function (_ref5) {
183
+ var window = _ref5.window;
169
184
 
170
185
  if (_this4._onPopState) {
171
186
  window.removeEventListener('popstate', _this4._onPopState);
@@ -184,12 +199,12 @@ var BrowserHistory = /*#__PURE__*/function () {
184
199
  }();
185
200
 
186
201
  export default function historyRouter() {
187
- var _ref5 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
188
- _ref5$createURL = _ref5.createURL,
189
- createURL = _ref5$createURL === void 0 ? function (_ref6) {
190
- var qsModule = _ref6.qsModule,
191
- routeState = _ref6.routeState,
192
- location = _ref6.location;
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;
193
208
  var protocol = location.protocol,
194
209
  hostname = location.hostname,
195
210
  _location$port = location.port,
@@ -205,11 +220,11 @@ export default function historyRouter() {
205
220
  }
206
221
 
207
222
  return "".concat(protocol, "//").concat(hostname).concat(portWithPrefix).concat(pathname, "?").concat(queryString).concat(hash);
208
- } : _ref5$createURL,
209
- _ref5$parseURL = _ref5.parseURL,
210
- parseURL = _ref5$parseURL === void 0 ? function (_ref7) {
211
- var qsModule = _ref7.qsModule,
212
- location = _ref7.location;
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;
213
228
  // `qs` by default converts arrays with more than 20 items to an object.
214
229
  // We want to avoid this because the data structure manipulated can therefore vary.
215
230
  // Setting the limit to `100` seems a good number because the engine's default is 100
@@ -223,21 +238,21 @@ export default function historyRouter() {
223
238
  return qsModule.parse(location.search.slice(1), {
224
239
  arrayLimit: 99
225
240
  });
226
- } : _ref5$parseURL,
227
- _ref5$writeDelay = _ref5.writeDelay,
228
- writeDelay = _ref5$writeDelay === void 0 ? 400 : _ref5$writeDelay,
229
- windowTitle = _ref5.windowTitle,
230
- _ref5$getLocation = _ref5.getLocation,
231
- getLocation = _ref5$getLocation === void 0 ? function () {
232
- return safelyRunOnBrowser(function (_ref8) {
233
- var window = _ref8.window;
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;
234
249
  return window.location;
235
250
  }, {
236
251
  fallback: function fallback() {
237
252
  throw new Error('You need to provide `getLocation` to the `history` router in environments where `window` does not exist.');
238
253
  }
239
254
  });
240
- } : _ref5$getLocation;
255
+ } : _ref6$getLocation;
241
256
 
242
257
  return new BrowserHistory({
243
258
  createURL: createURL,
@@ -1,2 +1,2 @@
1
- declare const _default: "4.38.0";
1
+ declare const _default: "4.38.1";
2
2
  export default _default;
package/es/lib/version.js CHANGED
@@ -1 +1 @@
1
- export default '4.38.0';
1
+ export default '4.38.1';
@@ -46,8 +46,10 @@ function extractPayload(widgets, instantSearchInstance, payload) {
46
46
 
47
47
  export function isMetadataEnabled() {
48
48
  return safelyRunOnBrowser(function (_ref) {
49
+ var _window$navigator, _window$navigator$use;
50
+
49
51
  var window = _ref.window;
50
- return window.navigator.userAgent.indexOf('Algolia Crawler') > -1;
52
+ return ((_window$navigator = window.navigator) === null || _window$navigator === void 0 ? void 0 : (_window$navigator$use = _window$navigator.userAgent) === null || _window$navigator$use === void 0 ? void 0 : _window$navigator$use.indexOf('Algolia Crawler')) > -1;
51
53
  }, {
52
54
  fallback: function fallback() {
53
55
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instantsearch.js",
3
- "version": "4.38.0",
3
+ "version": "4.38.1",
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",
@@ -120,7 +120,7 @@
120
120
  "eslint-plugin-prettier": "3.4.0",
121
121
  "eslint-plugin-react": "7.18.0",
122
122
  "eslint-plugin-react-hooks": "2.3.0",
123
- "instantsearch-e2e-tests": "algolia/instantsearch-e2e-tests#1.3.0",
123
+ "instantsearch-e2e-tests": "algolia/instantsearch-e2e-tests#2.0.2",
124
124
  "jest": "27.1.0",
125
125
  "jest-diff": "27.1.0",
126
126
  "jest-environment-jsdom": "27.1.0",