instantsearch.js 4.31.1 → 4.33.2

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.
Files changed (39) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +22 -0
  3. package/cjs/connectors/numeric-menu/connectNumericMenu.js +6 -4
  4. package/cjs/connectors/powered-by/connectPoweredBy.js +13 -4
  5. package/cjs/lib/InstantSearch.js +4 -2
  6. package/cjs/lib/infiniteHitsCache/sessionStorage.js +16 -12
  7. package/cjs/lib/routers/history.js +89 -42
  8. package/cjs/lib/utils/detect-insights-client.js +10 -1
  9. package/cjs/lib/utils/index.js +10 -1
  10. package/cjs/lib/utils/safelyRunOnBrowser.js +30 -0
  11. package/cjs/lib/version.js +1 -1
  12. package/cjs/lib/voiceSearchHelper/index.js +5 -0
  13. package/cjs/middlewares/createMetadataMiddleware.js +12 -3
  14. package/cjs/widgets/index/index.js +1 -1
  15. package/dist/instantsearch.development.d.ts +13 -2
  16. package/dist/instantsearch.development.js +193 -78
  17. package/dist/instantsearch.development.js.map +1 -1
  18. package/dist/instantsearch.development.min.d.ts +13 -2
  19. package/dist/instantsearch.production.d.ts +13 -2
  20. package/dist/instantsearch.production.min.d.ts +13 -2
  21. package/dist/instantsearch.production.min.js +2 -2
  22. package/dist/instantsearch.production.min.js.map +1 -1
  23. package/es/connectors/numeric-menu/connectNumericMenu.js +6 -4
  24. package/es/connectors/powered-by/connectPoweredBy.js +14 -5
  25. package/es/lib/InstantSearch.js +4 -2
  26. package/es/lib/infiniteHitsCache/sessionStorage.js +17 -14
  27. package/es/lib/routers/history.d.ts +13 -2
  28. package/es/lib/routers/history.js +88 -42
  29. package/es/lib/utils/detect-insights-client.js +9 -1
  30. package/es/lib/utils/index.d.ts +1 -0
  31. package/es/lib/utils/index.js +2 -1
  32. package/es/lib/utils/safelyRunOnBrowser.d.ts +14 -0
  33. package/es/lib/utils/safelyRunOnBrowser.js +23 -0
  34. package/es/lib/version.d.ts +1 -1
  35. package/es/lib/version.js +1 -1
  36. package/es/lib/voiceSearchHelper/index.js +5 -0
  37. package/es/middlewares/createMetadataMiddleware.js +12 -3
  38. package/es/widgets/index/index.js +1 -1
  39. package/package.json +6 -6
@@ -1,4 +1,4 @@
1
- /*! InstantSearch.js 4.31.1 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch.js */
1
+ /*! InstantSearch.js 4.33.2 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch.js */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4
4
  typeof define === 'function' && define.amd ? define(factory) :
@@ -318,7 +318,10 @@
318
318
  }
319
319
 
320
320
  for (var key in source) {
321
- if (!Object.prototype.hasOwnProperty.call(source, key)) {
321
+ if (
322
+ !Object.prototype.hasOwnProperty.call(source, key) ||
323
+ key === '__proto__'
324
+ ) {
322
325
  continue;
323
326
  }
324
327
 
@@ -329,7 +332,10 @@
329
332
  continue;
330
333
  }
331
334
 
332
- if (isObjectOrArrayOrFunction(targetVal) && isObjectOrArrayOrFunction(sourceVal)) {
335
+ if (
336
+ isObjectOrArrayOrFunction(targetVal) &&
337
+ isObjectOrArrayOrFunction(sourceVal)
338
+ ) {
333
339
  target[key] = _merge(targetVal, sourceVal);
334
340
  } else {
335
341
  target[key] = clone(sourceVal);
@@ -1906,9 +1912,17 @@
1906
1912
 
1907
1913
  managedParameters: [
1908
1914
  'index',
1909
- 'facets', 'disjunctiveFacets', 'facetsRefinements',
1910
- 'facetsExcludes', 'disjunctiveFacetsRefinements',
1911
- 'numericRefinements', 'tagRefinements', 'hierarchicalFacets', 'hierarchicalFacetsRefinements'
1915
+
1916
+ 'facets',
1917
+ 'disjunctiveFacets',
1918
+ 'facetsRefinements',
1919
+ 'hierarchicalFacets',
1920
+ 'facetsExcludes',
1921
+
1922
+ 'disjunctiveFacetsRefinements',
1923
+ 'numericRefinements',
1924
+ 'tagRefinements',
1925
+ 'hierarchicalFacetsRefinements'
1912
1926
  ],
1913
1927
  getQueryParams: function getQueryParams() {
1914
1928
  var managedParameters = this.managedParameters;
@@ -3146,6 +3160,10 @@
3146
3160
  }
3147
3161
  });
3148
3162
 
3163
+ orderedFacets = orderedFacets.filter(function(facet) {
3164
+ return facet;
3165
+ });
3166
+
3149
3167
  var sortRemainingBy = facetOrdering.sortRemainingBy;
3150
3168
  var ordering;
3151
3169
  if (sortRemainingBy === 'hidden') {
@@ -3837,7 +3855,7 @@
3837
3855
  var numericFilters = requestBuilder._getNumericFilters(state);
3838
3856
  var tagFilters = requestBuilder._getTagFilters(state);
3839
3857
  var additionalParams = {
3840
- facets: facets,
3858
+ facets: facets.indexOf('*') > -1 ? ['*'] : facets,
3841
3859
  tagFilters: tagFilters
3842
3860
  };
3843
3861
 
@@ -4097,7 +4115,7 @@
4097
4115
 
4098
4116
  var requestBuilder_1 = requestBuilder;
4099
4117
 
4100
- var version = '3.5.5';
4118
+ var version = '3.6.2';
4101
4119
 
4102
4120
  /**
4103
4121
  * Event triggered when a parameter is set or updated
@@ -7891,6 +7909,30 @@
7891
7909
  return attribute;
7892
7910
  }
7893
7911
 
7912
+ // eslint-disable-next-line no-restricted-globals
7913
+
7914
+ /**
7915
+ * Runs code on browser enviromnents safely.
7916
+ */
7917
+ function safelyRunOnBrowser(callback) {
7918
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
7919
+ fallback: function fallback() {
7920
+ return undefined;
7921
+ }
7922
+ },
7923
+ fallback = _ref.fallback;
7924
+
7925
+ // eslint-disable-next-line no-restricted-globals
7926
+ if (typeof window === 'undefined') {
7927
+ return fallback();
7928
+ } // eslint-disable-next-line no-restricted-globals
7929
+
7930
+
7931
+ return callback({
7932
+ window: window
7933
+ });
7934
+ }
7935
+
7894
7936
  var withUsage = createDocumentationMessageGenerator({
7895
7937
  name: 'index-widget'
7896
7938
  });
@@ -8410,7 +8452,7 @@
8410
8452
  localUiState = getLocalWidgetsUiState(localWidgets, {
8411
8453
  searchParameters: this.getHelper().state,
8412
8454
  helper: this.getHelper()
8413
- });
8455
+ }, localUiState);
8414
8456
  }
8415
8457
  };
8416
8458
  };
@@ -8423,7 +8465,7 @@
8423
8465
  instantSearchInstance.renderState = _objectSpread2(_objectSpread2({}, instantSearchInstance.renderState), {}, _defineProperty({}, parentIndexName, _objectSpread2(_objectSpread2({}, instantSearchInstance.renderState[parentIndexName]), renderState)));
8424
8466
  }
8425
8467
 
8426
- var version$1 = '4.31.1';
8468
+ var version$1 = '4.33.2';
8427
8469
 
8428
8470
  var NAMESPACE = 'ais';
8429
8471
  var component = function component(componentName) {
@@ -9491,6 +9533,8 @@
9491
9533
 
9492
9534
  var setWindowTitle = function setWindowTitle(title) {
9493
9535
  if (title) {
9536
+ // This function is only executed on browsers so we can disable this check.
9537
+ // eslint-disable-next-line no-restricted-globals
9494
9538
  window.document.title = title;
9495
9539
  }
9496
9540
  };
@@ -9501,11 +9545,14 @@
9501
9545
  * using web APIs (`window.location.pushState` and `onpopstate` event).
9502
9546
  */
9503
9547
  function BrowserHistory(_ref) {
9548
+ var _this = this;
9549
+
9504
9550
  var windowTitle = _ref.windowTitle,
9505
9551
  _ref$writeDelay = _ref.writeDelay,
9506
9552
  writeDelay = _ref$writeDelay === void 0 ? 400 : _ref$writeDelay,
9507
9553
  createURL = _ref.createURL,
9508
- parseURL = _ref.parseURL;
9554
+ parseURL = _ref.parseURL,
9555
+ getLocation = _ref.getLocation;
9509
9556
 
9510
9557
  _classCallCheck(this, BrowserHistory);
9511
9558
 
@@ -9517,15 +9564,23 @@
9517
9564
 
9518
9565
  _defineProperty(this, "parseURL", void 0);
9519
9566
 
9567
+ _defineProperty(this, "getLocation", void 0);
9568
+
9520
9569
  _defineProperty(this, "writeTimer", void 0);
9521
9570
 
9571
+ _defineProperty(this, "shouldPushState", true);
9572
+
9522
9573
  this.windowTitle = windowTitle;
9523
9574
  this.writeTimer = undefined;
9524
9575
  this.writeDelay = writeDelay;
9525
9576
  this._createURL = createURL;
9526
9577
  this.parseURL = parseURL;
9527
- var title = this.windowTitle && this.windowTitle(this.read());
9528
- setWindowTitle(title);
9578
+ this.getLocation = getLocation;
9579
+ safelyRunOnBrowser(function () {
9580
+ var title = _this.windowTitle && _this.windowTitle(_this.read());
9581
+
9582
+ setWindowTitle(title);
9583
+ });
9529
9584
  }
9530
9585
  /**
9531
9586
  * Reads the URL and returns a syncable UI search state.
@@ -9537,7 +9592,7 @@
9537
9592
  value: function read() {
9538
9593
  return this.parseURL({
9539
9594
  qsModule: lib$1,
9540
- location: window.location
9595
+ location: this.getLocation()
9541
9596
  });
9542
9597
  }
9543
9598
  /**
@@ -9547,20 +9602,30 @@
9547
9602
  }, {
9548
9603
  key: "write",
9549
9604
  value: function write(routeState) {
9550
- var _this = this;
9605
+ var _this2 = this;
9551
9606
 
9552
- var url = this.createURL(routeState);
9553
- var title = this.windowTitle && this.windowTitle(routeState);
9607
+ safelyRunOnBrowser(function (_ref2) {
9608
+ var window = _ref2.window;
9554
9609
 
9555
- if (this.writeTimer) {
9556
- window.clearTimeout(this.writeTimer);
9557
- }
9610
+ var url = _this2.createURL(routeState);
9611
+
9612
+ var title = _this2.windowTitle && _this2.windowTitle(routeState);
9558
9613
 
9559
- this.writeTimer = window.setTimeout(function () {
9560
- setWindowTitle(title);
9561
- window.history.pushState(routeState, title || '', url);
9562
- _this.writeTimer = undefined;
9563
- }, this.writeDelay);
9614
+ if (_this2.writeTimer) {
9615
+ clearTimeout(_this2.writeTimer);
9616
+ }
9617
+
9618
+ _this2.writeTimer = setTimeout(function () {
9619
+ setWindowTitle(title);
9620
+
9621
+ if (_this2.shouldPushState) {
9622
+ window.history.pushState(routeState, title || '', url);
9623
+ }
9624
+
9625
+ _this2.shouldPushState = true;
9626
+ _this2.writeTimer = undefined;
9627
+ }, _this2.writeDelay);
9628
+ });
9564
9629
  }
9565
9630
  /**
9566
9631
  * Sets a callback on the `onpopstate` event of the history API of the current page.
@@ -9570,26 +9635,30 @@
9570
9635
  }, {
9571
9636
  key: "onUpdate",
9572
9637
  value: function onUpdate(callback) {
9573
- var _this2 = this;
9638
+ var _this3 = this;
9574
9639
 
9575
9640
  this._onPopState = function (event) {
9576
- if (_this2.writeTimer) {
9577
- window.clearTimeout(_this2.writeTimer);
9578
- _this2.writeTimer = undefined;
9641
+ if (_this3.writeTimer) {
9642
+ clearTimeout(_this3.writeTimer);
9643
+ _this3.writeTimer = undefined;
9579
9644
  }
9580
9645
 
9646
+ _this3.shouldPushState = false;
9581
9647
  var routeState = event.state; // At initial load, the state is read from the URL without update.
9582
9648
  // Therefore the state object is not available.
9583
9649
  // In this case, we fallback and read the URL.
9584
9650
 
9585
9651
  if (!routeState) {
9586
- callback(_this2.read());
9652
+ callback(_this3.read());
9587
9653
  } else {
9588
9654
  callback(routeState);
9589
9655
  }
9590
9656
  };
9591
9657
 
9592
- window.addEventListener('popstate', this._onPopState);
9658
+ safelyRunOnBrowser(function (_ref3) {
9659
+ var window = _ref3.window;
9660
+ window.addEventListener('popstate', _this3._onPopState);
9661
+ });
9593
9662
  }
9594
9663
  /**
9595
9664
  * Creates a complete URL from a given syncable UI state.
@@ -9605,7 +9674,7 @@
9605
9674
  return this._createURL({
9606
9675
  qsModule: lib$1,
9607
9676
  routeState: routeState,
9608
- location: window.location
9677
+ location: this.getLocation()
9609
9678
  });
9610
9679
  }
9611
9680
  /**
@@ -9615,12 +9684,18 @@
9615
9684
  }, {
9616
9685
  key: "dispose",
9617
9686
  value: function dispose() {
9618
- if (this._onPopState) {
9619
- window.removeEventListener('popstate', this._onPopState);
9620
- }
9687
+ var _this4 = this;
9688
+
9689
+ safelyRunOnBrowser(function (_ref4) {
9690
+ var window = _ref4.window;
9691
+
9692
+ if (_this4._onPopState) {
9693
+ window.removeEventListener('popstate', _this4._onPopState);
9694
+ }
9695
+ });
9621
9696
 
9622
9697
  if (this.writeTimer) {
9623
- window.clearTimeout(this.writeTimer);
9698
+ clearTimeout(this.writeTimer);
9624
9699
  }
9625
9700
 
9626
9701
  this.write({});
@@ -9631,12 +9706,12 @@
9631
9706
  }();
9632
9707
 
9633
9708
  function historyRouter() {
9634
- var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
9635
- _ref2$createURL = _ref2.createURL,
9636
- createURL = _ref2$createURL === void 0 ? function (_ref3) {
9637
- var qsModule = _ref3.qsModule,
9638
- routeState = _ref3.routeState,
9639
- location = _ref3.location;
9709
+ var _ref5 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
9710
+ _ref5$createURL = _ref5.createURL,
9711
+ createURL = _ref5$createURL === void 0 ? function (_ref6) {
9712
+ var qsModule = _ref6.qsModule,
9713
+ routeState = _ref6.routeState,
9714
+ location = _ref6.location;
9640
9715
  var protocol = location.protocol,
9641
9716
  hostname = location.hostname,
9642
9717
  _location$port = location.port,
@@ -9652,11 +9727,11 @@
9652
9727
  }
9653
9728
 
9654
9729
  return "".concat(protocol, "//").concat(hostname).concat(portWithPrefix).concat(pathname, "?").concat(queryString).concat(hash);
9655
- } : _ref2$createURL,
9656
- _ref2$parseURL = _ref2.parseURL,
9657
- parseURL = _ref2$parseURL === void 0 ? function (_ref4) {
9658
- var qsModule = _ref4.qsModule,
9659
- location = _ref4.location;
9730
+ } : _ref5$createURL,
9731
+ _ref5$parseURL = _ref5.parseURL,
9732
+ parseURL = _ref5$parseURL === void 0 ? function (_ref7) {
9733
+ var qsModule = _ref7.qsModule,
9734
+ location = _ref7.location;
9660
9735
  // `qs` by default converts arrays with more than 20 items to an object.
9661
9736
  // We want to avoid this because the data structure manipulated can therefore vary.
9662
9737
  // Setting the limit to `100` seems a good number because the engine's default is 100
@@ -9670,16 +9745,28 @@
9670
9745
  return qsModule.parse(location.search.slice(1), {
9671
9746
  arrayLimit: 99
9672
9747
  });
9673
- } : _ref2$parseURL,
9674
- _ref2$writeDelay = _ref2.writeDelay,
9675
- writeDelay = _ref2$writeDelay === void 0 ? 400 : _ref2$writeDelay,
9676
- windowTitle = _ref2.windowTitle;
9748
+ } : _ref5$parseURL,
9749
+ _ref5$writeDelay = _ref5.writeDelay,
9750
+ writeDelay = _ref5$writeDelay === void 0 ? 400 : _ref5$writeDelay,
9751
+ windowTitle = _ref5.windowTitle,
9752
+ _ref5$getLocation = _ref5.getLocation,
9753
+ getLocation = _ref5$getLocation === void 0 ? function () {
9754
+ return safelyRunOnBrowser(function (_ref8) {
9755
+ var window = _ref8.window;
9756
+ return window.location;
9757
+ }, {
9758
+ fallback: function fallback() {
9759
+ throw new Error('You need to provide `getLocation` to the `history` router in environments where `window` does not exist.');
9760
+ }
9761
+ });
9762
+ } : _ref5$getLocation;
9677
9763
 
9678
9764
  return new BrowserHistory({
9679
9765
  createURL: createURL,
9680
9766
  parseURL: parseURL,
9681
9767
  writeDelay: writeDelay,
9682
- windowTitle: windowTitle
9768
+ windowTitle: windowTitle,
9769
+ getLocation: getLocation
9683
9770
  });
9684
9771
  }
9685
9772
 
@@ -9773,7 +9860,14 @@
9773
9860
  }
9774
9861
 
9775
9862
  function isMetadataEnabled() {
9776
- return typeof window !== 'undefined' && window.navigator.userAgent.indexOf('Algolia Crawler') > -1;
9863
+ return safelyRunOnBrowser(function (_ref) {
9864
+ var window = _ref.window;
9865
+ return window.navigator.userAgent.indexOf('Algolia Crawler') > -1;
9866
+ }, {
9867
+ fallback: function fallback() {
9868
+ return false;
9869
+ }
9870
+ });
9777
9871
  }
9778
9872
  /**
9779
9873
  * Exposes the metadata of mounted widgets in a custom
@@ -9784,8 +9878,8 @@
9784
9878
  */
9785
9879
 
9786
9880
  function createMetadataMiddleware() {
9787
- return function (_ref) {
9788
- var instantSearchInstance = _ref.instantSearchInstance;
9881
+ return function (_ref2) {
9882
+ var instantSearchInstance = _ref2.instantSearchInstance;
9789
9883
  var payload = {
9790
9884
  widgets: []
9791
9885
  };
@@ -10278,15 +10372,17 @@
10278
10372
  var nextUiState = typeof uiState === 'function' ? uiState(this.mainIndex.getWidgetUiState({})) : uiState;
10279
10373
 
10280
10374
  var setIndexHelperState = function setIndexHelperState(indexWidget) {
10375
+ var nextIndexUiState = nextUiState[indexWidget.getIndexId()] || {};
10376
+
10281
10377
  {
10282
10378
  checkIndexUiState({
10283
10379
  index: indexWidget,
10284
- indexUiState: nextUiState[indexWidget.getIndexId()]
10380
+ indexUiState: nextIndexUiState
10285
10381
  });
10286
10382
  }
10287
10383
 
10288
10384
  indexWidget.getHelper().setState(indexWidget.getWidgetSearchParameters(indexWidget.getHelper().state, {
10289
- uiState: nextUiState[indexWidget.getIndexId()]
10385
+ uiState: nextIndexUiState
10290
10386
  }));
10291
10387
  indexWidget.getWidgets().filter(isIndexWidget).forEach(setIndexHelperState);
10292
10388
  };
@@ -11972,6 +12068,8 @@
11972
12068
  if (option.start !== undefined && option.end !== undefined) {
11973
12069
  if (option.start === option.end) {
11974
12070
  return hasNumericRefinement(currentRefinements, '=', option.start);
12071
+ } else {
12072
+ return hasNumericRefinement(currentRefinements, '>=', option.start) && hasNumericRefinement(currentRefinements, '<=', option.end);
11975
12073
  }
11976
12074
  }
11977
12075
 
@@ -12025,17 +12123,17 @@
12025
12123
  if (refinedOption.start !== undefined) {
12026
12124
  if (hasNumericRefinement(currentRefinements, '>=', refinedOption.start)) {
12027
12125
  resolvedState = resolvedState.removeNumericRefinement(attribute, '>=', refinedOption.start);
12028
- } else {
12029
- resolvedState = resolvedState.addNumericRefinement(attribute, '>=', refinedOption.start);
12030
12126
  }
12127
+
12128
+ resolvedState = resolvedState.addNumericRefinement(attribute, '>=', refinedOption.start);
12031
12129
  }
12032
12130
 
12033
12131
  if (refinedOption.end !== undefined) {
12034
12132
  if (hasNumericRefinement(currentRefinements, '<=', refinedOption.end)) {
12035
12133
  resolvedState = resolvedState.removeNumericRefinement(attribute, '<=', refinedOption.end);
12036
- } else {
12037
- resolvedState = resolvedState.addNumericRefinement(attribute, '<=', refinedOption.end);
12038
12134
  }
12135
+
12136
+ resolvedState = resolvedState.addNumericRefinement(attribute, '<=', refinedOption.end);
12039
12137
  }
12040
12138
 
12041
12139
  if (typeof resolvedState.page === 'number') {
@@ -14104,11 +14202,20 @@
14104
14202
  var connectPoweredBy = function connectPoweredBy(renderFn) {
14105
14203
  var unmountFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
14106
14204
  checkRendering(renderFn, withUsage$k());
14107
- var defaultUrl = 'https://www.algolia.com/?' + 'utm_source=instantsearch.js&' + 'utm_medium=website&' + "utm_content=".concat(typeof window !== 'undefined' && window.location ? window.location.hostname : '', "&") + 'utm_campaign=poweredby';
14205
+ var defaultUrl = 'https://www.algolia.com/?' + 'utm_source=instantsearch.js&' + 'utm_medium=website&' + "utm_content=".concat(safelyRunOnBrowser(function (_ref) {
14206
+ var _window$location;
14207
+
14208
+ var window = _ref.window;
14209
+ return ((_window$location = window.location) === null || _window$location === void 0 ? void 0 : _window$location.hostname) || '';
14210
+ }, {
14211
+ fallback: function fallback() {
14212
+ return '';
14213
+ }
14214
+ }), "&") + 'utm_campaign=poweredby';
14108
14215
  return function (widgetParams) {
14109
- var _ref = widgetParams || {},
14110
- _ref$url = _ref.url,
14111
- url = _ref$url === void 0 ? defaultUrl : _ref$url;
14216
+ var _ref2 = widgetParams || {},
14217
+ _ref2$url = _ref2.url,
14218
+ url = _ref2$url === void 0 ? defaultUrl : _ref2$url;
14112
14219
 
14113
14220
  return {
14114
14221
  $$type: 'ais.poweredBy',
@@ -14593,6 +14700,11 @@
14593
14700
  };
14594
14701
  };
14595
14702
 
14703
+ // `SpeechRecognition` is an API used on the browser so we can safely disable
14704
+ // the `window` check.
14705
+
14706
+ /* eslint-disable no-restricted-globals */
14707
+
14596
14708
  /* global SpeechRecognition SpeechRecognitionEvent */
14597
14709
  var createVoiceSearchHelper = function createVoiceSearchHelper(_ref) {
14598
14710
  var searchAsYouSpeak = _ref.searchAsYouSpeak,
@@ -21469,28 +21581,27 @@
21469
21581
  }
21470
21582
 
21471
21583
  var KEY = 'ais.infiniteHits';
21472
-
21473
- function hasSessionStorage() {
21474
- return typeof window !== 'undefined' && typeof window.sessionStorage !== 'undefined';
21475
- }
21476
-
21477
21584
  function createInfiniteHitsSessionStorageCache() {
21478
21585
  return {
21479
21586
  read: function read(_ref2) {
21480
21587
  var state = _ref2.state;
21588
+ var sessionStorage = safelyRunOnBrowser(function (_ref3) {
21589
+ var window = _ref3.window;
21590
+ return window.sessionStorage;
21591
+ });
21481
21592
 
21482
- if (!hasSessionStorage()) {
21593
+ if (!sessionStorage) {
21483
21594
  return null;
21484
21595
  }
21485
21596
 
21486
21597
  try {
21487
21598
  var cache = JSON.parse( // @ts-expect-error JSON.parse() requires a string, but it actually accepts null, too.
21488
- window.sessionStorage.getItem(KEY));
21599
+ sessionStorage.getItem(KEY));
21489
21600
  return cache && isEqual(cache.state, getStateWithoutPage$1(state)) ? cache.hits : null;
21490
21601
  } catch (error) {
21491
21602
  if (error instanceof SyntaxError) {
21492
21603
  try {
21493
- window.sessionStorage.removeItem(KEY);
21604
+ sessionStorage.removeItem(KEY);
21494
21605
  } catch (err) {// do nothing
21495
21606
  }
21496
21607
  }
@@ -21498,16 +21609,20 @@
21498
21609
  return null;
21499
21610
  }
21500
21611
  },
21501
- write: function write(_ref3) {
21502
- var state = _ref3.state,
21503
- hits = _ref3.hits;
21612
+ write: function write(_ref4) {
21613
+ var state = _ref4.state,
21614
+ hits = _ref4.hits;
21615
+ var sessionStorage = safelyRunOnBrowser(function (_ref5) {
21616
+ var window = _ref5.window;
21617
+ return window.sessionStorage;
21618
+ });
21504
21619
 
21505
- if (!hasSessionStorage()) {
21620
+ if (!sessionStorage) {
21506
21621
  return;
21507
21622
  }
21508
21623
 
21509
21624
  try {
21510
- window.sessionStorage.setItem(KEY, JSON.stringify({
21625
+ sessionStorage.setItem(KEY, JSON.stringify({
21511
21626
  state: getStateWithoutPage$1(state),
21512
21627
  hits: hits
21513
21628
  }));