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,124 +1,124 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
- function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
5
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
6
- function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
- import InstantSearch, { INSTANTSEARCH_FUTURE_DEFAULTS } from "instantsearch.js/es/lib/InstantSearch.js";
8
- import { useCallback, useRef, version as ReactVersion } from 'react';
9
- import { useSyncExternalStore } from "use-sync-external-store/shim/index.js";
10
- import version from "../version.js";
11
- import { dequal } from "./dequal.js";
12
- import { useForceUpdate } from "./useForceUpdate.js";
13
- import { useInstantSearchServerContext } from "./useInstantSearchServerContext.js";
14
- import { useInstantSearchSSRContext } from "./useInstantSearchSSRContext.js";
15
- import { useRSCContext } from "./useRSCContext.js";
16
- import { warn } from "./warn.js";
17
- var defaultUserAgents = ["react (".concat(ReactVersion, ")"), "react-instantsearch (".concat(version, ")"), "react-instantsearch-core (".concat(version, ")")];
18
- var serverUserAgent = "react-instantsearch-server (".concat(version, ")");
1
+ import { _ as _$1 } from '@swc/helpers/cjs/_object_spread.cjs';
2
+ import { _ } from '@swc/helpers/cjs/_to_consumable_array.cjs';
3
+ import InstantSearch, { INSTANTSEARCH_FUTURE_DEFAULTS } from 'instantsearch.js/es/lib/InstantSearch.js';
4
+ import { useRef, useCallback, version } from 'react';
5
+ import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
6
+ import version$1 from '../version.js';
7
+ import { dequal } from './dequal.js';
8
+ import { useForceUpdate } from './useForceUpdate.js';
9
+ import { useInstantSearchServerContext } from './useInstantSearchServerContext.js';
10
+ import { useInstantSearchSSRContext } from './useInstantSearchSSRContext.js';
11
+ import { useRSCContext } from './useRSCContext.js';
12
+
13
+ var defaultUserAgents = [
14
+ "react (".concat(version, ")"),
15
+ "react-instantsearch (".concat(version$1, ")"),
16
+ "react-instantsearch-core (".concat(version$1, ")")
17
+ ];
18
+ var serverUserAgent = "react-instantsearch-server (".concat(version$1, ")");
19
19
  var nextUserAgent = function nextUserAgent(nextVersion) {
20
- return nextVersion ? "next.js (".concat(nextVersion, ")") : null;
20
+ return nextVersion ? "next.js (".concat(nextVersion, ")") : null;
21
21
  };
22
- export function useInstantSearchApi(props) {
23
- var forceUpdate = useForceUpdate();
24
- var serverContext = useInstantSearchServerContext();
25
- var serverState = useInstantSearchSSRContext();
26
- var _useRSCContext = useRSCContext(),
27
- waitForResultsRef = _useRSCContext.waitForResultsRef;
28
- var initialResults = serverState === null || serverState === void 0 ? void 0 : serverState.initialResults;
29
- var prevPropsRef = useRef(props);
30
- var shouldRenderAtOnce = serverContext || initialResults || waitForResultsRef;
31
- var searchRef = useRef(null);
32
- // As we need to render on mount with SSR, using the local ref above in `StrictMode` will
33
- // create and start two instances of InstantSearch. To avoid this, we instead discard it and use
34
- // an upward ref from `InstantSearchSSRContext` as it has already been mounted a second time at this point.
35
- if (serverState !== null && serverState !== void 0 && serverState.ssrSearchRef) {
36
- searchRef = serverState.ssrSearchRef;
37
- }
38
- if (searchRef.current === null) {
39
- // We don't use the `instantsearch()` function because it comes with other
40
- // top-level APIs that we don't need.
41
- // See https://github.com/algolia/instantsearch/blob/5b529f43d8acc680f85837eaaa41f7fd03a3f833/src/index.es.ts#L63-L86
42
- var search = new InstantSearch(props);
43
- search._schedule = function _schedule(cb) {
44
- search._schedule.queue.push(cb);
45
- clearTimeout(search._schedule.timer);
46
- search._schedule.timer = setTimeout(function () {
47
- search._schedule.queue.forEach(function (callback) {
48
- callback();
49
- });
50
- search._schedule.queue = [];
51
- }, 0);
52
- };
53
- search._schedule.queue = [];
54
- if (shouldRenderAtOnce) {
55
- // InstantSearch.js has a private Initial Results API that lets us inject
56
- // results on the search instance.
57
- // On the server, we default the initial results to an empty object so that
58
- // InstantSearch.js doesn't schedule a search that isn't used, leading to
59
- // an additional network request. (This is equivalent to monkey-patching
60
- // `scheduleSearch` to a noop.)
61
- search._initialResults = initialResults || {};
62
- // We don't rely on the `defer` to reset the schedule search, but will call
63
- // `search._resetScheduleSearch()` manually in the effect after children
64
- // mount in `InstantSearch`.
65
- search._manuallyResetScheduleSearch = true;
66
- }
67
- addAlgoliaAgents(props.searchClient, [].concat(defaultUserAgents, [serverContext && serverUserAgent, nextUserAgent(getNextVersion())]));
68
-
69
- // On the server, we start the search early to compute the search parameters.
70
- // On SSR, we start the search early to directly catch up with the lifecycle
71
- // and render.
72
- if (shouldRenderAtOnce) {
73
- search.start();
74
- }
75
- if (serverContext) {
76
- // We notify `getServerState()` of the InstantSearch internals to retrieve
77
- // the server state and pass it to the render on SSR.
78
- serverContext.notifyServer({
79
- search: search
80
- });
81
- }
82
- warnNextRouter(props.routing);
83
- warnNextAppDir(Boolean(waitForResultsRef));
84
- searchRef.current = search;
85
- }
86
- {
87
- var _search = searchRef.current;
88
- var prevProps = prevPropsRef.current;
89
- if (prevProps.indexName !== props.indexName) {
90
- _search.helper.setIndex(props.indexName || '').search();
91
- prevPropsRef.current = props;
22
+ function useInstantSearchApi(props) {
23
+ var forceUpdate = useForceUpdate();
24
+ var serverContext = useInstantSearchServerContext();
25
+ var serverState = useInstantSearchSSRContext();
26
+ var waitForResultsRef = useRSCContext().waitForResultsRef;
27
+ var initialResults = serverState === null || serverState === void 0 ? void 0 : serverState.initialResults;
28
+ var prevPropsRef = useRef(props);
29
+ var shouldRenderAtOnce = serverContext || initialResults || waitForResultsRef;
30
+ var searchRef = useRef(null);
31
+ // As we need to render on mount with SSR, using the local ref above in `StrictMode` will
32
+ // create and start two instances of InstantSearch. To avoid this, we instead discard it and use
33
+ // an upward ref from `InstantSearchSSRContext` as it has already been mounted a second time at this point.
34
+ if (serverState === null || serverState === void 0 ? void 0 : serverState.ssrSearchRef) {
35
+ searchRef = serverState.ssrSearchRef;
92
36
  }
93
- if (prevProps.searchClient !== props.searchClient) {
94
- process.env.NODE_ENV === 'development' ? warn(false, 'The `searchClient` prop of `<InstantSearch>` changed between renders, which may cause more search requests than necessary. If this is an unwanted behavior, please provide a stable reference: https://www.algolia.com/doc/api-reference/widgets/instantsearch/react/#widget-param-searchclient') : void 0;
95
- addAlgoliaAgents(props.searchClient, [].concat(defaultUserAgents, [serverContext && serverUserAgent]));
96
- _search.mainHelper.setClient(props.searchClient).search();
97
- prevPropsRef.current = props;
98
- }
99
- if (prevProps.onStateChange !== props.onStateChange) {
100
- _search.onStateChange = props.onStateChange;
101
- prevPropsRef.current = props;
102
- }
103
- if (prevProps.searchFunction !== props.searchFunction) {
104
- // Updating the `searchFunction` to `undefined` is not supported by
105
- // InstantSearch.js, so it will throw an error.
106
- // This is a fair behavior until we add an update API in InstantSearch.js.
107
- _search._searchFunction = props.searchFunction;
108
- prevPropsRef.current = props;
109
- }
110
- if (prevProps.stalledSearchDelay !== props.stalledSearchDelay) {
111
- var _props$stalledSearchD;
112
- // The default `stalledSearchDelay` in InstantSearch.js is 200ms.
113
- // We need to reset it when it's undefined to get back to the original value.
114
- _search._stalledSearchDelay = (_props$stalledSearchD = props.stalledSearchDelay) !== null && _props$stalledSearchD !== void 0 ? _props$stalledSearchD : 200;
115
- prevPropsRef.current = props;
116
- }
117
- if (!dequal(prevProps.future, props.future)) {
118
- _search.future = _objectSpread(_objectSpread({}, INSTANTSEARCH_FUTURE_DEFAULTS), props.future);
119
- prevPropsRef.current = props;
37
+ if (searchRef.current === null) {
38
+ // We don't use the `instantsearch()` function because it comes with other
39
+ // top-level APIs that we don't need.
40
+ // See https://github.com/algolia/instantsearch/blob/5b529f43d8acc680f85837eaaa41f7fd03a3f833/src/index.es.ts#L63-L86
41
+ var search = new InstantSearch(props);
42
+ search._schedule = function _schedule(cb) {
43
+ search._schedule.queue.push(cb);
44
+ clearTimeout(search._schedule.timer);
45
+ search._schedule.timer = setTimeout(function() {
46
+ search._schedule.queue.forEach(function(callback) {
47
+ callback();
48
+ });
49
+ search._schedule.queue = [];
50
+ }, 0);
51
+ };
52
+ search._schedule.queue = [];
53
+ if (shouldRenderAtOnce) {
54
+ // InstantSearch.js has a private Initial Results API that lets us inject
55
+ // results on the search instance.
56
+ // On the server, we default the initial results to an empty object so that
57
+ // InstantSearch.js doesn't schedule a search that isn't used, leading to
58
+ // an additional network request. (This is equivalent to monkey-patching
59
+ // `scheduleSearch` to a noop.)
60
+ search._initialResults = initialResults || {};
61
+ // We don't rely on the `defer` to reset the schedule search, but will call
62
+ // `search._resetScheduleSearch()` manually in the effect after children
63
+ // mount in `InstantSearch`.
64
+ search._manuallyResetScheduleSearch = true;
65
+ }
66
+ addAlgoliaAgents(props.searchClient, _(defaultUserAgents).concat([
67
+ serverContext && serverUserAgent,
68
+ nextUserAgent(getNextVersion())
69
+ ]));
70
+ // On the server, we start the search early to compute the search parameters.
71
+ // On SSR, we start the search early to directly catch up with the lifecycle
72
+ // and render.
73
+ if (shouldRenderAtOnce) {
74
+ search.start();
75
+ }
76
+ if (serverContext) {
77
+ // We notify `getServerState()` of the InstantSearch internals to retrieve
78
+ // the server state and pass it to the render on SSR.
79
+ serverContext.notifyServer({
80
+ search: search
81
+ });
82
+ }
83
+ warnNextRouter(props.routing);
84
+ searchRef.current = search;
120
85
  }
121
-
86
+ {
87
+ var search1 = searchRef.current;
88
+ var prevProps = prevPropsRef.current;
89
+ if (prevProps.indexName !== props.indexName) {
90
+ search1.helper.setIndex(props.indexName || '').search();
91
+ prevPropsRef.current = props;
92
+ }
93
+ if (prevProps.searchClient !== props.searchClient) {
94
+ addAlgoliaAgents(props.searchClient, _(defaultUserAgents).concat([
95
+ serverContext && serverUserAgent
96
+ ]));
97
+ search1.mainHelper.setClient(props.searchClient).search();
98
+ prevPropsRef.current = props;
99
+ }
100
+ if (prevProps.onStateChange !== props.onStateChange) {
101
+ search1.onStateChange = props.onStateChange;
102
+ prevPropsRef.current = props;
103
+ }
104
+ if (prevProps.searchFunction !== props.searchFunction) {
105
+ // Updating the `searchFunction` to `undefined` is not supported by
106
+ // InstantSearch.js, so it will throw an error.
107
+ // This is a fair behavior until we add an update API in InstantSearch.js.
108
+ search1._searchFunction = props.searchFunction;
109
+ prevPropsRef.current = props;
110
+ }
111
+ if (prevProps.stalledSearchDelay !== props.stalledSearchDelay) {
112
+ var _props_stalledSearchDelay;
113
+ // The default `stalledSearchDelay` in InstantSearch.js is 200ms.
114
+ // We need to reset it when it's undefined to get back to the original value.
115
+ search1._stalledSearchDelay = (_props_stalledSearchDelay = props.stalledSearchDelay) !== null && _props_stalledSearchDelay !== void 0 ? _props_stalledSearchDelay : 200;
116
+ prevPropsRef.current = props;
117
+ }
118
+ if (!dequal(prevProps.future, props.future)) {
119
+ search1.future = _$1({}, INSTANTSEARCH_FUTURE_DEFAULTS, props.future);
120
+ prevPropsRef.current = props;
121
+ }
122
122
  // Updating the `routing` prop is not supported because InstantSearch.js
123
123
  // doesn't let us change it. This might not be a problem though, because `routing`
124
124
  // shouldn't need to be dynamic.
@@ -126,87 +126,70 @@ export function useInstantSearchApi(props) {
126
126
  // it privately on the InstantSearch instance. Another way would be to
127
127
  // manually inject the routing middleware in this library, and not rely
128
128
  // on the provided `routing` prop.
129
- }
130
- var cleanupTimerRef = useRef(null);
131
- var store = useSyncExternalStore(useCallback(function () {
132
- var search = searchRef.current;
133
-
134
- // Scenario 1: the component mounts.
135
- if (cleanupTimerRef.current === null) {
136
- // On SSR, the instance is already started so we don't start it again.
137
- if (!search.started) {
138
- search.start();
139
- forceUpdate();
140
- }
141
- }
142
- // Scenario 2: the component updates.
143
- else {
144
- // We cancel the previous cleanup function because we don't want to
145
- // dispose the search during an update.
146
- clearTimeout(cleanupTimerRef.current);
147
- search._preventWidgetCleanup = false;
148
129
  }
149
- return function () {
150
- if (serverState !== null && serverState !== void 0 && serverState.ssrSearchRef) {
151
- return;
152
- }
153
- function cleanup() {
154
- search.dispose();
155
- }
156
- clearTimeout(search._schedule.timer);
157
- // We clean up only when the component that uses this subscription unmounts,
158
- // but not when it updates, because it would dispose the instance, which
159
- // would remove all the widgets and break routing.
160
- // Executing the cleanup function in a `setTimeout()` lets us cancel it
161
- // in the next effect.
162
- // (There might be better ways to do this.)
163
- cleanupTimerRef.current = setTimeout(cleanup);
164
- // We need to prevent the `useWidget` cleanup function so that widgets
165
- // are not removed before the instance is disposed, triggering
166
- // an unwanted search request.
167
- search._preventWidgetCleanup = true;
168
- };
169
- }, [forceUpdate, serverState]), function () {
170
- return searchRef.current;
171
- }, function () {
172
- return searchRef.current;
173
- });
174
- return store;
130
+ var cleanupTimerRef = useRef(null);
131
+ var store = useSyncExternalStore(useCallback(function() {
132
+ var search = searchRef.current;
133
+ // Scenario 1: the component mounts.
134
+ if (cleanupTimerRef.current === null) {
135
+ // On SSR, the instance is already started so we don't start it again.
136
+ if (!search.started) {
137
+ search.start();
138
+ forceUpdate();
139
+ }
140
+ } else {
141
+ // We cancel the previous cleanup function because we don't want to
142
+ // dispose the search during an update.
143
+ clearTimeout(cleanupTimerRef.current);
144
+ search._preventWidgetCleanup = false;
145
+ }
146
+ return function() {
147
+ if (serverState === null || serverState === void 0 ? void 0 : serverState.ssrSearchRef) {
148
+ return;
149
+ }
150
+ function cleanup() {
151
+ search.dispose();
152
+ }
153
+ clearTimeout(search._schedule.timer);
154
+ // We clean up only when the component that uses this subscription unmounts,
155
+ // but not when it updates, because it would dispose the instance, which
156
+ // would remove all the widgets and break routing.
157
+ // Executing the cleanup function in a `setTimeout()` lets us cancel it
158
+ // in the next effect.
159
+ // (There might be better ways to do this.)
160
+ cleanupTimerRef.current = setTimeout(cleanup);
161
+ // We need to prevent the `useWidget` cleanup function so that widgets
162
+ // are not removed before the instance is disposed, triggering
163
+ // an unwanted search request.
164
+ search._preventWidgetCleanup = true;
165
+ };
166
+ }, [
167
+ forceUpdate,
168
+ serverState
169
+ ]), function() {
170
+ return searchRef.current;
171
+ }, function() {
172
+ return searchRef.current;
173
+ });
174
+ return store;
175
175
  }
176
176
  function addAlgoliaAgents(searchClient, userAgents) {
177
- if (typeof searchClient.addAlgoliaAgent !== 'function') {
178
- return;
179
- }
180
- userAgents.filter(Boolean).forEach(function (userAgent) {
181
- searchClient.addAlgoliaAgent(userAgent);
182
- });
183
- }
184
- function warnNextRouter(routing) {
185
- if (process.env.NODE_ENV === 'development') {
186
- var _routing$router;
187
- if (!routing || typeof window === 'undefined' || !('__NEXT_DATA__' in window)) {
188
- return;
177
+ if (typeof searchClient.addAlgoliaAgent !== 'function') {
178
+ return;
189
179
  }
190
- var isUsingNextRouter =
191
- // @ts-expect-error: _isNextRouter is only set on the Next.js router
192
- routing !== true && (routing === null || routing === void 0 ? void 0 : (_routing$router = routing.router) === null || _routing$router === void 0 ? void 0 : _routing$router._isNextRouter);
193
- process.env.NODE_ENV === 'development' ? warn(isUsingNextRouter, "\nYou are using Next.js with InstantSearch without the \"react-instantsearch-router-nextjs\" package.\nThis package is recommended to make the routing work correctly with Next.js.\nPlease check its usage instructions: https://github.com/algolia/instantsearch/tree/master/packages/react-instantsearch-router-nextjs\n\nYou can ignore this warning if you are using a custom router that suits your needs, it won't be outputted in production builds.") : void 0;
194
- }
180
+ userAgents.filter(Boolean).forEach(function(userAgent) {
181
+ searchClient.addAlgoliaAgent(userAgent);
182
+ });
195
183
  }
196
- function warnNextAppDir(isRscContextDefined) {
197
- var _next;
198
- if (!(process.env.NODE_ENV === 'development') || typeof window === 'undefined' || isRscContextDefined) {
199
- return;
200
- }
201
- process.env.NODE_ENV === 'development' ? warn(Boolean((_next = window.next) === null || _next === void 0 ? void 0 : _next.appDir) === false, "\nWe've detected you are using Next.js with the App Router.\nWe released a package called \"react-instantsearch-nextjs\" that makes SSR work with the App Router.\nPlease check its usage instructions: https://www.algolia.com/doc/guides/building-search-ui/going-further/server-side-rendering/react/#with-nextjs-app-router\n\nThis warning will not be outputted in production builds.") : void 0;
184
+ function warnNextRouter(routing) {
202
185
  }
203
-
204
186
  /**
205
187
  * Gets the version of Next.js if it is available in the `window` object,
206
188
  * otherwise it returns the NEXT_RUNTIME environment variable (in SSR),
207
189
  * which is either `nodejs` or `edge`.
208
- */
209
- function getNextVersion() {
210
- var _next2, _process$env;
211
- 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);
212
- }
190
+ */ function getNextVersion() {
191
+ var _window_next, _process_env;
192
+ return typeof window !== 'undefined' && ((_window_next = window.next) === null || _window_next === void 0 ? void 0 : _window_next.version) || (typeof process !== 'undefined' ? (_process_env = process.env) === null || _process_env === void 0 ? void 0 : _process_env.NEXT_RUNTIME : undefined);
193
+ }
194
+
195
+ export { useInstantSearchApi };
@@ -1,8 +1,11 @@
1
1
  import { useContext } from 'react';
2
- import { InstantSearchContext } from "./InstantSearchContext.js";
3
- import { invariant } from "./invariant.js";
4
- export function useInstantSearchContext() {
5
- var search = useContext(InstantSearchContext);
6
- invariant(search !== null, 'Hooks must be used inside the <InstantSearch> component.\n\n' + 'They are not compatible with the `react-instantsearch-core@6.x` and `react-instantsearch-dom` packages, so make sure to use the <InstantSearch> component from `react-instantsearch-core@7.x`.');
7
- return search;
8
- }
2
+ import { InstantSearchContext } from './InstantSearchContext.js';
3
+ import { invariant } from './invariant.js';
4
+
5
+ function useInstantSearchContext() {
6
+ var search = useContext(InstantSearchContext);
7
+ invariant(search !== null);
8
+ return search;
9
+ }
10
+
11
+ export { useInstantSearchContext };
@@ -1,5 +1,8 @@
1
1
  import { useContext } from 'react';
2
- import { InstantSearchSSRContext } from "./InstantSearchSSRContext.js";
3
- export function useInstantSearchSSRContext() {
4
- return useContext(InstantSearchSSRContext);
5
- }
2
+ import { InstantSearchSSRContext } from './InstantSearchSSRContext.js';
3
+
4
+ function useInstantSearchSSRContext() {
5
+ return useContext(InstantSearchSSRContext);
6
+ }
7
+
8
+ export { useInstantSearchSSRContext };
@@ -1,5 +1,8 @@
1
1
  import { useContext } from 'react';
2
- import { InstantSearchServerContext } from "../components/InstantSearchServerContext.js";
3
- export function useInstantSearchServerContext() {
4
- return useContext(InstantSearchServerContext);
5
- }
2
+ import { InstantSearchServerContext } from '../components/InstantSearchServerContext.js';
3
+
4
+ function useInstantSearchServerContext() {
5
+ return useContext(InstantSearchServerContext);
6
+ }
7
+
8
+ export { useInstantSearchServerContext };
@@ -1,8 +1,9 @@
1
- import { useEffect, useLayoutEffect } from 'react';
1
+ import { useLayoutEffect, useEffect } from 'react';
2
2
 
3
3
  /**
4
4
  * `useLayoutEffect` that doesn't show a warning when server-side rendering.
5
5
  *
6
6
  * It uses `useEffect` on the server (no-op), and `useLayoutEffect` on the browser.
7
- */
8
- export var useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
7
+ */ var useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
8
+
9
+ export { useIsomorphicLayoutEffect };
@@ -1,5 +1,8 @@
1
1
  import { useContext } from 'react';
2
- import { InstantSearchRSCContext } from "./InstantSearchRSCContext.js";
3
- export function useRSCContext() {
4
- return useContext(InstantSearchRSCContext);
5
- }
2
+ import { InstantSearchRSCContext } from './InstantSearchRSCContext.js';
3
+
4
+ function useRSCContext() {
5
+ return useContext(InstantSearchRSCContext);
6
+ }
7
+
8
+ export { useRSCContext };
@@ -1,59 +1,55 @@
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 { isIndexWidget } from "instantsearch.js/es/lib/utils/index.js";
8
- import { useEffect, useState } from 'react';
9
- import { getIndexSearchResults } from "./getIndexSearchResults.js";
10
- import { useIndexContext } from "./useIndexContext.js";
11
- import { useInstantSearchContext } from "./useInstantSearchContext.js";
12
- export function useSearchResults() {
13
- var search = useInstantSearchContext();
14
- var searchIndex = useIndexContext();
15
- var _useState = useState(function () {
16
- var indexSearchResults = getIndexSearchResults(searchIndex);
17
- // We do this not to leak `recommendResults` in the API.
18
- return {
19
- results: indexSearchResults.results,
20
- scopedResults: indexSearchResults.scopedResults
21
- };
22
- }),
23
- _useState2 = _slicedToArray(_useState, 2),
24
- searchResults = _useState2[0],
25
- setSearchResults = _useState2[1];
26
- useEffect(function () {
27
- function handleRender() {
28
- var results = searchIndex.getResults();
1
+ import { _ } from '@swc/helpers/cjs/_sliced_to_array.cjs';
2
+ import { isIndexWidget } from 'instantsearch.js/es/lib/utils/index.js';
3
+ import { useState, useEffect } from 'react';
4
+ import { getIndexSearchResults } from './getIndexSearchResults.js';
5
+ import { useIndexContext } from './useIndexContext.js';
6
+ import { useInstantSearchContext } from './useInstantSearchContext.js';
29
7
 
30
- // Results can be `null` when the first search is stalled.
31
- // In this case, we skip the update.
32
- // See: https://github.com/algolia/instantsearch/blob/20996c7a159988c58e00ff24d2d2dc98af8b980f/src/widgets/index/index.ts#L652-L657
33
- if (results !== null) {
34
- setSearchResults({
35
- results: results,
36
- scopedResults: searchIndex.getScopedResults()
37
- });
38
- } else if (search.mainIndex.getIndexName().length === 0) {
39
- // If the main index has no name, we get the scoped results from
40
- // the first child index instead.
41
- var childIndex = search.mainIndex.getWidgets().find(isIndexWidget);
42
- childIndex && setSearchResults({
43
- results: getIndexSearchResults(searchIndex).results,
44
- scopedResults: childIndex.getScopedResults()
45
- });
46
- }
47
- }
48
- search.addListener('render', handleRender);
8
+ function useSearchResults() {
9
+ var search = useInstantSearchContext();
10
+ var searchIndex = useIndexContext();
11
+ var _useState = _(useState(function() {
12
+ var indexSearchResults = getIndexSearchResults(searchIndex);
13
+ // We do this not to leak `recommendResults` in the API.
14
+ return {
15
+ results: indexSearchResults.results,
16
+ scopedResults: indexSearchResults.scopedResults
17
+ };
18
+ }), 2), searchResults = _useState[0], setSearchResults = _useState[1];
19
+ useEffect(function() {
20
+ function handleRender() {
21
+ var results = searchIndex.getResults();
22
+ // Results can be `null` when the first search is stalled.
23
+ // In this case, we skip the update.
24
+ // See: https://github.com/algolia/instantsearch/blob/20996c7a159988c58e00ff24d2d2dc98af8b980f/src/widgets/index/index.ts#L652-L657
25
+ if (results !== null) {
26
+ setSearchResults({
27
+ results: results,
28
+ scopedResults: searchIndex.getScopedResults()
29
+ });
30
+ } else if (search.mainIndex.getIndexName().length === 0) {
31
+ // If the main index has no name, we get the scoped results from
32
+ // the first child index instead.
33
+ var childIndex = search.mainIndex.getWidgets().find(isIndexWidget);
34
+ childIndex && setSearchResults({
35
+ results: getIndexSearchResults(searchIndex).results,
36
+ scopedResults: childIndex.getScopedResults()
37
+ });
38
+ }
39
+ }
40
+ search.addListener('render', handleRender);
41
+ // Force setting results 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);
47
+ };
48
+ }, [
49
+ search,
50
+ searchIndex
51
+ ]);
52
+ return searchResults;
53
+ }
49
54
 
50
- // Force setting results to mitigate potential race conditions where
51
- // render listener is added after search results have been returned.
52
- // This edge case is currently not covered by the tests.
53
- handleRender();
54
- return function () {
55
- search.removeListener('render', handleRender);
56
- };
57
- }, [search, searchIndex]);
58
- return searchResults;
59
- }
55
+ export { useSearchResults };