react-instantsearch 7.16.0 → 7.16.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.
@@ -7,7 +7,7 @@
7
7
 
8
8
  var React__default = 'default' in React ? React['default'] : React;
9
9
 
10
- var version = '7.16.0';
10
+ var version = '7.16.2';
11
11
 
12
12
  // Copyright Joyent, Inc. and other Node contributors.
13
13
  //
@@ -9575,19 +9575,29 @@
9575
9575
  */
9576
9576
  var useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
9577
9577
 
9578
- var InstantSearchRSCContext = /*#__PURE__*/React.createContext(null);
9578
+ var InstantSearchRSCContext = /*#__PURE__*/React.createContext({
9579
+ countRef: {
9580
+ current: 0
9581
+ },
9582
+ waitForResultsRef: null,
9583
+ ignoreMultipleHooksWarning: false
9584
+ });
9579
9585
 
9580
9586
  function useRSCContext() {
9581
9587
  return React.useContext(InstantSearchRSCContext);
9582
9588
  }
9583
9589
 
9584
9590
  function useWidget(_ref) {
9585
- var _waitingForResultsRef;
9591
+ var _waitForResultsRef$cu, _waitForResultsRef$cu2;
9586
9592
  var widget = _ref.widget,
9587
9593
  parentIndex = _ref.parentIndex,
9588
9594
  props = _ref.props,
9589
- shouldSsr = _ref.shouldSsr;
9590
- var waitingForResultsRef = useRSCContext();
9595
+ shouldSsr = _ref.shouldSsr,
9596
+ skipSuspense = _ref.skipSuspense;
9597
+ var _useRSCContext = useRSCContext(),
9598
+ waitForResultsRef = _useRSCContext.waitForResultsRef,
9599
+ countRef = _useRSCContext.countRef,
9600
+ ignoreMultipleHooksWarning = _useRSCContext.ignoreMultipleHooksWarning;
9591
9601
  var prevPropsRef = React.useRef(props);
9592
9602
  React.useEffect(function () {
9593
9603
  prevPropsRef.current = props;
@@ -9647,20 +9657,21 @@
9647
9657
  });
9648
9658
  };
9649
9659
  }, [parentIndex, widget, shouldSsr, search, props]);
9650
- if (shouldAddWidgetEarly || (waitingForResultsRef === null || waitingForResultsRef === void 0 ? void 0 : (_waitingForResultsRef = waitingForResultsRef.current) === null || _waitingForResultsRef === void 0 ? void 0 : _waitingForResultsRef.status) === 'pending') {
9660
+ if (shouldAddWidgetEarly || (waitForResultsRef === null || waitForResultsRef === void 0 ? void 0 : (_waitForResultsRef$cu = waitForResultsRef.current) === null || _waitForResultsRef$cu === void 0 ? void 0 : _waitForResultsRef$cu.status) === 'pending') {
9651
9661
  parentIndex.addWidgets([widget]);
9652
9662
  }
9653
- if (typeof window === 'undefined' && waitingForResultsRef !== null && waitingForResultsRef !== void 0 && waitingForResultsRef.current &&
9654
- // We need the widgets contained in the index to be added before we trigger the search request.
9655
- widget.$$type !== 'ais.index') {
9663
+ if (waitForResultsRef !== null && waitForResultsRef !== void 0 && waitForResultsRef.current && !skipSuspense) {
9656
9664
  var _search$helper;
9657
- use(waitingForResultsRef.current);
9665
+ use(waitForResultsRef.current);
9658
9666
  // If we made a second request because of DynamicWidgets, we need to wait for the second result,
9659
9667
  // except for DynamicWidgets itself which needs to render its children after the first result.
9660
9668
  if (widget.$$type !== 'ais.dynamicWidgets' && (_search$helper = search.helper) !== null && _search$helper !== void 0 && _search$helper.lastResults) {
9661
- use(waitingForResultsRef.current);
9669
+ use(waitForResultsRef.current);
9662
9670
  }
9663
9671
  }
9672
+ if ((waitForResultsRef === null || waitForResultsRef === void 0 ? void 0 : (_waitForResultsRef$cu2 = waitForResultsRef.current) === null || _waitForResultsRef$cu2 === void 0 ? void 0 : _waitForResultsRef$cu2.status) === 'fulfilled') {
9673
+ countRef.current += 1;
9674
+ }
9664
9675
  }
9665
9676
 
9666
9677
  function _typeof$d(o) {
@@ -9672,8 +9683,9 @@
9672
9683
  return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
9673
9684
  }, _typeof$d(o);
9674
9685
  }
9675
- var _excluded$1 = ["instantSearchInstance", "widgetParams"],
9676
- _excluded2 = ["widgetParams"];
9686
+ var _excluded$1 = ["skipSuspense"],
9687
+ _excluded2 = ["instantSearchInstance", "widgetParams"],
9688
+ _excluded3 = ["widgetParams"];
9677
9689
  function _slicedToArray$5(arr, i) {
9678
9690
  return _arrayWithHoles$5(arr) || _iterableToArrayLimit$5(arr, i) || _unsupportedIterableToArray$6(arr, i) || _nonIterableRest$5();
9679
9691
  }
@@ -9801,7 +9813,10 @@
9801
9813
  }
9802
9814
  function useConnector(connector) {
9803
9815
  var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
9804
- var additionalWidgetProperties = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
9816
+ var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
9817
+ _ref$skipSuspense = _ref.skipSuspense,
9818
+ skipSuspense = _ref$skipSuspense === void 0 ? false : _ref$skipSuspense,
9819
+ additionalWidgetProperties = _objectWithoutProperties$1(_ref, _excluded$1);
9805
9820
  var serverContext = useInstantSearchServerContext();
9806
9821
  var ssrContext = useInstantSearchSSRContext();
9807
9822
  var search = useInstantSearchContext();
@@ -9835,7 +9850,7 @@
9835
9850
  if (shouldSetStateRef.current) {
9836
9851
  var instantSearchInstance = connectorState.instantSearchInstance,
9837
9852
  widgetParams = connectorState.widgetParams,
9838
- renderState = _objectWithoutProperties$1(connectorState, _excluded$1);
9853
+ renderState = _objectWithoutProperties$1(connectorState, _excluded2);
9839
9854
 
9840
9855
  // We only update the state when a widget render state param changes,
9841
9856
  // except for functions. We ignore function reference changes to avoid
@@ -9891,7 +9906,7 @@
9891
9906
  error: search.error
9892
9907
  }),
9893
9908
  widgetParams = _widget$getWidgetRend.widgetParams,
9894
- renderState = _objectWithoutProperties$1(_widget$getWidgetRend, _excluded2);
9909
+ renderState = _objectWithoutProperties$1(_widget$getWidgetRend, _excluded3);
9895
9910
  return renderState;
9896
9911
  }
9897
9912
  return {};
@@ -9903,7 +9918,8 @@
9903
9918
  widget: widget,
9904
9919
  parentIndex: parentIndex,
9905
9920
  props: stableProps,
9906
- shouldSsr: Boolean(serverContext)
9921
+ shouldSsr: Boolean(serverContext),
9922
+ skipSuspense: skipSuspense
9907
9923
  });
9908
9924
  return state;
9909
9925
  }
@@ -11118,7 +11134,8 @@
11118
11134
  widget: indexWidget,
11119
11135
  parentIndex: parentIndex,
11120
11136
  props: stableProps,
11121
- shouldSsr: Boolean(serverContext || initialResults)
11137
+ shouldSsr: Boolean(serverContext || initialResults),
11138
+ skipSuspense: true
11122
11139
  });
11123
11140
  return indexWidget;
11124
11141
  }
@@ -13451,7 +13468,7 @@
13451
13468
  };
13452
13469
  }
13453
13470
 
13454
- var version$3 = '4.79.0';
13471
+ var version$3 = '4.79.2';
13455
13472
 
13456
13473
  function _typeof$q(o) {
13457
13474
  "@babel/helpers - typeof";
@@ -14307,15 +14324,16 @@
14307
14324
  var forceUpdate = useForceUpdate();
14308
14325
  var serverContext = useInstantSearchServerContext();
14309
14326
  var serverState = useInstantSearchSSRContext();
14310
- var waitingForResultsRef = useRSCContext();
14327
+ var _useRSCContext = useRSCContext(),
14328
+ waitForResultsRef = _useRSCContext.waitForResultsRef;
14311
14329
  var initialResults = serverState === null || serverState === void 0 ? void 0 : serverState.initialResults;
14312
14330
  var prevPropsRef = React.useRef(props);
14313
- var shouldRenderAtOnce = serverContext || initialResults || waitingForResultsRef;
14331
+ var shouldRenderAtOnce = serverContext || initialResults || waitForResultsRef;
14314
14332
  var searchRef = React.useRef(null);
14315
14333
  // As we need to render on mount with SSR, using the local ref above in `StrictMode` will
14316
14334
  // create and start two instances of InstantSearch. To avoid this, we instead discard it and use
14317
14335
  // an upward ref from `InstantSearchSSRContext` as it has already been mounted a second time at this point.
14318
- if (serverState) {
14336
+ if (serverState !== null && serverState !== void 0 && serverState.ssrSearchRef) {
14319
14337
  searchRef = serverState.ssrSearchRef;
14320
14338
  }
14321
14339
  if (searchRef.current === null) {
@@ -14428,6 +14446,9 @@
14428
14446
  search._preventWidgetCleanup = false;
14429
14447
  }
14430
14448
  return function () {
14449
+ if (serverState !== null && serverState !== void 0 && serverState.ssrSearchRef) {
14450
+ return;
14451
+ }
14431
14452
  function cleanup() {
14432
14453
  search.dispose();
14433
14454
  }
@@ -14439,13 +14460,12 @@
14439
14460
  // in the next effect.
14440
14461
  // (There might be better ways to do this.)
14441
14462
  cleanupTimerRef.current = setTimeout(cleanup);
14442
-
14443
14463
  // We need to prevent the `useWidget` cleanup function so that widgets
14444
14464
  // are not removed before the instance is disposed, triggering
14445
14465
  // an unwanted search request.
14446
14466
  search._preventWidgetCleanup = true;
14447
14467
  };
14448
- }, [forceUpdate]), function () {
14468
+ }, [forceUpdate, serverState]), function () {
14449
14469
  return searchRef.current;
14450
14470
  }, function () {
14451
14471
  return searchRef.current;
@@ -16776,22 +16796,20 @@
16776
16796
  return Math.max.apply(Math, [page].concat(_toConsumableArray$6(pages)));
16777
16797
  }
16778
16798
  };
16779
- var getShowPrevious = function getShowPrevious(helper) {
16799
+ var getShowPrevious = function getShowPrevious(helper, getCachedHits) {
16780
16800
  return function () {
16801
+ var cachedHits = getCachedHits();
16781
16802
  // Using the helper's `overrideStateWithoutTriggeringChangeEvent` method
16782
16803
  // avoid updating the browser URL when the user displays the previous page.
16783
16804
  helper.overrideStateWithoutTriggeringChangeEvent(_objectSpread$v(_objectSpread$v({}, helper.state), {}, {
16784
- page: getFirstReceivedPage(helper.state, cache.read({
16785
- state: normalizeState(helper.state)
16786
- }) || {}) - 1
16805
+ page: getFirstReceivedPage(helper.state, cachedHits) - 1
16787
16806
  })).searchWithoutTriggeringOnStateChange();
16788
16807
  };
16789
16808
  };
16790
- var getShowMore = function getShowMore(helper) {
16809
+ var getShowMore = function getShowMore(helper, getCachedHits) {
16791
16810
  return function () {
16792
- helper.setPage(getLastReceivedPage(helper.state, cache.read({
16793
- state: normalizeState(helper.state)
16794
- }) || {}) + 1).search();
16811
+ var cachedHits = getCachedHits();
16812
+ helper.setPage(getLastReceivedPage(helper.state, cachedHits) + 1).search();
16795
16813
  };
16796
16814
  };
16797
16815
  return {
@@ -16823,6 +16841,12 @@
16823
16841
  parent = _ref6.parent,
16824
16842
  existingState = _ref6.state,
16825
16843
  instantSearchInstance = _ref6.instantSearchInstance;
16844
+ var getCacheHits = function getCacheHits() {
16845
+ var state = parent.getPreviousState() || existingState;
16846
+ return cache.read({
16847
+ state: normalizeState(state)
16848
+ }) || {};
16849
+ };
16826
16850
  var isFirstPage;
16827
16851
  var currentPageHits = [];
16828
16852
  /**
@@ -16831,13 +16855,15 @@
16831
16855
  * is loading.
16832
16856
  */
16833
16857
  var state = parent.getPreviousState() || existingState;
16834
- var cachedHits = cache.read({
16835
- state: normalizeState(state)
16836
- }) || {};
16858
+ var cachedHits = getCacheHits();
16837
16859
  var banner = results === null || results === void 0 ? void 0 : (_results$renderingCon = results.renderingContent) === null || _results$renderingCon === void 0 ? void 0 : (_results$renderingCon2 = _results$renderingCon.widgets) === null || _results$renderingCon2 === void 0 ? void 0 : (_results$renderingCon3 = _results$renderingCon2.banners) === null || _results$renderingCon3 === void 0 ? void 0 : _results$renderingCon3[0];
16838
16860
  if (!showPrevious) {
16839
- showPrevious = getShowPrevious(helper);
16840
- showMore = getShowMore(helper);
16861
+ showPrevious = function showPrevious() {
16862
+ return getShowPrevious(helper, getCacheHits)();
16863
+ };
16864
+ showMore = function showMore() {
16865
+ return getShowMore(helper, getCacheHits)();
16866
+ };
16841
16867
  }
16842
16868
  if (!sendEvent) {
16843
16869
  sendEvent = createSendEventForHits({
@@ -21011,18 +21037,13 @@
21011
21037
 
21012
21038
  var _extends_1 = createCommonjsModule(function (module) {
21013
21039
  function _extends() {
21014
- module.exports = _extends = Object.assign ? Object.assign.bind() : function (target) {
21015
- for (var i = 1; i < arguments.length; i++) {
21016
- var source = arguments[i];
21017
- for (var key in source) {
21018
- if (Object.prototype.hasOwnProperty.call(source, key)) {
21019
- target[key] = source[key];
21020
- }
21021
- }
21040
+ return module.exports = _extends = Object.assign ? Object.assign.bind() : function (n) {
21041
+ for (var e = 1; e < arguments.length; e++) {
21042
+ var t = arguments[e];
21043
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
21022
21044
  }
21023
- return target;
21024
- }, module.exports.__esModule = true, module.exports["default"] = module.exports;
21025
- return _extends.apply(this, arguments);
21045
+ return n;
21046
+ }, module.exports.__esModule = true, module.exports["default"] = module.exports, _extends.apply(null, arguments);
21026
21047
  }
21027
21048
  module.exports = _extends, module.exports.__esModule = true, module.exports["default"] = module.exports;
21028
21049
  });
@@ -21030,63 +21051,57 @@
21030
21051
  var _extends$2 = unwrapExports(_extends_1);
21031
21052
 
21032
21053
  var _typeof_1 = createCommonjsModule(function (module) {
21033
- function _typeof(obj) {
21054
+ function _typeof(o) {
21034
21055
  "@babel/helpers - typeof";
21035
21056
 
21036
- return (module.exports = _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
21037
- return typeof obj;
21038
- } : function (obj) {
21039
- return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
21040
- }, module.exports.__esModule = true, module.exports["default"] = module.exports), _typeof(obj);
21057
+ return module.exports = _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
21058
+ return typeof o;
21059
+ } : function (o) {
21060
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
21061
+ }, module.exports.__esModule = true, module.exports["default"] = module.exports, _typeof(o);
21041
21062
  }
21042
21063
  module.exports = _typeof, module.exports.__esModule = true, module.exports["default"] = module.exports;
21043
21064
  });
21044
21065
 
21045
21066
  unwrapExports(_typeof_1);
21046
21067
 
21047
- var toPrimitive = createCommonjsModule(function (module) {
21068
+ var toPrimitive_1 = createCommonjsModule(function (module) {
21048
21069
  var _typeof = _typeof_1["default"];
21049
- function _toPrimitive(input, hint) {
21050
- if (_typeof(input) !== "object" || input === null) return input;
21051
- var prim = input[Symbol.toPrimitive];
21052
- if (prim !== undefined) {
21053
- var res = prim.call(input, hint || "default");
21054
- if (_typeof(res) !== "object") return res;
21070
+ function toPrimitive(t, r) {
21071
+ if ("object" != _typeof(t) || !t) return t;
21072
+ var e = t[Symbol.toPrimitive];
21073
+ if (void 0 !== e) {
21074
+ var i = e.call(t, r || "default");
21075
+ if ("object" != _typeof(i)) return i;
21055
21076
  throw new TypeError("@@toPrimitive must return a primitive value.");
21056
21077
  }
21057
- return (hint === "string" ? String : Number)(input);
21078
+ return ("string" === r ? String : Number)(t);
21058
21079
  }
21059
- module.exports = _toPrimitive, module.exports.__esModule = true, module.exports["default"] = module.exports;
21080
+ module.exports = toPrimitive, module.exports.__esModule = true, module.exports["default"] = module.exports;
21060
21081
  });
21061
21082
 
21062
- unwrapExports(toPrimitive);
21083
+ unwrapExports(toPrimitive_1);
21063
21084
 
21064
- var toPropertyKey = createCommonjsModule(function (module) {
21085
+ var toPropertyKey_1 = createCommonjsModule(function (module) {
21065
21086
  var _typeof = _typeof_1["default"];
21066
21087
 
21067
- function _toPropertyKey(arg) {
21068
- var key = toPrimitive(arg, "string");
21069
- return _typeof(key) === "symbol" ? key : String(key);
21088
+ function toPropertyKey(t) {
21089
+ var i = toPrimitive_1(t, "string");
21090
+ return "symbol" == _typeof(i) ? i : i + "";
21070
21091
  }
21071
- module.exports = _toPropertyKey, module.exports.__esModule = true, module.exports["default"] = module.exports;
21092
+ module.exports = toPropertyKey, module.exports.__esModule = true, module.exports["default"] = module.exports;
21072
21093
  });
21073
21094
 
21074
- unwrapExports(toPropertyKey);
21095
+ unwrapExports(toPropertyKey_1);
21075
21096
 
21076
21097
  var defineProperty = createCommonjsModule(function (module) {
21077
- function _defineProperty(obj, key, value) {
21078
- key = toPropertyKey(key);
21079
- if (key in obj) {
21080
- Object.defineProperty(obj, key, {
21081
- value: value,
21082
- enumerable: true,
21083
- configurable: true,
21084
- writable: true
21085
- });
21086
- } else {
21087
- obj[key] = value;
21088
- }
21089
- return obj;
21098
+ function _defineProperty(e, r, t) {
21099
+ return (r = toPropertyKey_1(r)) in e ? Object.defineProperty(e, r, {
21100
+ value: t,
21101
+ enumerable: !0,
21102
+ configurable: !0,
21103
+ writable: !0
21104
+ }) : e[r] = t, e;
21090
21105
  }
21091
21106
  module.exports = _defineProperty, module.exports.__esModule = true, module.exports["default"] = module.exports;
21092
21107
  });
@@ -21094,17 +21109,14 @@
21094
21109
  var _defineProperty$N = unwrapExports(defineProperty);
21095
21110
 
21096
21111
  var objectWithoutPropertiesLoose = createCommonjsModule(function (module) {
21097
- function _objectWithoutPropertiesLoose(source, excluded) {
21098
- if (source == null) return {};
21099
- var target = {};
21100
- var sourceKeys = Object.keys(source);
21101
- var key, i;
21102
- for (i = 0; i < sourceKeys.length; i++) {
21103
- key = sourceKeys[i];
21104
- if (excluded.indexOf(key) >= 0) continue;
21105
- target[key] = source[key];
21112
+ function _objectWithoutPropertiesLoose(r, e) {
21113
+ if (null == r) return {};
21114
+ var t = {};
21115
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
21116
+ if (-1 !== e.indexOf(n)) continue;
21117
+ t[n] = r[n];
21106
21118
  }
21107
- return target;
21119
+ return t;
21108
21120
  }
21109
21121
  module.exports = _objectWithoutPropertiesLoose, module.exports.__esModule = true, module.exports["default"] = module.exports;
21110
21122
  });
@@ -21112,20 +21124,16 @@
21112
21124
  unwrapExports(objectWithoutPropertiesLoose);
21113
21125
 
21114
21126
  var objectWithoutProperties = createCommonjsModule(function (module) {
21115
- function _objectWithoutProperties(source, excluded) {
21116
- if (source == null) return {};
21117
- var target = objectWithoutPropertiesLoose(source, excluded);
21118
- var key, i;
21127
+ function _objectWithoutProperties(e, t) {
21128
+ if (null == e) return {};
21129
+ var o,
21130
+ r,
21131
+ i = objectWithoutPropertiesLoose(e, t);
21119
21132
  if (Object.getOwnPropertySymbols) {
21120
- var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
21121
- for (i = 0; i < sourceSymbolKeys.length; i++) {
21122
- key = sourceSymbolKeys[i];
21123
- if (excluded.indexOf(key) >= 0) continue;
21124
- if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
21125
- target[key] = source[key];
21126
- }
21133
+ var n = Object.getOwnPropertySymbols(e);
21134
+ for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
21127
21135
  }
21128
- return target;
21136
+ return i;
21129
21137
  }
21130
21138
  module.exports = _objectWithoutProperties, module.exports.__esModule = true, module.exports["default"] = module.exports;
21131
21139
  });
@@ -23758,6 +23766,7 @@
23758
23766
  exports.InfiniteHits = InfiniteHits$1;
23759
23767
  exports.InstantSearch = InstantSearch$1;
23760
23768
  exports.InstantSearchRSCContext = InstantSearchRSCContext;
23769
+ exports.InstantSearchSSRContext = InstantSearchSSRContext;
23761
23770
  exports.InstantSearchSSRProvider = InstantSearchSSRProvider;
23762
23771
  exports.InstantSearchServerContext = InstantSearchServerContext;
23763
23772
  exports.LookingSimilar = LookingSimilar;