react-instantsearch-core 7.0.2 → 7.1.0

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.
@@ -1,4 +1,4 @@
1
- /*! React InstantSearchCore UNRELEASED | © Algolia, inc. | https://github.com/algolia/instantsearch.js */
1
+ /*! React InstantSearchCore UNRELEASED | © Algolia, inc. | https://github.com/algolia/instantsearch */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
4
4
  typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
@@ -7,7 +7,7 @@
7
7
 
8
8
  var React__default = 'default' in React ? React['default'] : React;
9
9
 
10
- var version = '7.0.2';
10
+ var version = '7.1.0';
11
11
 
12
12
  // Copyright Joyent, Inc. and other Node contributors.
13
13
  //
@@ -4327,7 +4327,7 @@
4327
4327
 
4328
4328
  var SearchResults_1 = SearchResults;
4329
4329
 
4330
- var version$1 = '3.14.0';
4330
+ var version$1 = '3.14.2';
4331
4331
 
4332
4332
  var escapeFacetValue$3 = escapeFacetValue_1.escapeFacetValue;
4333
4333
 
@@ -8045,6 +8045,11 @@
8045
8045
  return stableValue;
8046
8046
  }
8047
8047
 
8048
+ var useKey = 'use';
8049
+
8050
+ // @TODO: Remove this file and import directly from React when available.
8051
+ var use = React[useKey];
8052
+
8048
8053
  /**
8049
8054
  * `useLayoutEffect` that doesn't show a warning when server-side rendering.
8050
8055
  *
@@ -8052,11 +8057,19 @@
8052
8057
  */
8053
8058
  var useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
8054
8059
 
8060
+ var InstantSearchRSCContext = /*#__PURE__*/React.createContext(null);
8061
+
8062
+ function useRSCContext() {
8063
+ return React.useContext(InstantSearchRSCContext);
8064
+ }
8065
+
8055
8066
  function useWidget(_ref) {
8067
+ var _waitingForResultsRef;
8056
8068
  var widget = _ref.widget,
8057
8069
  parentIndex = _ref.parentIndex,
8058
8070
  props = _ref.props,
8059
8071
  shouldSsr = _ref.shouldSsr;
8072
+ var waitingForResultsRef = useRSCContext();
8060
8073
  var prevPropsRef = React.useRef(props);
8061
8074
  React.useEffect(function () {
8062
8075
  prevPropsRef.current = props;
@@ -8116,9 +8129,20 @@
8116
8129
  });
8117
8130
  };
8118
8131
  }, [parentIndex, widget, shouldAddWidgetEarly, search, props]);
8119
- if (shouldAddWidgetEarly) {
8132
+ if (shouldAddWidgetEarly || (waitingForResultsRef === null || waitingForResultsRef === void 0 ? void 0 : (_waitingForResultsRef = waitingForResultsRef.current) === null || _waitingForResultsRef === void 0 ? void 0 : _waitingForResultsRef.status) === 'pending') {
8120
8133
  parentIndex.addWidgets([widget]);
8121
8134
  }
8135
+ if (typeof window === 'undefined' && waitingForResultsRef !== null && waitingForResultsRef !== void 0 && waitingForResultsRef.current &&
8136
+ // We need the widgets contained in the index to be added before we trigger the search request.
8137
+ widget.$$type !== 'ais.index') {
8138
+ var _search$helper;
8139
+ use(waitingForResultsRef.current);
8140
+ // If we made a second request because of DynamicWidgets, we need to wait for the second result,
8141
+ // except for DynamicWidgets itself which needs to render its children after the first result.
8142
+ if (widget.$$type !== 'ais.dynamicWidgets' && (_search$helper = search.helper) !== null && _search$helper !== void 0 && _search$helper.lastResults) {
8143
+ use(waitingForResultsRef.current);
8144
+ }
8145
+ }
8122
8146
  }
8123
8147
 
8124
8148
  var _excluded$1 = ["instantSearchInstance", "widgetParams"],
@@ -8195,7 +8219,7 @@
8195
8219
 
8196
8220
  // We get the widget render state by providing the same parameters as
8197
8221
  // InstantSearch provides to the widget's `render` method.
8198
- // See https://github.com/algolia/instantsearch.js/blob/019cd18d0de6dd320284aa4890541b7fe2198c65/src/widgets/index/index.ts#L604-L617
8222
+ // See https://github.com/algolia/instantsearch/blob/019cd18d0de6dd320284aa4890541b7fe2198c65/src/widgets/index/index.ts#L604-L617
8199
8223
  var _widget$getWidgetRend = widget.getWidgetRenderState({
8200
8224
  helper: helper,
8201
8225
  parent: parentIndex,
@@ -8948,7 +8972,7 @@
8948
8972
  // configuration step. This is mainly for backward compatibility with custom
8949
8973
  // widgets. When the subscription happens before the `init` step, the (static)
8950
8974
  // configuration of the widget is pushed in the URL. That's what we want to avoid.
8951
- // https://github.com/algolia/instantsearch.js/pull/994/commits/4a672ae3fd78809e213de0368549ef12e9dc9454
8975
+ // https://github.com/algolia/instantsearch/pull/994/commits/4a672ae3fd78809e213de0368549ef12e9dc9454
8952
8976
  helper.on('change', function (event) {
8953
8977
  var state = event.state;
8954
8978
  var _uiState = event._uiState;
@@ -10773,7 +10797,7 @@
10773
10797
  *
10774
10798
  * It always generates the full URL, not a relative one.
10775
10799
  * This allows to handle cases like using a <base href>.
10776
- * See: https://github.com/algolia/instantsearch.js/issues/790
10800
+ * See: https://github.com/algolia/instantsearch/issues/790
10777
10801
  */
10778
10802
  }, {
10779
10803
  key: "createURL",
@@ -11262,7 +11286,7 @@
11262
11286
  };
11263
11287
  }
11264
11288
 
11265
- var version$2 = '4.56.10';
11289
+ var version$2 = '4.57.0';
11266
11290
 
11267
11291
  function _typeof$j(obj) {
11268
11292
  "@babel/helpers - typeof";
@@ -11852,7 +11876,7 @@
11852
11876
  /**
11853
11877
  * Removes all widgets without triggering a search afterwards. This is an **EXPERIMENTAL** feature,
11854
11878
  * if you find an issue with it, please
11855
- * [open an issue](https://github.com/algolia/instantsearch.js/issues/new?title=Problem%20with%20dispose).
11879
+ * [open an issue](https://github.com/algolia/instantsearch/issues/new?title=Problem%20with%20dispose).
11856
11880
  * @return {undefined} This method does not return anything
11857
11881
  */
11858
11882
  }, {
@@ -11988,8 +12012,10 @@
11988
12012
  var forceUpdate = useForceUpdate();
11989
12013
  var serverContext = useInstantSearchServerContext();
11990
12014
  var serverState = useInstantSearchSSRContext();
12015
+ var waitingForResultsRef = useRSCContext();
11991
12016
  var initialResults = serverState === null || serverState === void 0 ? void 0 : serverState.initialResults;
11992
12017
  var prevPropsRef = React.useRef(props);
12018
+ var shouldRenderAtOnce = serverContext || initialResults || waitingForResultsRef;
11993
12019
  var searchRef = React.useRef(null);
11994
12020
  // As we need to render on mount with SSR, using the local ref above in `StrictMode` will
11995
12021
  // create and start two instances of InstantSearch. To avoid this, we instead discard it and use
@@ -12000,7 +12026,7 @@
12000
12026
  if (searchRef.current === null) {
12001
12027
  // We don't use the `instantsearch()` function because it comes with other
12002
12028
  // top-level APIs that we don't need.
12003
- // See https://github.com/algolia/instantsearch.js/blob/5b529f43d8acc680f85837eaaa41f7fd03a3f833/src/index.es.ts#L63-L86
12029
+ // See https://github.com/algolia/instantsearch/blob/5b529f43d8acc680f85837eaaa41f7fd03a3f833/src/index.es.ts#L63-L86
12004
12030
  var search = new InstantSearch(props);
12005
12031
  search._schedule = function _schedule(cb) {
12006
12032
  search._schedule.queue.push(cb);
@@ -12013,7 +12039,7 @@
12013
12039
  }, 0);
12014
12040
  };
12015
12041
  search._schedule.queue = [];
12016
- if (serverContext || initialResults) {
12042
+ if (shouldRenderAtOnce) {
12017
12043
  // InstantSearch.js has a private Initial Results API that lets us inject
12018
12044
  // results on the search instance.
12019
12045
  // On the server, we default the initial results to an empty object so that
@@ -12027,7 +12053,7 @@
12027
12053
  // On the server, we start the search early to compute the search parameters.
12028
12054
  // On SSR, we start the search early to directly catch up with the lifecycle
12029
12055
  // and render.
12030
- if (serverContext || initialResults) {
12056
+ if (shouldRenderAtOnce) {
12031
12057
  search.start();
12032
12058
  }
12033
12059
  if (serverContext) {
@@ -12141,8 +12167,8 @@
12141
12167
  * which is either `nodejs` or `edge`.
12142
12168
  */
12143
12169
  function getNextVersion() {
12144
- var _next, _process$env;
12145
- return typeof window !== 'undefined' && ((_next = window.next) === null || _next === void 0 ? void 0 : _next.version) || (typeof process !== 'undefined' ? (_process$env = process.env) === null || _process$env === void 0 ? void 0 : _process$env.NEXT_RUNTIME : undefined);
12170
+ var _next2, _process$env;
12171
+ return typeof window !== 'undefined' && ((_next2 = window.next) === null || _next2 === void 0 ? void 0 : _next2.version) || (typeof process !== 'undefined' ? (_process$env = process.env) === null || _process$env === void 0 ? void 0 : _process$env.NEXT_RUNTIME : undefined);
12146
12172
  }
12147
12173
 
12148
12174
  var _excluded$6 = ["children"];
@@ -17206,7 +17232,7 @@
17206
17232
 
17207
17233
  // Results can be `null` when the first search is stalled.
17208
17234
  // In this case, we skip the update.
17209
- // See: https://github.com/algolia/instantsearch.js/blob/20996c7a159988c58e00ff24d2d2dc98af8b980f/src/widgets/index/index.ts#L652-L657
17235
+ // See: https://github.com/algolia/instantsearch/blob/20996c7a159988c58e00ff24d2d2dc98af8b980f/src/widgets/index/index.ts#L652-L657
17210
17236
  if (results !== null) {
17211
17237
  setSearchResults({
17212
17238
  results: results,
@@ -17304,6 +17330,33 @@
17304
17330
  };
17305
17331
  }
17306
17332
 
17333
+ // This is needed in order to work with RSC Suspense, perhaps they will later provide a wrapper.
17334
+
17335
+ function isStatefulPromise(promise) {
17336
+ return 'status' in promise;
17337
+ }
17338
+ function wrapPromiseWithState(promise) {
17339
+ if (isStatefulPromise(promise)) {
17340
+ return promise;
17341
+ }
17342
+ var pendingPromise = promise;
17343
+ pendingPromise.status = 'pending';
17344
+ pendingPromise.then(function (value) {
17345
+ if (pendingPromise.status === 'pending') {
17346
+ var fulfilledPromise = pendingPromise;
17347
+ fulfilledPromise.status = 'fulfilled';
17348
+ fulfilledPromise.value = value;
17349
+ }
17350
+ }, function (reason) {
17351
+ if (pendingPromise.status === 'pending') {
17352
+ var rejectedPromise = pendingPromise;
17353
+ rejectedPromise.status = 'rejected';
17354
+ rejectedPromise.reason = reason;
17355
+ }
17356
+ });
17357
+ return promise;
17358
+ }
17359
+
17307
17360
  function _typeof$D(obj) {
17308
17361
  "@babel/helpers - typeof";
17309
17362
 
@@ -17501,6 +17554,7 @@
17501
17554
  exports.DynamicWidgets = DynamicWidgets;
17502
17555
  exports.Index = Index;
17503
17556
  exports.InstantSearch = InstantSearch$1;
17557
+ exports.InstantSearchRSCContext = InstantSearchRSCContext;
17504
17558
  exports.InstantSearchSSRProvider = InstantSearchSSRProvider;
17505
17559
  exports.InstantSearchServerContext = InstantSearchServerContext;
17506
17560
  exports.getServerState = getServerState;
@@ -17516,11 +17570,13 @@
17516
17570
  exports.useHitsPerPage = useHitsPerPage;
17517
17571
  exports.useInfiniteHits = useInfiniteHits;
17518
17572
  exports.useInstantSearch = useInstantSearch;
17573
+ exports.useInstantSearchContext = useInstantSearchContext;
17519
17574
  exports.useMenu = useMenu;
17520
17575
  exports.useNumericMenu = useNumericMenu;
17521
17576
  exports.usePagination = usePagination;
17522
17577
  exports.usePoweredBy = usePoweredBy;
17523
17578
  exports.useQueryRules = useQueryRules;
17579
+ exports.useRSCContext = useRSCContext;
17524
17580
  exports.useRange = useRange;
17525
17581
  exports.useRefinementList = useRefinementList;
17526
17582
  exports.useSearchBox = useSearchBox;
@@ -17528,6 +17584,7 @@
17528
17584
  exports.useStats = useStats;
17529
17585
  exports.useToggleRefinement = useToggleRefinement;
17530
17586
  exports.version = version;
17587
+ exports.wrapPromiseWithState = wrapPromiseWithState;
17531
17588
 
17532
17589
  Object.defineProperty(exports, '__esModule', { value: true });
17533
17590