instantsearch.js 4.38.0 → 4.39.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.
Files changed (30) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/cjs/connectors/hits/connectHits.js +1 -1
  3. package/cjs/connectors/infinite-hits/connectInfiniteHits.js +3 -2
  4. package/cjs/lib/routers/history.js +44 -29
  5. package/cjs/lib/version.js +1 -1
  6. package/cjs/middlewares/createMetadataMiddleware.js +3 -1
  7. package/dist/instantsearch.development.d.ts +51 -36
  8. package/dist/instantsearch.development.js +53 -35
  9. package/dist/instantsearch.development.js.map +1 -1
  10. package/dist/instantsearch.production.d.ts +51 -36
  11. package/dist/instantsearch.production.min.d.ts +51 -36
  12. package/dist/instantsearch.production.min.js +2 -2
  13. package/dist/instantsearch.production.min.js.map +1 -1
  14. package/es/components/ToggleRefinement/ToggleRefinement.d.ts +3 -0
  15. package/es/components/ToggleRefinement/ToggleRefinement.js +4 -0
  16. package/es/connectors/hits/connectHits.d.ts +10 -10
  17. package/es/connectors/hits/connectHits.js +1 -1
  18. package/es/connectors/hits/connectHitsWithInsights.d.ts +1 -1
  19. package/es/connectors/infinite-hits/connectInfiniteHits.d.ts +21 -21
  20. package/es/connectors/infinite-hits/connectInfiniteHits.js +3 -2
  21. package/es/connectors/infinite-hits/connectInfiniteHitsWithInsights.d.ts +1 -1
  22. package/es/lib/routers/history.d.ts +11 -0
  23. package/es/lib/routers/history.js +44 -29
  24. package/es/lib/utils/createSendEventForHits.d.ts +3 -0
  25. package/es/lib/utils/createSendEventForHits.js +3 -0
  26. package/es/lib/version.d.ts +1 -1
  27. package/es/lib/version.js +1 -1
  28. package/es/middlewares/createMetadataMiddleware.js +3 -1
  29. package/es/types/results.d.ts +8 -5
  30. package/package.json +4 -4
@@ -1,4 +1,4 @@
1
- /*! InstantSearch.js 4.38.0 | © Algolia, Inc. and contributors; MIT License | https://github.com/algolia/instantsearch.js */
1
+ /*! InstantSearch.js 4.39.1 | © 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) :
@@ -8483,7 +8483,7 @@
8483
8483
  instantSearchInstance.renderState = _objectSpread2(_objectSpread2({}, instantSearchInstance.renderState), {}, _defineProperty({}, parentIndexName, _objectSpread2(_objectSpread2({}, instantSearchInstance.renderState[parentIndexName]), renderState)));
8484
8484
  }
8485
8485
 
8486
- var version$1 = '4.38.0';
8486
+ var version$1 = '4.39.1';
8487
8487
 
8488
8488
  var NAMESPACE = 'ais';
8489
8489
  var component = function component(componentName) {
@@ -9600,16 +9600,23 @@
9600
9600
 
9601
9601
  _defineProperty(this, "shouldPushState", true);
9602
9602
 
9603
+ _defineProperty(this, "isDisposed", false);
9604
+
9605
+ _defineProperty(this, "latestAcknowledgedHistory", 0);
9606
+
9603
9607
  this.windowTitle = windowTitle;
9604
9608
  this.writeTimer = undefined;
9605
9609
  this.writeDelay = writeDelay;
9606
9610
  this._createURL = createURL;
9607
9611
  this.parseURL = parseURL;
9608
9612
  this.getLocation = getLocation;
9609
- safelyRunOnBrowser(function () {
9613
+ safelyRunOnBrowser(function (_ref2) {
9614
+ var window = _ref2.window;
9615
+
9610
9616
  var title = _this.windowTitle && _this.windowTitle(_this.read());
9611
9617
 
9612
9618
  setWindowTitle(title);
9619
+ _this.latestAcknowledgedHistory = window.history.length;
9613
9620
  });
9614
9621
  }
9615
9622
  /**
@@ -9634,8 +9641,8 @@
9634
9641
  value: function write(routeState) {
9635
9642
  var _this2 = this;
9636
9643
 
9637
- safelyRunOnBrowser(function (_ref2) {
9638
- var window = _ref2.window;
9644
+ safelyRunOnBrowser(function (_ref3) {
9645
+ var window = _ref3.window;
9639
9646
 
9640
9647
  var url = _this2.createURL(routeState);
9641
9648
 
@@ -9646,10 +9653,17 @@
9646
9653
  }
9647
9654
 
9648
9655
  _this2.writeTimer = setTimeout(function () {
9649
- setWindowTitle(title);
9656
+ setWindowTitle(title); // We do want to `pushState` if:
9657
+ // - the router is not disposed, IS.js needs to update the URL
9658
+ // OR
9659
+ // - the last write was from InstantSearch.js
9660
+ // (unlike a SPA, where it would have last written)
9661
+
9662
+ var lastPushWasByISAfterDispose = !_this2.isDisposed || _this2.latestAcknowledgedHistory === window.history.length;
9650
9663
 
9651
- if (_this2.shouldPushState) {
9664
+ if (_this2.shouldPushState && lastPushWasByISAfterDispose) {
9652
9665
  window.history.pushState(routeState, title || '', url);
9666
+ _this2.latestAcknowledgedHistory = window.history.length;
9653
9667
  }
9654
9668
 
9655
9669
  _this2.shouldPushState = true;
@@ -9685,8 +9699,8 @@
9685
9699
  }
9686
9700
  };
9687
9701
 
9688
- safelyRunOnBrowser(function (_ref3) {
9689
- var window = _ref3.window;
9702
+ safelyRunOnBrowser(function (_ref4) {
9703
+ var window = _ref4.window;
9690
9704
  window.addEventListener('popstate', _this3._onPopState);
9691
9705
  });
9692
9706
  }
@@ -9716,8 +9730,9 @@
9716
9730
  value: function dispose() {
9717
9731
  var _this4 = this;
9718
9732
 
9719
- safelyRunOnBrowser(function (_ref4) {
9720
- var window = _ref4.window;
9733
+ this.isDisposed = true;
9734
+ safelyRunOnBrowser(function (_ref5) {
9735
+ var window = _ref5.window;
9721
9736
 
9722
9737
  if (_this4._onPopState) {
9723
9738
  window.removeEventListener('popstate', _this4._onPopState);
@@ -9736,12 +9751,12 @@
9736
9751
  }();
9737
9752
 
9738
9753
  function historyRouter() {
9739
- var _ref5 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
9740
- _ref5$createURL = _ref5.createURL,
9741
- createURL = _ref5$createURL === void 0 ? function (_ref6) {
9742
- var qsModule = _ref6.qsModule,
9743
- routeState = _ref6.routeState,
9744
- location = _ref6.location;
9754
+ var _ref6 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
9755
+ _ref6$createURL = _ref6.createURL,
9756
+ createURL = _ref6$createURL === void 0 ? function (_ref7) {
9757
+ var qsModule = _ref7.qsModule,
9758
+ routeState = _ref7.routeState,
9759
+ location = _ref7.location;
9745
9760
  var protocol = location.protocol,
9746
9761
  hostname = location.hostname,
9747
9762
  _location$port = location.port,
@@ -9757,11 +9772,11 @@
9757
9772
  }
9758
9773
 
9759
9774
  return "".concat(protocol, "//").concat(hostname).concat(portWithPrefix).concat(pathname, "?").concat(queryString).concat(hash);
9760
- } : _ref5$createURL,
9761
- _ref5$parseURL = _ref5.parseURL,
9762
- parseURL = _ref5$parseURL === void 0 ? function (_ref7) {
9763
- var qsModule = _ref7.qsModule,
9764
- location = _ref7.location;
9775
+ } : _ref6$createURL,
9776
+ _ref6$parseURL = _ref6.parseURL,
9777
+ parseURL = _ref6$parseURL === void 0 ? function (_ref8) {
9778
+ var qsModule = _ref8.qsModule,
9779
+ location = _ref8.location;
9765
9780
  // `qs` by default converts arrays with more than 20 items to an object.
9766
9781
  // We want to avoid this because the data structure manipulated can therefore vary.
9767
9782
  // Setting the limit to `100` seems a good number because the engine's default is 100
@@ -9775,21 +9790,21 @@
9775
9790
  return qsModule.parse(location.search.slice(1), {
9776
9791
  arrayLimit: 99
9777
9792
  });
9778
- } : _ref5$parseURL,
9779
- _ref5$writeDelay = _ref5.writeDelay,
9780
- writeDelay = _ref5$writeDelay === void 0 ? 400 : _ref5$writeDelay,
9781
- windowTitle = _ref5.windowTitle,
9782
- _ref5$getLocation = _ref5.getLocation,
9783
- getLocation = _ref5$getLocation === void 0 ? function () {
9784
- return safelyRunOnBrowser(function (_ref8) {
9785
- var window = _ref8.window;
9793
+ } : _ref6$parseURL,
9794
+ _ref6$writeDelay = _ref6.writeDelay,
9795
+ writeDelay = _ref6$writeDelay === void 0 ? 400 : _ref6$writeDelay,
9796
+ windowTitle = _ref6.windowTitle,
9797
+ _ref6$getLocation = _ref6.getLocation,
9798
+ getLocation = _ref6$getLocation === void 0 ? function () {
9799
+ return safelyRunOnBrowser(function (_ref9) {
9800
+ var window = _ref9.window;
9786
9801
  return window.location;
9787
9802
  }, {
9788
9803
  fallback: function fallback() {
9789
9804
  throw new Error('You need to provide `getLocation` to the `history` router in environments where `window` does not exist.');
9790
9805
  }
9791
9806
  });
9792
- } : _ref5$getLocation;
9807
+ } : _ref6$getLocation;
9793
9808
 
9794
9809
  return new BrowserHistory({
9795
9810
  createURL: createURL,
@@ -9891,8 +9906,10 @@
9891
9906
 
9892
9907
  function isMetadataEnabled() {
9893
9908
  return safelyRunOnBrowser(function (_ref) {
9909
+ var _window$navigator, _window$navigator$use;
9910
+
9894
9911
  var window = _ref.window;
9895
- return window.navigator.userAgent.indexOf('Algolia Crawler') > -1;
9912
+ 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;
9896
9913
  }, {
9897
9914
  fallback: function fallback() {
9898
9915
  return false;
@@ -11075,10 +11092,10 @@
11075
11092
  },
11076
11093
  render: function render(renderOptions) {
11077
11094
  var renderState = this.getWidgetRenderState(renderOptions);
11078
- renderState.sendEvent('view', renderState.hits);
11079
11095
  renderFn(_objectSpread2(_objectSpread2({}, renderState), {}, {
11080
11096
  instantSearchInstance: renderOptions.instantSearchInstance
11081
11097
  }), false);
11098
+ renderState.sendEvent('view', renderState.hits);
11082
11099
  },
11083
11100
  getRenderState: function getRenderState(renderState, renderOptions) {
11084
11101
  return _objectSpread2(_objectSpread2({}, renderState), {}, {
@@ -11530,7 +11547,8 @@
11530
11547
 
11531
11548
  var connectInfiniteHits = function connectInfiniteHits(renderFn) {
11532
11549
  var unmountFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : noop;
11533
- checkRendering(renderFn, withUsage$7());
11550
+ checkRendering(renderFn, withUsage$7()); // @TODO: this should be a generic, but a Connector can not yet be generic itself
11551
+
11534
11552
  return function (widgetParams) {
11535
11553
  var _ref4 = widgetParams || {},
11536
11554
  _ref4$escapeHTML = _ref4.escapeHTML,
@@ -11601,10 +11619,10 @@
11601
11619
  render: function render(renderOptions) {
11602
11620
  var instantSearchInstance = renderOptions.instantSearchInstance;
11603
11621
  var widgetRenderState = this.getWidgetRenderState(renderOptions);
11604
- sendEvent('view', widgetRenderState.currentPageHits);
11605
11622
  renderFn(_objectSpread2(_objectSpread2({}, widgetRenderState), {}, {
11606
11623
  instantSearchInstance: instantSearchInstance
11607
11624
  }), false);
11625
+ sendEvent('view', widgetRenderState.currentPageHits);
11608
11626
  },
11609
11627
  getRenderState: function getRenderState(renderState, renderOptions) {
11610
11628
  return _objectSpread2(_objectSpread2({}, renderState), {}, {