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