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.
- package/dist/cjs/components/Configure.js +11 -17
- package/dist/cjs/components/DynamicWidgets.js +46 -53
- package/dist/cjs/components/Index.js +19 -22
- package/dist/cjs/components/InstantSearch.js +34 -36
- package/dist/cjs/components/InstantSearchSSRProvider.js +31 -41
- package/dist/cjs/components/InstantSearchServerContext.js +6 -10
- package/dist/cjs/connectors/useAutocomplete.js +8 -10
- package/dist/cjs/connectors/useBreadcrumb.js +8 -10
- package/dist/cjs/connectors/useChat.js +8 -10
- package/dist/cjs/connectors/useClearRefinements.js +8 -10
- package/dist/cjs/connectors/useConfigure.js +10 -12
- package/dist/cjs/connectors/useCurrentRefinements.js +8 -10
- package/dist/cjs/connectors/useDynamicWidgets.js +14 -20
- package/dist/cjs/connectors/useFilterSuggestions.js +8 -10
- package/dist/cjs/connectors/useFrequentlyBoughtTogether.js +8 -10
- package/dist/cjs/connectors/useGeoSearch.js +8 -10
- package/dist/cjs/connectors/useHierarchicalMenu.js +8 -10
- package/dist/cjs/connectors/useHits.js +8 -10
- package/dist/cjs/connectors/useHitsPerPage.js +8 -10
- package/dist/cjs/connectors/useInfiniteHits.js +8 -10
- package/dist/cjs/connectors/useLookingSimilar.js +8 -10
- package/dist/cjs/connectors/useMenu.js +8 -10
- package/dist/cjs/connectors/useNumericMenu.js +8 -10
- package/dist/cjs/connectors/usePagination.js +8 -10
- package/dist/cjs/connectors/usePoweredBy.js +18 -19
- package/dist/cjs/connectors/useQueryRules.js +8 -10
- package/dist/cjs/connectors/useRange.js +8 -10
- package/dist/cjs/connectors/useRefinementList.js +8 -10
- package/dist/cjs/connectors/useRelatedProducts.js +8 -10
- package/dist/cjs/connectors/useSearchBox.js +8 -10
- package/dist/cjs/connectors/useSortBy.js +8 -10
- package/dist/cjs/connectors/useStats.js +8 -10
- package/dist/cjs/connectors/useToggleRefinement.js +8 -10
- package/dist/cjs/connectors/useTrendingItems.js +8 -10
- package/dist/cjs/hooks/useConnector.js +123 -139
- package/dist/cjs/hooks/useInstantSearch.js +59 -59
- package/dist/cjs/index.js +90 -519
- package/dist/cjs/lib/IndexContext.js +6 -10
- package/dist/cjs/lib/InstantSearchContext.js +6 -10
- package/dist/cjs/lib/InstantSearchRSCContext.js +11 -12
- package/dist/cjs/lib/InstantSearchSSRContext.js +6 -10
- package/dist/cjs/lib/createSearchResults.js +24 -25
- package/dist/cjs/lib/dequal.js +33 -40
- package/dist/cjs/lib/getIndexSearchResults.js +23 -30
- package/dist/cjs/lib/invariant.js +11 -17
- package/dist/cjs/lib/noop.js +8 -6
- package/dist/cjs/lib/use.js +26 -11
- package/dist/cjs/lib/useAppIdAndApiKey.js +10 -12
- package/dist/cjs/lib/useForceUpdate.js +12 -21
- package/dist/cjs/lib/useIndex.js +40 -37
- package/dist/cjs/lib/useIndexContext.js +11 -12
- package/dist/cjs/lib/useInstantSearchApi.js +174 -197
- package/dist/cjs/lib/useInstantSearchContext.js +11 -12
- package/dist/cjs/lib/useInstantSearchSSRContext.js +8 -9
- package/dist/cjs/lib/useInstantSearchServerContext.js +8 -9
- package/dist/cjs/lib/useIsomorphicLayoutEffect.js +6 -8
- package/dist/cjs/lib/useRSCContext.js +8 -9
- package/dist/cjs/lib/useSearchResults.js +54 -62
- package/dist/cjs/lib/useSearchState.js +53 -60
- package/dist/cjs/lib/useStableValue.js +15 -24
- package/dist/cjs/lib/useWidget.js +99 -95
- package/dist/cjs/lib/warn.js +11 -35
- package/dist/cjs/lib/wrapPromiseWithState.js +23 -26
- package/dist/cjs/package.json +4 -1
- package/dist/cjs/server/getServerState.js +81 -91
- package/dist/cjs/server/index.js +6 -15
- package/dist/cjs/version.js +6 -6
- package/dist/es/components/Configure.js +11 -13
- package/dist/es/components/DynamicWidgets.js +45 -47
- package/dist/es/components/Index.js +19 -17
- package/dist/es/components/InstantSearch.js +33 -29
- package/dist/es/components/InstantSearchSSRProvider.js +30 -35
- package/dist/es/components/InstantSearchServerContext.js +4 -4
- package/dist/es/connectors/useAutocomplete.js +8 -5
- package/dist/es/connectors/useBreadcrumb.js +8 -5
- package/dist/es/connectors/useChat.js +8 -5
- package/dist/es/connectors/useClearRefinements.js +8 -5
- package/dist/es/connectors/useConfigure.js +10 -7
- package/dist/es/connectors/useCurrentRefinements.js +8 -5
- package/dist/es/connectors/useDynamicWidgets.js +14 -15
- package/dist/es/connectors/useFilterSuggestions.js +8 -5
- package/dist/es/connectors/useFrequentlyBoughtTogether.js +8 -5
- package/dist/es/connectors/useGeoSearch.js +8 -5
- package/dist/es/connectors/useHierarchicalMenu.js +8 -5
- package/dist/es/connectors/useHits.js +8 -5
- package/dist/es/connectors/useHitsPerPage.js +8 -5
- package/dist/es/connectors/useInfiniteHits.js +8 -5
- package/dist/es/connectors/useLookingSimilar.js +8 -5
- package/dist/es/connectors/useMenu.js +8 -5
- package/dist/es/connectors/useNumericMenu.js +8 -5
- package/dist/es/connectors/usePagination.js +8 -5
- package/dist/es/connectors/usePoweredBy.js +18 -15
- package/dist/es/connectors/useQueryRules.js +8 -5
- package/dist/es/connectors/useRange.js +8 -5
- package/dist/es/connectors/useRefinementList.js +8 -5
- package/dist/es/connectors/useRelatedProducts.js +8 -5
- package/dist/es/connectors/useSearchBox.js +8 -5
- package/dist/es/connectors/useSortBy.js +8 -5
- package/dist/es/connectors/useStats.js +8 -5
- package/dist/es/connectors/useToggleRefinement.js +8 -5
- package/dist/es/connectors/useTrendingItems.js +8 -5
- package/dist/es/hooks/useConnector.js +122 -134
- package/dist/es/hooks/useInstantSearch.js +58 -54
- package/dist/es/index.js +43 -43
- package/dist/es/lib/IndexContext.js +4 -4
- package/dist/es/lib/InstantSearchContext.js +4 -4
- package/dist/es/lib/InstantSearchRSCContext.js +10 -7
- package/dist/es/lib/InstantSearchSSRContext.js +4 -4
- package/dist/es/lib/createSearchResults.js +23 -19
- package/dist/es/lib/dequal.js +33 -36
- package/dist/es/lib/getIndexSearchResults.js +23 -26
- package/dist/es/lib/invariant.js +10 -12
- package/dist/es/lib/noop.js +7 -1
- package/dist/es/lib/use.js +4 -2
- package/dist/es/lib/useAppIdAndApiKey.js +9 -7
- package/dist/es/lib/useForceUpdate.js +9 -15
- package/dist/es/lib/useIndex.js +39 -31
- package/dist/es/lib/useIndexContext.js +10 -7
- package/dist/es/lib/useInstantSearchApi.js +174 -191
- package/dist/es/lib/useInstantSearchContext.js +10 -7
- package/dist/es/lib/useInstantSearchSSRContext.js +7 -4
- package/dist/es/lib/useInstantSearchServerContext.js +7 -4
- package/dist/es/lib/useIsomorphicLayoutEffect.js +4 -3
- package/dist/es/lib/useRSCContext.js +7 -4
- package/dist/es/lib/useSearchResults.js +53 -57
- package/dist/es/lib/useSearchState.js +52 -55
- package/dist/es/lib/useStableValue.js +14 -19
- package/dist/es/lib/useWidget.js +98 -90
- package/dist/es/lib/warn.js +9 -29
- package/dist/es/lib/wrapPromiseWithState.js +23 -22
- package/dist/es/package.json +4 -0
- package/dist/es/server/getServerState.js +80 -85
- package/dist/es/server/index.js +1 -1
- package/dist/es/version.d.ts +1 -1
- package/dist/es/version.js +3 -1
- package/dist/umd/ReactInstantSearchCore.js +17488 -22329
- package/dist/umd/ReactInstantSearchCore.min.js +3 -3
- package/package.json +7 -11
- package/dist/umd/ReactInstantSearchCore.js.map +0 -1
- package/dist/umd/ReactInstantSearchCore.min.js.map +0 -1
|
@@ -1,132 +1,126 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
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; }
|
|
22
|
-
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; }
|
|
23
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
24
|
-
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); }
|
|
25
|
-
var defaultUserAgents = ["react (".concat(_react.version, ")"), "react-instantsearch (".concat(_version.default, ")"), "react-instantsearch-core (".concat(_version.default, ")")];
|
|
26
|
-
var serverUserAgent = "react-instantsearch-server (".concat(_version.default, ")");
|
|
3
|
+
var _object_spread = require('@swc/helpers/_/_object_spread');
|
|
4
|
+
var _to_consumable_array = require('@swc/helpers/_/_to_consumable_array');
|
|
5
|
+
var InstantSearch = require('instantsearch.js/cjs/lib/InstantSearch');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
var shim = require('use-sync-external-store/shim');
|
|
8
|
+
var version = require('../version.js');
|
|
9
|
+
var dequal = require('./dequal.js');
|
|
10
|
+
var useForceUpdate = require('./useForceUpdate.js');
|
|
11
|
+
var useInstantSearchServerContext = require('./useInstantSearchServerContext.js');
|
|
12
|
+
var useInstantSearchSSRContext = require('./useInstantSearchSSRContext.js');
|
|
13
|
+
var useRSCContext = require('./useRSCContext.js');
|
|
14
|
+
|
|
15
|
+
var defaultUserAgents = [
|
|
16
|
+
"react (".concat(React.version, ")"),
|
|
17
|
+
"react-instantsearch (".concat(version.default, ")"),
|
|
18
|
+
"react-instantsearch-core (".concat(version.default, ")")
|
|
19
|
+
];
|
|
20
|
+
var serverUserAgent = "react-instantsearch-server (".concat(version.default, ")");
|
|
27
21
|
var nextUserAgent = function nextUserAgent(nextVersion) {
|
|
28
|
-
|
|
22
|
+
return nextVersion ? "next.js (".concat(nextVersion, ")") : null;
|
|
29
23
|
};
|
|
30
24
|
function useInstantSearchApi(props) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
searchRef = serverState.ssrSearchRef;
|
|
45
|
-
}
|
|
46
|
-
if (searchRef.current === null) {
|
|
47
|
-
// We don't use the `instantsearch()` function because it comes with other
|
|
48
|
-
// top-level APIs that we don't need.
|
|
49
|
-
// See https://github.com/algolia/instantsearch/blob/5b529f43d8acc680f85837eaaa41f7fd03a3f833/src/index.es.ts#L63-L86
|
|
50
|
-
var search = new _InstantSearch.default(props);
|
|
51
|
-
search._schedule = function _schedule(cb) {
|
|
52
|
-
search._schedule.queue.push(cb);
|
|
53
|
-
clearTimeout(search._schedule.timer);
|
|
54
|
-
search._schedule.timer = setTimeout(function () {
|
|
55
|
-
search._schedule.queue.forEach(function (callback) {
|
|
56
|
-
callback();
|
|
57
|
-
});
|
|
58
|
-
search._schedule.queue = [];
|
|
59
|
-
}, 0);
|
|
60
|
-
};
|
|
61
|
-
search._schedule.queue = [];
|
|
62
|
-
if (shouldRenderAtOnce) {
|
|
63
|
-
// InstantSearch.js has a private Initial Results API that lets us inject
|
|
64
|
-
// results on the search instance.
|
|
65
|
-
// On the server, we default the initial results to an empty object so that
|
|
66
|
-
// InstantSearch.js doesn't schedule a search that isn't used, leading to
|
|
67
|
-
// an additional network request. (This is equivalent to monkey-patching
|
|
68
|
-
// `scheduleSearch` to a noop.)
|
|
69
|
-
search._initialResults = initialResults || {};
|
|
70
|
-
// We don't rely on the `defer` to reset the schedule search, but will call
|
|
71
|
-
// `search._resetScheduleSearch()` manually in the effect after children
|
|
72
|
-
// mount in `InstantSearch`.
|
|
73
|
-
search._manuallyResetScheduleSearch = true;
|
|
74
|
-
}
|
|
75
|
-
addAlgoliaAgents(props.searchClient, [].concat(defaultUserAgents, [serverContext && serverUserAgent, nextUserAgent(getNextVersion())]));
|
|
76
|
-
|
|
77
|
-
// On the server, we start the search early to compute the search parameters.
|
|
78
|
-
// On SSR, we start the search early to directly catch up with the lifecycle
|
|
79
|
-
// and render.
|
|
80
|
-
if (shouldRenderAtOnce) {
|
|
81
|
-
search.start();
|
|
82
|
-
}
|
|
83
|
-
if (serverContext) {
|
|
84
|
-
// We notify `getServerState()` of the InstantSearch internals to retrieve
|
|
85
|
-
// the server state and pass it to the render on SSR.
|
|
86
|
-
serverContext.notifyServer({
|
|
87
|
-
search: search
|
|
88
|
-
});
|
|
25
|
+
var forceUpdate = useForceUpdate.useForceUpdate();
|
|
26
|
+
var serverContext = useInstantSearchServerContext.useInstantSearchServerContext();
|
|
27
|
+
var serverState = useInstantSearchSSRContext.useInstantSearchSSRContext();
|
|
28
|
+
var waitForResultsRef = useRSCContext.useRSCContext().waitForResultsRef;
|
|
29
|
+
var initialResults = serverState === null || serverState === void 0 ? void 0 : serverState.initialResults;
|
|
30
|
+
var prevPropsRef = React.useRef(props);
|
|
31
|
+
var shouldRenderAtOnce = serverContext || initialResults || waitForResultsRef;
|
|
32
|
+
var searchRef = React.useRef(null);
|
|
33
|
+
// As we need to render on mount with SSR, using the local ref above in `StrictMode` will
|
|
34
|
+
// create and start two instances of InstantSearch. To avoid this, we instead discard it and use
|
|
35
|
+
// an upward ref from `InstantSearchSSRContext` as it has already been mounted a second time at this point.
|
|
36
|
+
if (serverState === null || serverState === void 0 ? void 0 : serverState.ssrSearchRef) {
|
|
37
|
+
searchRef = serverState.ssrSearchRef;
|
|
89
38
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
39
|
+
if (searchRef.current === null) {
|
|
40
|
+
// We don't use the `instantsearch()` function because it comes with other
|
|
41
|
+
// top-level APIs that we don't need.
|
|
42
|
+
// See https://github.com/algolia/instantsearch/blob/5b529f43d8acc680f85837eaaa41f7fd03a3f833/src/index.es.ts#L63-L86
|
|
43
|
+
var search = new InstantSearch(props);
|
|
44
|
+
search._schedule = function _schedule(cb) {
|
|
45
|
+
search._schedule.queue.push(cb);
|
|
46
|
+
clearTimeout(search._schedule.timer);
|
|
47
|
+
search._schedule.timer = setTimeout(function() {
|
|
48
|
+
search._schedule.queue.forEach(function(callback) {
|
|
49
|
+
callback();
|
|
50
|
+
});
|
|
51
|
+
search._schedule.queue = [];
|
|
52
|
+
}, 0);
|
|
53
|
+
};
|
|
54
|
+
search._schedule.queue = [];
|
|
55
|
+
if (shouldRenderAtOnce) {
|
|
56
|
+
// InstantSearch.js has a private Initial Results API that lets us inject
|
|
57
|
+
// results on the search instance.
|
|
58
|
+
// On the server, we default the initial results to an empty object so that
|
|
59
|
+
// InstantSearch.js doesn't schedule a search that isn't used, leading to
|
|
60
|
+
// an additional network request. (This is equivalent to monkey-patching
|
|
61
|
+
// `scheduleSearch` to a noop.)
|
|
62
|
+
search._initialResults = initialResults || {};
|
|
63
|
+
// We don't rely on the `defer` to reset the schedule search, but will call
|
|
64
|
+
// `search._resetScheduleSearch()` manually in the effect after children
|
|
65
|
+
// mount in `InstantSearch`.
|
|
66
|
+
search._manuallyResetScheduleSearch = true;
|
|
67
|
+
}
|
|
68
|
+
addAlgoliaAgents(props.searchClient, _to_consumable_array._(defaultUserAgents).concat([
|
|
69
|
+
serverContext && serverUserAgent,
|
|
70
|
+
nextUserAgent(getNextVersion())
|
|
71
|
+
]));
|
|
72
|
+
// On the server, we start the search early to compute the search parameters.
|
|
73
|
+
// On SSR, we start the search early to directly catch up with the lifecycle
|
|
74
|
+
// and render.
|
|
75
|
+
if (shouldRenderAtOnce) {
|
|
76
|
+
search.start();
|
|
77
|
+
}
|
|
78
|
+
if (serverContext) {
|
|
79
|
+
// We notify `getServerState()` of the InstantSearch internals to retrieve
|
|
80
|
+
// the server state and pass it to the render on SSR.
|
|
81
|
+
serverContext.notifyServer({
|
|
82
|
+
search: search
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
warnNextRouter(props.routing);
|
|
86
|
+
searchRef.current = search;
|
|
128
87
|
}
|
|
129
|
-
|
|
88
|
+
{
|
|
89
|
+
var search1 = searchRef.current;
|
|
90
|
+
var prevProps = prevPropsRef.current;
|
|
91
|
+
if (prevProps.indexName !== props.indexName) {
|
|
92
|
+
search1.helper.setIndex(props.indexName || '').search();
|
|
93
|
+
prevPropsRef.current = props;
|
|
94
|
+
}
|
|
95
|
+
if (prevProps.searchClient !== props.searchClient) {
|
|
96
|
+
addAlgoliaAgents(props.searchClient, _to_consumable_array._(defaultUserAgents).concat([
|
|
97
|
+
serverContext && serverUserAgent
|
|
98
|
+
]));
|
|
99
|
+
search1.mainHelper.setClient(props.searchClient).search();
|
|
100
|
+
prevPropsRef.current = props;
|
|
101
|
+
}
|
|
102
|
+
if (prevProps.onStateChange !== props.onStateChange) {
|
|
103
|
+
search1.onStateChange = props.onStateChange;
|
|
104
|
+
prevPropsRef.current = props;
|
|
105
|
+
}
|
|
106
|
+
if (prevProps.searchFunction !== props.searchFunction) {
|
|
107
|
+
// Updating the `searchFunction` to `undefined` is not supported by
|
|
108
|
+
// InstantSearch.js, so it will throw an error.
|
|
109
|
+
// This is a fair behavior until we add an update API in InstantSearch.js.
|
|
110
|
+
search1._searchFunction = props.searchFunction;
|
|
111
|
+
prevPropsRef.current = props;
|
|
112
|
+
}
|
|
113
|
+
if (prevProps.stalledSearchDelay !== props.stalledSearchDelay) {
|
|
114
|
+
var _props_stalledSearchDelay;
|
|
115
|
+
// The default `stalledSearchDelay` in InstantSearch.js is 200ms.
|
|
116
|
+
// We need to reset it when it's undefined to get back to the original value.
|
|
117
|
+
search1._stalledSearchDelay = (_props_stalledSearchDelay = props.stalledSearchDelay) !== null && _props_stalledSearchDelay !== void 0 ? _props_stalledSearchDelay : 200;
|
|
118
|
+
prevPropsRef.current = props;
|
|
119
|
+
}
|
|
120
|
+
if (!dequal.dequal(prevProps.future, props.future)) {
|
|
121
|
+
search1.future = _object_spread._({}, InstantSearch.INSTANTSEARCH_FUTURE_DEFAULTS, props.future);
|
|
122
|
+
prevPropsRef.current = props;
|
|
123
|
+
}
|
|
130
124
|
// Updating the `routing` prop is not supported because InstantSearch.js
|
|
131
125
|
// doesn't let us change it. This might not be a problem though, because `routing`
|
|
132
126
|
// shouldn't need to be dynamic.
|
|
@@ -134,87 +128,70 @@ function useInstantSearchApi(props) {
|
|
|
134
128
|
// it privately on the InstantSearch instance. Another way would be to
|
|
135
129
|
// manually inject the routing middleware in this library, and not rely
|
|
136
130
|
// on the provided `routing` prop.
|
|
137
|
-
}
|
|
138
|
-
var cleanupTimerRef = (0, _react.useRef)(null);
|
|
139
|
-
var store = (0, _shim.useSyncExternalStore)((0, _react.useCallback)(function () {
|
|
140
|
-
var search = searchRef.current;
|
|
141
|
-
|
|
142
|
-
// Scenario 1: the component mounts.
|
|
143
|
-
if (cleanupTimerRef.current === null) {
|
|
144
|
-
// On SSR, the instance is already started so we don't start it again.
|
|
145
|
-
if (!search.started) {
|
|
146
|
-
search.start();
|
|
147
|
-
forceUpdate();
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
// Scenario 2: the component updates.
|
|
151
|
-
else {
|
|
152
|
-
// We cancel the previous cleanup function because we don't want to
|
|
153
|
-
// dispose the search during an update.
|
|
154
|
-
clearTimeout(cleanupTimerRef.current);
|
|
155
|
-
search._preventWidgetCleanup = false;
|
|
156
131
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
132
|
+
var cleanupTimerRef = React.useRef(null);
|
|
133
|
+
var store = shim.useSyncExternalStore(React.useCallback(function() {
|
|
134
|
+
var search = searchRef.current;
|
|
135
|
+
// Scenario 1: the component mounts.
|
|
136
|
+
if (cleanupTimerRef.current === null) {
|
|
137
|
+
// On SSR, the instance is already started so we don't start it again.
|
|
138
|
+
if (!search.started) {
|
|
139
|
+
search.start();
|
|
140
|
+
forceUpdate();
|
|
141
|
+
}
|
|
142
|
+
} else {
|
|
143
|
+
// We cancel the previous cleanup function because we don't want to
|
|
144
|
+
// dispose the search during an update.
|
|
145
|
+
clearTimeout(cleanupTimerRef.current);
|
|
146
|
+
search._preventWidgetCleanup = false;
|
|
147
|
+
}
|
|
148
|
+
return function() {
|
|
149
|
+
if (serverState === null || serverState === void 0 ? void 0 : serverState.ssrSearchRef) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
function cleanup() {
|
|
153
|
+
search.dispose();
|
|
154
|
+
}
|
|
155
|
+
clearTimeout(search._schedule.timer);
|
|
156
|
+
// We clean up only when the component that uses this subscription unmounts,
|
|
157
|
+
// but not when it updates, because it would dispose the instance, which
|
|
158
|
+
// would remove all the widgets and break routing.
|
|
159
|
+
// Executing the cleanup function in a `setTimeout()` lets us cancel it
|
|
160
|
+
// in the next effect.
|
|
161
|
+
// (There might be better ways to do this.)
|
|
162
|
+
cleanupTimerRef.current = setTimeout(cleanup);
|
|
163
|
+
// We need to prevent the `useWidget` cleanup function so that widgets
|
|
164
|
+
// are not removed before the instance is disposed, triggering
|
|
165
|
+
// an unwanted search request.
|
|
166
|
+
search._preventWidgetCleanup = true;
|
|
167
|
+
};
|
|
168
|
+
}, [
|
|
169
|
+
forceUpdate,
|
|
170
|
+
serverState
|
|
171
|
+
]), function() {
|
|
172
|
+
return searchRef.current;
|
|
173
|
+
}, function() {
|
|
174
|
+
return searchRef.current;
|
|
175
|
+
});
|
|
176
|
+
return store;
|
|
183
177
|
}
|
|
184
178
|
function addAlgoliaAgents(searchClient, userAgents) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}
|
|
188
|
-
userAgents.filter(Boolean).forEach(function (userAgent) {
|
|
189
|
-
searchClient.addAlgoliaAgent(userAgent);
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
function warnNextRouter(routing) {
|
|
193
|
-
if (process.env.NODE_ENV === 'development') {
|
|
194
|
-
var _routing$router;
|
|
195
|
-
if (!routing || typeof window === 'undefined' || !('__NEXT_DATA__' in window)) {
|
|
196
|
-
return;
|
|
179
|
+
if (typeof searchClient.addAlgoliaAgent !== 'function') {
|
|
180
|
+
return;
|
|
197
181
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
process.env.NODE_ENV === 'development' ? (0, _warn.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;
|
|
202
|
-
}
|
|
182
|
+
userAgents.filter(Boolean).forEach(function(userAgent) {
|
|
183
|
+
searchClient.addAlgoliaAgent(userAgent);
|
|
184
|
+
});
|
|
203
185
|
}
|
|
204
|
-
function
|
|
205
|
-
var _next;
|
|
206
|
-
if (!(process.env.NODE_ENV === 'development') || typeof window === 'undefined' || isRscContextDefined) {
|
|
207
|
-
return;
|
|
208
|
-
}
|
|
209
|
-
process.env.NODE_ENV === 'development' ? (0, _warn.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;
|
|
186
|
+
function warnNextRouter(routing) {
|
|
210
187
|
}
|
|
211
|
-
|
|
212
188
|
/**
|
|
213
189
|
* Gets the version of Next.js if it is available in the `window` object,
|
|
214
190
|
* otherwise it returns the NEXT_RUNTIME environment variable (in SSR),
|
|
215
191
|
* which is either `nodejs` or `edge`.
|
|
216
|
-
*/
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
192
|
+
*/ function getNextVersion() {
|
|
193
|
+
var _window_next, _process_env;
|
|
194
|
+
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);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
exports.useInstantSearchApi = useInstantSearchApi;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var InstantSearchContext = require('./InstantSearchContext.js');
|
|
5
|
+
var invariant = require('./invariant.js');
|
|
2
6
|
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useInstantSearchContext = useInstantSearchContext;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _InstantSearchContext = require("./InstantSearchContext");
|
|
9
|
-
var _invariant = require("./invariant");
|
|
10
7
|
function useInstantSearchContext() {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
8
|
+
var search = React.useContext(InstantSearchContext.InstantSearchContext);
|
|
9
|
+
invariant.invariant(search !== null);
|
|
10
|
+
return search;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
exports.useInstantSearchContext = useInstantSearchContext;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var InstantSearchSSRContext = require('./InstantSearchSSRContext.js');
|
|
2
5
|
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useInstantSearchSSRContext = useInstantSearchSSRContext;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _InstantSearchSSRContext = require("./InstantSearchSSRContext");
|
|
9
6
|
function useInstantSearchSSRContext() {
|
|
10
|
-
|
|
11
|
-
}
|
|
7
|
+
return React.useContext(InstantSearchSSRContext.InstantSearchSSRContext);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
exports.useInstantSearchSSRContext = useInstantSearchSSRContext;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var InstantSearchServerContext = require('../components/InstantSearchServerContext.js');
|
|
2
5
|
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useInstantSearchServerContext = useInstantSearchServerContext;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _InstantSearchServerContext = require("../components/InstantSearchServerContext");
|
|
9
6
|
function useInstantSearchServerContext() {
|
|
10
|
-
|
|
11
|
-
}
|
|
7
|
+
return React.useContext(InstantSearchServerContext.InstantSearchServerContext);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
exports.useInstantSearchServerContext = useInstantSearchServerContext;
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
2
4
|
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useIsomorphicLayoutEffect = void 0;
|
|
7
|
-
var _react = require("react");
|
|
8
5
|
/**
|
|
9
6
|
* `useLayoutEffect` that doesn't show a warning when server-side rendering.
|
|
10
7
|
*
|
|
11
8
|
* It uses `useEffect` on the server (no-op), and `useLayoutEffect` on the browser.
|
|
12
|
-
*/
|
|
13
|
-
|
|
9
|
+
*/ var useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
|
|
10
|
+
|
|
11
|
+
exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var InstantSearchRSCContext = require('./InstantSearchRSCContext.js');
|
|
2
5
|
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useRSCContext = useRSCContext;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _InstantSearchRSCContext = require("./InstantSearchRSCContext");
|
|
9
6
|
function useRSCContext() {
|
|
10
|
-
|
|
11
|
-
}
|
|
7
|
+
return React.useContext(InstantSearchRSCContext.InstantSearchRSCContext);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
exports.useRSCContext = useRSCContext;
|
|
@@ -1,65 +1,57 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var _getIndexSearchResults = require("./getIndexSearchResults");
|
|
10
|
-
var _useIndexContext = require("./useIndexContext");
|
|
11
|
-
var _useInstantSearchContext = require("./useInstantSearchContext");
|
|
12
|
-
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
13
|
-
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."); }
|
|
14
|
-
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; } }
|
|
15
|
-
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; }
|
|
16
|
-
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; } }
|
|
17
|
-
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
18
|
-
function useSearchResults() {
|
|
19
|
-
var search = (0, _useInstantSearchContext.useInstantSearchContext)();
|
|
20
|
-
var searchIndex = (0, _useIndexContext.useIndexContext)();
|
|
21
|
-
var _useState = (0, _react.useState)(function () {
|
|
22
|
-
var indexSearchResults = (0, _getIndexSearchResults.getIndexSearchResults)(searchIndex);
|
|
23
|
-
// We do this not to leak `recommendResults` in the API.
|
|
24
|
-
return {
|
|
25
|
-
results: indexSearchResults.results,
|
|
26
|
-
scopedResults: indexSearchResults.scopedResults
|
|
27
|
-
};
|
|
28
|
-
}),
|
|
29
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
30
|
-
searchResults = _useState2[0],
|
|
31
|
-
setSearchResults = _useState2[1];
|
|
32
|
-
(0, _react.useEffect)(function () {
|
|
33
|
-
function handleRender() {
|
|
34
|
-
var results = searchIndex.getResults();
|
|
3
|
+
var _sliced_to_array = require('@swc/helpers/_/_sliced_to_array');
|
|
4
|
+
var utils = require('instantsearch.js/cjs/lib/utils');
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var getIndexSearchResults = require('./getIndexSearchResults.js');
|
|
7
|
+
var useIndexContext = require('./useIndexContext.js');
|
|
8
|
+
var useInstantSearchContext = require('./useInstantSearchContext.js');
|
|
35
9
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
10
|
+
function useSearchResults() {
|
|
11
|
+
var search = useInstantSearchContext.useInstantSearchContext();
|
|
12
|
+
var searchIndex = useIndexContext.useIndexContext();
|
|
13
|
+
var _useState = _sliced_to_array._(React.useState(function() {
|
|
14
|
+
var indexSearchResults = getIndexSearchResults.getIndexSearchResults(searchIndex);
|
|
15
|
+
// We do this not to leak `recommendResults` in the API.
|
|
16
|
+
return {
|
|
17
|
+
results: indexSearchResults.results,
|
|
18
|
+
scopedResults: indexSearchResults.scopedResults
|
|
19
|
+
};
|
|
20
|
+
}), 2), searchResults = _useState[0], setSearchResults = _useState[1];
|
|
21
|
+
React.useEffect(function() {
|
|
22
|
+
function handleRender() {
|
|
23
|
+
var results = searchIndex.getResults();
|
|
24
|
+
// Results can be `null` when the first search is stalled.
|
|
25
|
+
// In this case, we skip the update.
|
|
26
|
+
// See: https://github.com/algolia/instantsearch/blob/20996c7a159988c58e00ff24d2d2dc98af8b980f/src/widgets/index/index.ts#L652-L657
|
|
27
|
+
if (results !== null) {
|
|
28
|
+
setSearchResults({
|
|
29
|
+
results: results,
|
|
30
|
+
scopedResults: searchIndex.getScopedResults()
|
|
31
|
+
});
|
|
32
|
+
} else if (search.mainIndex.getIndexName().length === 0) {
|
|
33
|
+
// If the main index has no name, we get the scoped results from
|
|
34
|
+
// the first child index instead.
|
|
35
|
+
var childIndex = search.mainIndex.getWidgets().find(utils.isIndexWidget);
|
|
36
|
+
childIndex && setSearchResults({
|
|
37
|
+
results: getIndexSearchResults.getIndexSearchResults(searchIndex).results,
|
|
38
|
+
scopedResults: childIndex.getScopedResults()
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
search.addListener('render', handleRender);
|
|
43
|
+
// Force setting results to mitigate potential race conditions where
|
|
44
|
+
// render listener is added after search results have been returned.
|
|
45
|
+
// This edge case is currently not covered by the tests.
|
|
46
|
+
handleRender();
|
|
47
|
+
return function() {
|
|
48
|
+
search.removeListener('render', handleRender);
|
|
49
|
+
};
|
|
50
|
+
}, [
|
|
51
|
+
search,
|
|
52
|
+
searchIndex
|
|
53
|
+
]);
|
|
54
|
+
return searchResults;
|
|
55
|
+
}
|
|
55
56
|
|
|
56
|
-
|
|
57
|
-
// render listener is added after search results have been returned.
|
|
58
|
-
// This edge case is currently not covered by the tests.
|
|
59
|
-
handleRender();
|
|
60
|
-
return function () {
|
|
61
|
-
search.removeListener('render', handleRender);
|
|
62
|
-
};
|
|
63
|
-
}, [search, searchIndex]);
|
|
64
|
-
return searchResults;
|
|
65
|
-
}
|
|
57
|
+
exports.useSearchResults = useSearchResults;
|