react-instantsearch-core 7.24.0 → 7.26.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.
Files changed (140) hide show
  1. package/dist/cjs/components/Configure.js +11 -17
  2. package/dist/cjs/components/DynamicWidgets.js +46 -53
  3. package/dist/cjs/components/Index.js +19 -22
  4. package/dist/cjs/components/InstantSearch.js +34 -36
  5. package/dist/cjs/components/InstantSearchSSRProvider.js +31 -41
  6. package/dist/cjs/components/InstantSearchServerContext.js +6 -10
  7. package/dist/cjs/connectors/useAutocomplete.js +8 -10
  8. package/dist/cjs/connectors/useBreadcrumb.js +8 -10
  9. package/dist/cjs/connectors/useChat.js +8 -10
  10. package/dist/cjs/connectors/useClearRefinements.js +8 -10
  11. package/dist/cjs/connectors/useConfigure.js +10 -12
  12. package/dist/cjs/connectors/useCurrentRefinements.js +8 -10
  13. package/dist/cjs/connectors/useDynamicWidgets.js +14 -20
  14. package/dist/cjs/connectors/useFilterSuggestions.js +8 -10
  15. package/dist/cjs/connectors/useFrequentlyBoughtTogether.js +8 -10
  16. package/dist/cjs/connectors/useGeoSearch.js +8 -10
  17. package/dist/cjs/connectors/useHierarchicalMenu.js +8 -10
  18. package/dist/cjs/connectors/useHits.js +8 -10
  19. package/dist/cjs/connectors/useHitsPerPage.js +8 -10
  20. package/dist/cjs/connectors/useInfiniteHits.js +8 -10
  21. package/dist/cjs/connectors/useLookingSimilar.js +8 -10
  22. package/dist/cjs/connectors/useMenu.js +8 -10
  23. package/dist/cjs/connectors/useNumericMenu.js +8 -10
  24. package/dist/cjs/connectors/usePagination.js +8 -10
  25. package/dist/cjs/connectors/usePoweredBy.js +18 -19
  26. package/dist/cjs/connectors/useQueryRules.js +8 -10
  27. package/dist/cjs/connectors/useRange.js +8 -10
  28. package/dist/cjs/connectors/useRefinementList.js +8 -10
  29. package/dist/cjs/connectors/useRelatedProducts.js +8 -10
  30. package/dist/cjs/connectors/useSearchBox.js +8 -10
  31. package/dist/cjs/connectors/useSortBy.js +8 -10
  32. package/dist/cjs/connectors/useStats.js +8 -10
  33. package/dist/cjs/connectors/useToggleRefinement.js +8 -10
  34. package/dist/cjs/connectors/useTrendingItems.js +8 -10
  35. package/dist/cjs/hooks/useConnector.js +123 -139
  36. package/dist/cjs/hooks/useInstantSearch.js +59 -59
  37. package/dist/cjs/index.js +90 -519
  38. package/dist/cjs/lib/IndexContext.js +6 -10
  39. package/dist/cjs/lib/InstantSearchContext.js +6 -10
  40. package/dist/cjs/lib/InstantSearchRSCContext.js +11 -12
  41. package/dist/cjs/lib/InstantSearchSSRContext.js +6 -10
  42. package/dist/cjs/lib/createSearchResults.js +24 -25
  43. package/dist/cjs/lib/dequal.js +33 -40
  44. package/dist/cjs/lib/getIndexSearchResults.js +23 -30
  45. package/dist/cjs/lib/invariant.js +11 -17
  46. package/dist/cjs/lib/noop.js +8 -6
  47. package/dist/cjs/lib/use.js +26 -11
  48. package/dist/cjs/lib/useAppIdAndApiKey.js +10 -12
  49. package/dist/cjs/lib/useForceUpdate.js +12 -21
  50. package/dist/cjs/lib/useIndex.js +40 -37
  51. package/dist/cjs/lib/useIndexContext.js +11 -12
  52. package/dist/cjs/lib/useInstantSearchApi.js +174 -197
  53. package/dist/cjs/lib/useInstantSearchContext.js +11 -12
  54. package/dist/cjs/lib/useInstantSearchSSRContext.js +8 -9
  55. package/dist/cjs/lib/useInstantSearchServerContext.js +8 -9
  56. package/dist/cjs/lib/useIsomorphicLayoutEffect.js +6 -8
  57. package/dist/cjs/lib/useRSCContext.js +8 -9
  58. package/dist/cjs/lib/useSearchResults.js +54 -62
  59. package/dist/cjs/lib/useSearchState.js +53 -60
  60. package/dist/cjs/lib/useStableValue.js +15 -24
  61. package/dist/cjs/lib/useWidget.js +99 -95
  62. package/dist/cjs/lib/warn.js +11 -35
  63. package/dist/cjs/lib/wrapPromiseWithState.js +23 -26
  64. package/dist/cjs/package.json +4 -1
  65. package/dist/cjs/server/getServerState.js +81 -91
  66. package/dist/cjs/server/index.js +6 -15
  67. package/dist/cjs/version.js +6 -6
  68. package/dist/es/components/Configure.js +11 -13
  69. package/dist/es/components/DynamicWidgets.js +45 -47
  70. package/dist/es/components/Index.js +19 -17
  71. package/dist/es/components/InstantSearch.js +33 -29
  72. package/dist/es/components/InstantSearchSSRProvider.js +30 -35
  73. package/dist/es/components/InstantSearchServerContext.js +4 -4
  74. package/dist/es/connectors/useAutocomplete.js +8 -5
  75. package/dist/es/connectors/useBreadcrumb.js +8 -5
  76. package/dist/es/connectors/useChat.js +8 -5
  77. package/dist/es/connectors/useClearRefinements.js +8 -5
  78. package/dist/es/connectors/useConfigure.js +10 -7
  79. package/dist/es/connectors/useCurrentRefinements.js +8 -5
  80. package/dist/es/connectors/useDynamicWidgets.js +14 -15
  81. package/dist/es/connectors/useFilterSuggestions.js +8 -5
  82. package/dist/es/connectors/useFrequentlyBoughtTogether.js +8 -5
  83. package/dist/es/connectors/useGeoSearch.js +8 -5
  84. package/dist/es/connectors/useHierarchicalMenu.js +8 -5
  85. package/dist/es/connectors/useHits.js +8 -5
  86. package/dist/es/connectors/useHitsPerPage.js +8 -5
  87. package/dist/es/connectors/useInfiniteHits.js +8 -5
  88. package/dist/es/connectors/useLookingSimilar.js +8 -5
  89. package/dist/es/connectors/useMenu.js +8 -5
  90. package/dist/es/connectors/useNumericMenu.js +8 -5
  91. package/dist/es/connectors/usePagination.js +8 -5
  92. package/dist/es/connectors/usePoweredBy.js +18 -15
  93. package/dist/es/connectors/useQueryRules.js +8 -5
  94. package/dist/es/connectors/useRange.js +8 -5
  95. package/dist/es/connectors/useRefinementList.js +8 -5
  96. package/dist/es/connectors/useRelatedProducts.js +8 -5
  97. package/dist/es/connectors/useSearchBox.js +8 -5
  98. package/dist/es/connectors/useSortBy.js +8 -5
  99. package/dist/es/connectors/useStats.js +8 -5
  100. package/dist/es/connectors/useToggleRefinement.js +8 -5
  101. package/dist/es/connectors/useTrendingItems.js +8 -5
  102. package/dist/es/hooks/useConnector.js +122 -134
  103. package/dist/es/hooks/useInstantSearch.js +58 -54
  104. package/dist/es/index.js +43 -43
  105. package/dist/es/lib/IndexContext.js +4 -4
  106. package/dist/es/lib/InstantSearchContext.js +4 -4
  107. package/dist/es/lib/InstantSearchRSCContext.js +10 -7
  108. package/dist/es/lib/InstantSearchSSRContext.js +4 -4
  109. package/dist/es/lib/createSearchResults.js +23 -19
  110. package/dist/es/lib/dequal.js +33 -36
  111. package/dist/es/lib/getIndexSearchResults.js +23 -26
  112. package/dist/es/lib/invariant.js +10 -12
  113. package/dist/es/lib/noop.js +7 -1
  114. package/dist/es/lib/use.js +4 -2
  115. package/dist/es/lib/useAppIdAndApiKey.js +9 -7
  116. package/dist/es/lib/useForceUpdate.js +9 -15
  117. package/dist/es/lib/useIndex.js +39 -31
  118. package/dist/es/lib/useIndexContext.js +10 -7
  119. package/dist/es/lib/useInstantSearchApi.js +174 -191
  120. package/dist/es/lib/useInstantSearchContext.js +10 -7
  121. package/dist/es/lib/useInstantSearchSSRContext.js +7 -4
  122. package/dist/es/lib/useInstantSearchServerContext.js +7 -4
  123. package/dist/es/lib/useIsomorphicLayoutEffect.js +4 -3
  124. package/dist/es/lib/useRSCContext.js +7 -4
  125. package/dist/es/lib/useSearchResults.js +53 -57
  126. package/dist/es/lib/useSearchState.js +52 -55
  127. package/dist/es/lib/useStableValue.js +14 -19
  128. package/dist/es/lib/useWidget.js +98 -90
  129. package/dist/es/lib/warn.js +9 -29
  130. package/dist/es/lib/wrapPromiseWithState.js +23 -22
  131. package/dist/es/package.json +4 -0
  132. package/dist/es/server/getServerState.js +80 -85
  133. package/dist/es/server/index.js +1 -1
  134. package/dist/es/version.d.ts +1 -1
  135. package/dist/es/version.js +3 -1
  136. package/dist/umd/ReactInstantSearchCore.js +17488 -22329
  137. package/dist/umd/ReactInstantSearchCore.min.js +3 -3
  138. package/package.json +7 -11
  139. package/dist/umd/ReactInstantSearchCore.js.map +0 -1
  140. package/dist/umd/ReactInstantSearchCore.min.js.map +0 -1
@@ -1,57 +1,54 @@
1
- function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
2
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
4
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
5
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
- function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
7
- import { useCallback, useEffect, useState } from 'react';
8
- import { useIndexContext } from "./useIndexContext.js";
9
- import { useInstantSearchContext } from "./useInstantSearchContext.js";
10
- export function useSearchState() {
11
- var search = useInstantSearchContext();
12
- var searchIndex = useIndexContext();
13
- var indexId = searchIndex.getIndexId();
14
- var _useState = useState(function () {
15
- return search.getUiState();
16
- }),
17
- _useState2 = _slicedToArray(_useState, 2),
18
- uiState = _useState2[0],
19
- setLocalUiState = _useState2[1];
20
- var indexUiState = uiState[indexId];
21
- var _useState3 = useState(function () {
22
- return search.renderState;
23
- }),
24
- _useState4 = _slicedToArray(_useState3, 2),
25
- renderState = _useState4[0],
26
- setRenderState = _useState4[1];
27
- var indexRenderState = renderState[indexId] || {};
28
- var setUiState = useCallback(function (nextUiState) {
29
- search.setUiState(nextUiState);
30
- }, [search]);
31
- var setIndexUiState = useCallback(function (nextIndexUiState) {
32
- searchIndex.setIndexUiState(nextIndexUiState);
33
- }, [searchIndex]);
34
- useEffect(function () {
35
- function handleRender() {
36
- setLocalUiState(search.getUiState());
37
- setRenderState(search.renderState);
38
- }
39
- search.addListener('render', handleRender);
1
+ import { _ } from '@swc/helpers/cjs/_sliced_to_array.cjs';
2
+ import { useState, useCallback, useEffect } from 'react';
3
+ import { useIndexContext } from './useIndexContext.js';
4
+ import { useInstantSearchContext } from './useInstantSearchContext.js';
40
5
 
41
- // Force setting state to mitigate potential race conditions where
42
- // render listener is added after search results have been returned.
43
- // This edge case is currently not covered by the tests.
44
- handleRender();
45
- return function () {
46
- search.removeListener('render', handleRender);
6
+ function useSearchState() {
7
+ var search = useInstantSearchContext();
8
+ var searchIndex = useIndexContext();
9
+ var indexId = searchIndex.getIndexId();
10
+ var _useState = _(useState(function() {
11
+ return search.getUiState();
12
+ }), 2), uiState = _useState[0], setLocalUiState = _useState[1];
13
+ var indexUiState = uiState[indexId];
14
+ var _useState1 = _(useState(function() {
15
+ return search.renderState;
16
+ }), 2), renderState = _useState1[0], setRenderState = _useState1[1];
17
+ var indexRenderState = renderState[indexId] || {};
18
+ var setUiState = useCallback(function(nextUiState) {
19
+ search.setUiState(nextUiState);
20
+ }, [
21
+ search
22
+ ]);
23
+ var setIndexUiState = useCallback(function(nextIndexUiState) {
24
+ searchIndex.setIndexUiState(nextIndexUiState);
25
+ }, [
26
+ searchIndex
27
+ ]);
28
+ useEffect(function() {
29
+ function handleRender() {
30
+ setLocalUiState(search.getUiState());
31
+ setRenderState(search.renderState);
32
+ }
33
+ search.addListener('render', handleRender);
34
+ // Force setting state to mitigate potential race conditions where
35
+ // render listener is added after search results have been returned.
36
+ // This edge case is currently not covered by the tests.
37
+ handleRender();
38
+ return function() {
39
+ search.removeListener('render', handleRender);
40
+ };
41
+ }, [
42
+ search
43
+ ]);
44
+ return {
45
+ uiState: uiState,
46
+ setUiState: setUiState,
47
+ indexUiState: indexUiState,
48
+ setIndexUiState: setIndexUiState,
49
+ renderState: renderState,
50
+ indexRenderState: indexRenderState
47
51
  };
48
- }, [search]);
49
- return {
50
- uiState: uiState,
51
- setUiState: setUiState,
52
- indexUiState: indexUiState,
53
- setIndexUiState: setIndexUiState,
54
- renderState: renderState,
55
- indexRenderState: indexRenderState
56
- };
57
- }
52
+ }
53
+
54
+ export { useSearchState };
@@ -1,20 +1,15 @@
1
- function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
2
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
- function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
4
- function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
5
- function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
- function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
1
+ import { _ } from '@swc/helpers/cjs/_sliced_to_array.cjs';
7
2
  import { useState } from 'react';
8
- import { dequal } from "./dequal.js";
9
- export function useStableValue(value) {
10
- var _useState = useState(function () {
11
- return value;
12
- }),
13
- _useState2 = _slicedToArray(_useState, 2),
14
- stableValue = _useState2[0],
15
- setStableValue = _useState2[1];
16
- if (!dequal(stableValue, value)) {
17
- setStableValue(value);
18
- }
19
- return stableValue;
20
- }
3
+ import { dequal } from './dequal.js';
4
+
5
+ function useStableValue(value) {
6
+ var _useState = _(useState(function() {
7
+ return value;
8
+ }), 2), stableValue = _useState[0], setStableValue = _useState[1];
9
+ if (!dequal(stableValue, value)) {
10
+ setStableValue(value);
11
+ }
12
+ return stableValue;
13
+ }
14
+
15
+ export { useStableValue };
@@ -1,94 +1,102 @@
1
- import { useEffect, useRef } from 'react';
2
- import { dequal } from "./dequal.js";
3
- import { use } from "./use.js";
4
- import { useInstantSearchContext } from "./useInstantSearchContext.js";
5
- import { useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect.js";
6
- import { useRSCContext } from "./useRSCContext.js";
7
- import { warn } from "./warn.js";
8
- export function useWidget(_ref) {
9
- var _waitForResultsRef$cu, _waitForResultsRef$cu2;
10
- var widget = _ref.widget,
11
- parentIndex = _ref.parentIndex,
12
- props = _ref.props,
13
- shouldSsr = _ref.shouldSsr,
14
- skipSuspense = _ref.skipSuspense;
15
- var _useRSCContext = useRSCContext(),
16
- waitForResultsRef = _useRSCContext.waitForResultsRef,
17
- countRef = _useRSCContext.countRef,
18
- ignoreMultipleHooksWarning = _useRSCContext.ignoreMultipleHooksWarning;
19
- var prevPropsRef = useRef(props);
20
- useEffect(function () {
21
- prevPropsRef.current = props;
22
- }, [props]);
23
- var prevWidgetRef = useRef(widget);
24
- useEffect(function () {
25
- prevWidgetRef.current = widget;
26
- }, [widget]);
27
- var cleanupTimerRef = useRef(null);
28
- var shouldAddWidgetEarly = shouldSsr && !parentIndex.getWidgets().includes(widget);
29
- var search = useInstantSearchContext();
1
+ import { useRef, useEffect } from 'react';
2
+ import { dequal } from './dequal.js';
3
+ import { use } from './use.js';
4
+ import { useInstantSearchContext } from './useInstantSearchContext.js';
5
+ import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect.js';
6
+ import { useRSCContext } from './useRSCContext.js';
30
7
 
31
- // This effect is responsible for adding, removing, and updating the widget.
32
- // We need to support scenarios where the widget is remounted quickly, like in
33
- // Strict Mode, so that we don't lose its state, and therefore that we don't
34
- // break routing.
35
- useIsomorphicLayoutEffect(function () {
36
- var previousWidget = prevWidgetRef.current;
37
-
38
- // Scenario 1: the widget is added for the first time.
39
- if (!cleanupTimerRef.current) {
40
- if (!shouldSsr) {
41
- parentIndex.addWidgets([widget]);
42
- }
8
+ function useWidget(param) {
9
+ var widget = param.widget, parentIndex = param.parentIndex, props = param.props, shouldSsr = param.shouldSsr, skipSuspense = param.skipSuspense;
10
+ var _waitForResultsRef_current, _waitForResultsRef_current1;
11
+ var _useRSCContext = useRSCContext(), waitForResultsRef = _useRSCContext.waitForResultsRef, countRef = _useRSCContext.countRef; _useRSCContext.ignoreMultipleHooksWarning;
12
+ var prevPropsRef = useRef(props);
13
+ useEffect(function() {
14
+ prevPropsRef.current = props;
15
+ }, [
16
+ props
17
+ ]);
18
+ var prevWidgetRef = useRef(widget);
19
+ useEffect(function() {
20
+ prevWidgetRef.current = widget;
21
+ }, [
22
+ widget
23
+ ]);
24
+ var cleanupTimerRef = useRef(null);
25
+ var shouldAddWidgetEarly = shouldSsr && !parentIndex.getWidgets().includes(widget);
26
+ var search = useInstantSearchContext();
27
+ // This effect is responsible for adding, removing, and updating the widget.
28
+ // We need to support scenarios where the widget is remounted quickly, like in
29
+ // Strict Mode, so that we don't lose its state, and therefore that we don't
30
+ // break routing.
31
+ useIsomorphicLayoutEffect(function() {
32
+ var previousWidget = prevWidgetRef.current;
33
+ // Scenario 1: the widget is added for the first time.
34
+ if (!cleanupTimerRef.current) {
35
+ if (!shouldSsr) {
36
+ parentIndex.addWidgets([
37
+ widget
38
+ ]);
39
+ }
40
+ } else {
41
+ // We cancel the original effect cleanup because it may not be necessary if
42
+ // props haven't changed. (We manually call it if it is below.)
43
+ clearTimeout(cleanupTimerRef.current);
44
+ // Warning: if an unstable function prop is provided, `dequal` is not able
45
+ // to keep its reference and therefore will consider that props did change.
46
+ // This could unsollicitely remove/add the widget, therefore forget its state,
47
+ // and could be a source of confusion.
48
+ // If users face this issue, we should advise them to provide stable function
49
+ // references.
50
+ var arePropsEqual = dequal(props, prevPropsRef.current);
51
+ // If props did change, then we execute the cleanup function instantly
52
+ // and then add the widget back. This lets us add the widget without
53
+ // waiting for the scheduled cleanup function to finish (that we canceled
54
+ // above).
55
+ if (!arePropsEqual) {
56
+ parentIndex.removeWidgets([
57
+ previousWidget
58
+ ]);
59
+ parentIndex.addWidgets([
60
+ widget
61
+ ]);
62
+ }
63
+ }
64
+ return function() {
65
+ // We don't remove the widget right away, but rather schedule it so that
66
+ // we're able to cancel it in the next effect.
67
+ cleanupTimerRef.current = setTimeout(function() {
68
+ search._schedule(function() {
69
+ if (search._preventWidgetCleanup) return;
70
+ parentIndex.removeWidgets([
71
+ previousWidget
72
+ ]);
73
+ });
74
+ });
75
+ };
76
+ }, [
77
+ parentIndex,
78
+ widget,
79
+ shouldSsr,
80
+ search,
81
+ props
82
+ ]);
83
+ if (shouldAddWidgetEarly || (waitForResultsRef === null || waitForResultsRef === void 0 ? void 0 : (_waitForResultsRef_current = waitForResultsRef.current) === null || _waitForResultsRef_current === void 0 ? void 0 : _waitForResultsRef_current.status) === 'pending') {
84
+ parentIndex.addWidgets([
85
+ widget
86
+ ]);
43
87
  }
44
- // Scenario 2: the widget is rerendered or updated.
45
- else {
46
- // We cancel the original effect cleanup because it may not be necessary if
47
- // props haven't changed. (We manually call it if it is below.)
48
- clearTimeout(cleanupTimerRef.current);
49
-
50
- // Warning: if an unstable function prop is provided, `dequal` is not able
51
- // to keep its reference and therefore will consider that props did change.
52
- // This could unsollicitely remove/add the widget, therefore forget its state,
53
- // and could be a source of confusion.
54
- // If users face this issue, we should advise them to provide stable function
55
- // references.
56
- var arePropsEqual = dequal(props, prevPropsRef.current);
57
-
58
- // If props did change, then we execute the cleanup function instantly
59
- // and then add the widget back. This lets us add the widget without
60
- // waiting for the scheduled cleanup function to finish (that we canceled
61
- // above).
62
- if (!arePropsEqual) {
63
- parentIndex.removeWidgets([previousWidget]);
64
- parentIndex.addWidgets([widget]);
65
- }
88
+ if ((waitForResultsRef === null || waitForResultsRef === void 0 ? void 0 : waitForResultsRef.current) && !skipSuspense) {
89
+ var _search_helper;
90
+ use(waitForResultsRef.current);
91
+ // If we made a second request because of DynamicWidgets, we need to wait for the second result,
92
+ // except for DynamicWidgets itself which needs to render its children after the first result.
93
+ if (widget.$$type !== 'ais.dynamicWidgets' && ((_search_helper = search.helper) === null || _search_helper === void 0 ? void 0 : _search_helper.lastResults)) {
94
+ use(waitForResultsRef.current);
95
+ }
66
96
  }
67
- return function () {
68
- // We don't remove the widget right away, but rather schedule it so that
69
- // we're able to cancel it in the next effect.
70
- cleanupTimerRef.current = setTimeout(function () {
71
- search._schedule(function () {
72
- if (search._preventWidgetCleanup) return;
73
- parentIndex.removeWidgets([previousWidget]);
74
- });
75
- });
76
- };
77
- }, [parentIndex, widget, shouldSsr, search, props]);
78
- if (shouldAddWidgetEarly || (waitForResultsRef === null || waitForResultsRef === void 0 ? void 0 : (_waitForResultsRef$cu = waitForResultsRef.current) === null || _waitForResultsRef$cu === void 0 ? void 0 : _waitForResultsRef$cu.status) === 'pending') {
79
- parentIndex.addWidgets([widget]);
80
- }
81
- if (waitForResultsRef !== null && waitForResultsRef !== void 0 && waitForResultsRef.current && !skipSuspense) {
82
- var _search$helper;
83
- use(waitForResultsRef.current);
84
- // If we made a second request because of DynamicWidgets, we need to wait for the second result,
85
- // except for DynamicWidgets itself which needs to render its children after the first result.
86
- if (widget.$$type !== 'ais.dynamicWidgets' && (_search$helper = search.helper) !== null && _search$helper !== void 0 && _search$helper.lastResults) {
87
- use(waitForResultsRef.current);
97
+ if ((waitForResultsRef === null || waitForResultsRef === void 0 ? void 0 : (_waitForResultsRef_current1 = waitForResultsRef.current) === null || _waitForResultsRef_current1 === void 0 ? void 0 : _waitForResultsRef_current1.status) === 'fulfilled') {
98
+ countRef.current += 1;
88
99
  }
89
- }
90
- if ((waitForResultsRef === null || waitForResultsRef === void 0 ? void 0 : (_waitForResultsRef$cu2 = waitForResultsRef.current) === null || _waitForResultsRef$cu2 === void 0 ? void 0 : _waitForResultsRef$cu2.status) === 'fulfilled') {
91
- countRef.current += 1;
92
- process.env.NODE_ENV === 'development' ? warn(ignoreMultipleHooksWarning || countRef.current <= parentIndex.getWidgets().length, "We detected you may have a component with multiple InstantSearch hooks.\n\nWith Next.js, you need to set `skipSuspense` to `true` for all but the last hook in the component, otherwise, only the first hook will be rendered on the server.\n\nThis warning can be a false positive if you are using dynamic widgets or multi-index, in which case you can ignore it by setting `ignoreMultipleHooksWarning` to `true` in `<InstantSearchNext`.\n\nFor more information, see https://www.algolia.com/doc/guides/building-search-ui/going-further/server-side-rendering/react/#composing-hooks") : void 0;
93
- }
94
- }
100
+ }
101
+
102
+ export { useWidget };
@@ -1,33 +1,13 @@
1
- /* eslint-disable no-console, no-empty */
2
-
3
- export var warnCache = {
4
- current: {}
1
+ /* eslint-disable no-console, no-empty */ var warnCache = {
2
+ current: {}
5
3
  };
6
-
7
4
  /**
8
5
  * Logs a warning if the condition is not met.
9
6
  * This is used to log issues in development environment only.
10
- */
11
- export function warn(condition, message) {
12
- if (!(process.env.NODE_ENV === 'development')) {
13
- return;
14
- }
15
- if (condition) {
16
- return;
17
- }
18
- var sanitizedMessage = message.trim();
19
- var hasAlreadyPrinted = warnCache.current[sanitizedMessage];
20
- if (!hasAlreadyPrinted) {
21
- warnCache.current[sanitizedMessage] = true;
22
- var warning = "[InstantSearch] ".concat(sanitizedMessage);
23
- console.warn(warning);
24
- try {
25
- // Welcome to debugging InstantSearch.
26
- //
27
- // This error was thrown as a convenience so that you can find the source
28
- // of the warning that appears in the console by enabling "Pause on exceptions"
29
- // in your debugger.
30
- throw new Error(warning);
31
- } catch (error) {}
32
- }
33
- }
7
+ */ function warn(condition, message) {
8
+ {
9
+ return;
10
+ }
11
+ }
12
+
13
+ export { warn, warnCache };
@@ -1,26 +1,27 @@
1
1
  // This is needed in order to work with RSC Suspense, perhaps they will later provide a wrapper.
2
-
3
2
  function isStatefulPromise(promise) {
4
- return 'status' in promise;
3
+ return 'status' in promise;
5
4
  }
6
- export function wrapPromiseWithState(promise) {
7
- if (isStatefulPromise(promise)) {
8
- return promise;
9
- }
10
- var pendingPromise = promise;
11
- pendingPromise.status = 'pending';
12
- pendingPromise.then(function (value) {
13
- if (pendingPromise.status === 'pending') {
14
- var fulfilledPromise = pendingPromise;
15
- fulfilledPromise.status = 'fulfilled';
16
- fulfilledPromise.value = value;
17
- }
18
- }, function (reason) {
19
- if (pendingPromise.status === 'pending') {
20
- var rejectedPromise = pendingPromise;
21
- rejectedPromise.status = 'rejected';
22
- rejectedPromise.reason = reason;
5
+ function wrapPromiseWithState(promise) {
6
+ if (isStatefulPromise(promise)) {
7
+ return promise;
23
8
  }
24
- });
25
- return promise;
26
- }
9
+ var pendingPromise = promise;
10
+ pendingPromise.status = 'pending';
11
+ pendingPromise.then(function(value) {
12
+ if (pendingPromise.status === 'pending') {
13
+ var fulfilledPromise = pendingPromise;
14
+ fulfilledPromise.status = 'fulfilled';
15
+ fulfilledPromise.value = value;
16
+ }
17
+ }, function(reason) {
18
+ if (pendingPromise.status === 'pending') {
19
+ var rejectedPromise = pendingPromise;
20
+ rejectedPromise.status = 'rejected';
21
+ rejectedPromise.reason = reason;
22
+ }
23
+ });
24
+ return promise;
25
+ }
26
+
27
+ export { wrapPromiseWithState };
@@ -0,0 +1,4 @@
1
+ {
2
+ "type": "module",
3
+ "sideEffects": false
4
+ }
@@ -1,91 +1,86 @@
1
- import { getInitialResults, waitForResults } from "instantsearch.js/es/lib/server.js";
2
- import { walkIndex, resetWidgetId } from "instantsearch.js/es/lib/utils/index.js";
3
- import React from 'react';
4
- import { InstantSearchServerContext } from "../components/InstantSearchServerContext.js";
5
- import { InstantSearchSSRProvider } from "../components/InstantSearchSSRProvider.js";
1
+ import { waitForResults, getInitialResults } from 'instantsearch.js/es/lib/server.js';
2
+ import { resetWidgetId, walkIndex } from 'instantsearch.js/es/lib/utils/index.js';
3
+ import React__default from 'react';
4
+ import { InstantSearchServerContext } from '../components/InstantSearchServerContext.js';
5
+ import { InstantSearchSSRProvider } from '../components/InstantSearchSSRProvider.js';
6
+
6
7
  /**
7
8
  * Returns the InstantSearch server state from a component.
8
- */
9
- export function getServerState(children, _ref) {
10
- var renderToString = _ref.renderToString;
11
- var searchRef = {
12
- current: undefined
13
- };
14
- resetWidgetId();
15
- var createNotifyServer = function createNotifyServer() {
16
- var hasBeenNotified = false;
17
- var notifyServer = function notifyServer(_ref2) {
18
- var search = _ref2.search;
19
- if (hasBeenNotified) {
20
- throw new Error('getServerState should be called with a single InstantSearchSSRProvider and a single InstantSearch component.');
21
- }
22
- hasBeenNotified = true;
23
- searchRef.current = search;
9
+ */ function getServerState(children, param) {
10
+ var renderToString = param.renderToString;
11
+ var searchRef = {
12
+ current: undefined
24
13
  };
25
- return notifyServer;
26
- };
27
- return execute({
28
- children: children,
29
- renderToString: renderToString,
30
- searchRef: searchRef,
31
- notifyServer: createNotifyServer()
32
- }).then(function (serverState) {
33
- var shouldRefetch = false;
34
-
35
- // <DynamicWidgets> requires another query to retrieve the dynamic widgets
36
- // to render.
37
- walkIndex(searchRef.current.mainIndex, function (index) {
38
- shouldRefetch = shouldRefetch || index.getWidgets().some(function (widget) {
39
- return widget.$$type === 'ais.dynamicWidgets';
40
- });
41
- });
42
- if (shouldRefetch) {
43
- resetWidgetId();
44
- return execute({
45
- children: /*#__PURE__*/React.createElement(InstantSearchSSRProvider, serverState, children),
14
+ resetWidgetId();
15
+ var createNotifyServer = function createNotifyServer() {
16
+ var hasBeenNotified = false;
17
+ var notifyServer = function notifyServer(param) {
18
+ var search = param.search;
19
+ if (hasBeenNotified) {
20
+ throw new Error('getServerState should be called with a single InstantSearchSSRProvider and a single InstantSearch component.');
21
+ }
22
+ hasBeenNotified = true;
23
+ searchRef.current = search;
24
+ };
25
+ return notifyServer;
26
+ };
27
+ return execute({
28
+ children: children,
46
29
  renderToString: renderToString,
47
30
  searchRef: searchRef,
48
- notifyServer: createNotifyServer(),
49
- skipRecommend: true
50
- });
51
- }
52
- return serverState;
53
- });
31
+ notifyServer: createNotifyServer()
32
+ }).then(function(serverState) {
33
+ var shouldRefetch = false;
34
+ // <DynamicWidgets> requires another query to retrieve the dynamic widgets
35
+ // to render.
36
+ walkIndex(searchRef.current.mainIndex, function(index) {
37
+ shouldRefetch = shouldRefetch || index.getWidgets().some(function(widget) {
38
+ return widget.$$type === 'ais.dynamicWidgets';
39
+ });
40
+ });
41
+ if (shouldRefetch) {
42
+ resetWidgetId();
43
+ return execute({
44
+ children: /*#__PURE__*/ React__default.createElement(InstantSearchSSRProvider, serverState, children),
45
+ renderToString: renderToString,
46
+ searchRef: searchRef,
47
+ notifyServer: createNotifyServer(),
48
+ skipRecommend: true
49
+ });
50
+ }
51
+ return serverState;
52
+ });
54
53
  }
55
- function execute(_ref3) {
56
- var children = _ref3.children,
57
- renderToString = _ref3.renderToString,
58
- notifyServer = _ref3.notifyServer,
59
- searchRef = _ref3.searchRef,
60
- skipRecommend = _ref3.skipRecommend;
61
- return Promise.resolve().then(function () {
62
- renderToString(/*#__PURE__*/React.createElement(InstantSearchServerContext.Provider, {
63
- value: {
64
- notifyServer: notifyServer
65
- }
66
- }, children));
67
- }).then(function () {
68
- return (
69
- // We wait for the component to mount so that `notifyServer()` is called.
70
- new Promise(function (resolve) {
71
- return setTimeout(resolve, 0);
72
- })
73
- );
74
- }).then(function () {
75
- // If `notifyServer()` is not called by then, it means that <InstantSearch>
76
- // wasn't within the `children`.
77
- // We decide to go with a strict behavior in that case; throwing. If users have
78
- // some routes that don't mount the <InstantSearch> component, they would need
79
- // to try/catch the `getServerState()` call.
80
- // If this behavior turns out to be too strict for many users, we can decide
81
- // to warn instead of throwing.
82
- if (!searchRef.current) {
83
- throw new Error("Unable to retrieve InstantSearch's server state in `getServerState()`. Did you mount the <InstantSearch> component?");
84
- }
85
- return waitForResults(searchRef.current, skipRecommend);
86
- }).then(function (requestParamsList) {
87
- return {
88
- initialResults: getInitialResults(searchRef.current.mainIndex, requestParamsList)
89
- };
90
- });
91
- }
54
+ function execute(param) {
55
+ var children = param.children, renderToString = param.renderToString, notifyServer = param.notifyServer, searchRef = param.searchRef, skipRecommend = param.skipRecommend;
56
+ return Promise.resolve().then(function() {
57
+ renderToString(/*#__PURE__*/ React__default.createElement(InstantSearchServerContext.Provider, {
58
+ value: {
59
+ notifyServer: notifyServer
60
+ }
61
+ }, children));
62
+ }).then(function() {
63
+ return(// We wait for the component to mount so that `notifyServer()` is called.
64
+ new Promise(function(resolve) {
65
+ return setTimeout(resolve, 0);
66
+ }));
67
+ }).then(function() {
68
+ // If `notifyServer()` is not called by then, it means that <InstantSearch>
69
+ // wasn't within the `children`.
70
+ // We decide to go with a strict behavior in that case; throwing. If users have
71
+ // some routes that don't mount the <InstantSearch> component, they would need
72
+ // to try/catch the `getServerState()` call.
73
+ // If this behavior turns out to be too strict for many users, we can decide
74
+ // to warn instead of throwing.
75
+ if (!searchRef.current) {
76
+ throw new Error("Unable to retrieve InstantSearch's server state in `getServerState()`. Did you mount the <InstantSearch> component?");
77
+ }
78
+ return waitForResults(searchRef.current, skipRecommend);
79
+ }).then(function(requestParamsList) {
80
+ return {
81
+ initialResults: getInitialResults(searchRef.current.mainIndex, requestParamsList)
82
+ };
83
+ });
84
+ }
85
+
86
+ export { getServerState };
@@ -1 +1 @@
1
- export * from "./getServerState.js";
1
+ export { getServerState } from './getServerState.js';
@@ -1,2 +1,2 @@
1
- declare const _default: "7.24.0";
1
+ declare const _default: "7.26.0";
2
2
  export default _default;
@@ -1 +1,3 @@
1
- export default '7.24.0';
1
+ var version = '7.26.0';
2
+
3
+ export { version as default };