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,124 +1,124 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
20
|
+
return nextVersion ? "next.js (".concat(nextVersion, ")") : null;
|
|
21
21
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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 (
|
|
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
|
-
|
|
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
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
-
|
|
178
|
-
|
|
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
|
-
|
|
191
|
-
|
|
192
|
-
|
|
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
|
|
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
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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
|
|
3
|
-
import { invariant } from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
3
|
-
|
|
4
|
-
|
|
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 {
|
|
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
|
-
|
|
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
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
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 };
|