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,63 +1,56 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _useIndexContext = require("./useIndexContext");
|
|
9
|
-
var _useInstantSearchContext = require("./useInstantSearchContext");
|
|
10
|
-
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
11
|
-
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."); }
|
|
12
|
-
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; } }
|
|
13
|
-
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; }
|
|
14
|
-
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; } }
|
|
15
|
-
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
16
|
-
function useSearchState() {
|
|
17
|
-
var search = (0, _useInstantSearchContext.useInstantSearchContext)();
|
|
18
|
-
var searchIndex = (0, _useIndexContext.useIndexContext)();
|
|
19
|
-
var indexId = searchIndex.getIndexId();
|
|
20
|
-
var _useState = (0, _react.useState)(function () {
|
|
21
|
-
return search.getUiState();
|
|
22
|
-
}),
|
|
23
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
24
|
-
uiState = _useState2[0],
|
|
25
|
-
setLocalUiState = _useState2[1];
|
|
26
|
-
var indexUiState = uiState[indexId];
|
|
27
|
-
var _useState3 = (0, _react.useState)(function () {
|
|
28
|
-
return search.renderState;
|
|
29
|
-
}),
|
|
30
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
31
|
-
renderState = _useState4[0],
|
|
32
|
-
setRenderState = _useState4[1];
|
|
33
|
-
var indexRenderState = renderState[indexId] || {};
|
|
34
|
-
var setUiState = (0, _react.useCallback)(function (nextUiState) {
|
|
35
|
-
search.setUiState(nextUiState);
|
|
36
|
-
}, [search]);
|
|
37
|
-
var setIndexUiState = (0, _react.useCallback)(function (nextIndexUiState) {
|
|
38
|
-
searchIndex.setIndexUiState(nextIndexUiState);
|
|
39
|
-
}, [searchIndex]);
|
|
40
|
-
(0, _react.useEffect)(function () {
|
|
41
|
-
function handleRender() {
|
|
42
|
-
setLocalUiState(search.getUiState());
|
|
43
|
-
setRenderState(search.renderState);
|
|
44
|
-
}
|
|
45
|
-
search.addListener('render', handleRender);
|
|
3
|
+
var _sliced_to_array = require('@swc/helpers/_/_sliced_to_array');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var useIndexContext = require('./useIndexContext.js');
|
|
6
|
+
var useInstantSearchContext = require('./useInstantSearchContext.js');
|
|
46
7
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
8
|
+
function useSearchState() {
|
|
9
|
+
var search = useInstantSearchContext.useInstantSearchContext();
|
|
10
|
+
var searchIndex = useIndexContext.useIndexContext();
|
|
11
|
+
var indexId = searchIndex.getIndexId();
|
|
12
|
+
var _useState = _sliced_to_array._(React.useState(function() {
|
|
13
|
+
return search.getUiState();
|
|
14
|
+
}), 2), uiState = _useState[0], setLocalUiState = _useState[1];
|
|
15
|
+
var indexUiState = uiState[indexId];
|
|
16
|
+
var _useState1 = _sliced_to_array._(React.useState(function() {
|
|
17
|
+
return search.renderState;
|
|
18
|
+
}), 2), renderState = _useState1[0], setRenderState = _useState1[1];
|
|
19
|
+
var indexRenderState = renderState[indexId] || {};
|
|
20
|
+
var setUiState = React.useCallback(function(nextUiState) {
|
|
21
|
+
search.setUiState(nextUiState);
|
|
22
|
+
}, [
|
|
23
|
+
search
|
|
24
|
+
]);
|
|
25
|
+
var setIndexUiState = React.useCallback(function(nextIndexUiState) {
|
|
26
|
+
searchIndex.setIndexUiState(nextIndexUiState);
|
|
27
|
+
}, [
|
|
28
|
+
searchIndex
|
|
29
|
+
]);
|
|
30
|
+
React.useEffect(function() {
|
|
31
|
+
function handleRender() {
|
|
32
|
+
setLocalUiState(search.getUiState());
|
|
33
|
+
setRenderState(search.renderState);
|
|
34
|
+
}
|
|
35
|
+
search.addListener('render', handleRender);
|
|
36
|
+
// Force setting state to mitigate potential race conditions where
|
|
37
|
+
// render listener is added after search results have been returned.
|
|
38
|
+
// This edge case is currently not covered by the tests.
|
|
39
|
+
handleRender();
|
|
40
|
+
return function() {
|
|
41
|
+
search.removeListener('render', handleRender);
|
|
42
|
+
};
|
|
43
|
+
}, [
|
|
44
|
+
search
|
|
45
|
+
]);
|
|
46
|
+
return {
|
|
47
|
+
uiState: uiState,
|
|
48
|
+
setUiState: setUiState,
|
|
49
|
+
indexUiState: indexUiState,
|
|
50
|
+
setIndexUiState: setIndexUiState,
|
|
51
|
+
renderState: renderState,
|
|
52
|
+
indexRenderState: indexRenderState
|
|
53
53
|
};
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
setUiState: setUiState,
|
|
58
|
-
indexUiState: indexUiState,
|
|
59
|
-
setIndexUiState: setIndexUiState,
|
|
60
|
-
renderState: renderState,
|
|
61
|
-
indexRenderState: indexRenderState
|
|
62
|
-
};
|
|
63
|
-
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
exports.useSearchState = useSearchState;
|
|
@@ -1,26 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _sliced_to_array = require('@swc/helpers/_/_sliced_to_array');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var dequal = require('./dequal.js');
|
|
2
6
|
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useStableValue = useStableValue;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _dequal = require("./dequal");
|
|
9
|
-
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
10
|
-
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."); }
|
|
11
|
-
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; } }
|
|
12
|
-
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; }
|
|
13
|
-
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; } }
|
|
14
|
-
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
15
7
|
function useStableValue(value) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}),
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
8
|
+
var _useState = _sliced_to_array._(React.useState(function() {
|
|
9
|
+
return value;
|
|
10
|
+
}), 2), stableValue = _useState[0], setStableValue = _useState[1];
|
|
11
|
+
if (!dequal.dequal(stableValue, value)) {
|
|
12
|
+
setStableValue(value);
|
|
13
|
+
}
|
|
14
|
+
return stableValue;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exports.useStableValue = useStableValue;
|
|
@@ -1,100 +1,104 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var _use = require("./use");
|
|
10
|
-
var _useInstantSearchContext = require("./useInstantSearchContext");
|
|
11
|
-
var _useIsomorphicLayoutEffect = require("./useIsomorphicLayoutEffect");
|
|
12
|
-
var _useRSCContext2 = require("./useRSCContext");
|
|
13
|
-
var _warn = require("./warn");
|
|
14
|
-
function useWidget(_ref) {
|
|
15
|
-
var _waitForResultsRef$cu, _waitForResultsRef$cu2;
|
|
16
|
-
var widget = _ref.widget,
|
|
17
|
-
parentIndex = _ref.parentIndex,
|
|
18
|
-
props = _ref.props,
|
|
19
|
-
shouldSsr = _ref.shouldSsr,
|
|
20
|
-
skipSuspense = _ref.skipSuspense;
|
|
21
|
-
var _useRSCContext = (0, _useRSCContext2.useRSCContext)(),
|
|
22
|
-
waitForResultsRef = _useRSCContext.waitForResultsRef,
|
|
23
|
-
countRef = _useRSCContext.countRef,
|
|
24
|
-
ignoreMultipleHooksWarning = _useRSCContext.ignoreMultipleHooksWarning;
|
|
25
|
-
var prevPropsRef = (0, _react.useRef)(props);
|
|
26
|
-
(0, _react.useEffect)(function () {
|
|
27
|
-
prevPropsRef.current = props;
|
|
28
|
-
}, [props]);
|
|
29
|
-
var prevWidgetRef = (0, _react.useRef)(widget);
|
|
30
|
-
(0, _react.useEffect)(function () {
|
|
31
|
-
prevWidgetRef.current = widget;
|
|
32
|
-
}, [widget]);
|
|
33
|
-
var cleanupTimerRef = (0, _react.useRef)(null);
|
|
34
|
-
var shouldAddWidgetEarly = shouldSsr && !parentIndex.getWidgets().includes(widget);
|
|
35
|
-
var search = (0, _useInstantSearchContext.useInstantSearchContext)();
|
|
36
|
-
|
|
37
|
-
// This effect is responsible for adding, removing, and updating the widget.
|
|
38
|
-
// We need to support scenarios where the widget is remounted quickly, like in
|
|
39
|
-
// Strict Mode, so that we don't lose its state, and therefore that we don't
|
|
40
|
-
// break routing.
|
|
41
|
-
(0, _useIsomorphicLayoutEffect.useIsomorphicLayoutEffect)(function () {
|
|
42
|
-
var previousWidget = prevWidgetRef.current;
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var dequal = require('./dequal.js');
|
|
5
|
+
var use = require('./use.js');
|
|
6
|
+
var useInstantSearchContext = require('./useInstantSearchContext.js');
|
|
7
|
+
var useIsomorphicLayoutEffect = require('./useIsomorphicLayoutEffect.js');
|
|
8
|
+
var useRSCContext = require('./useRSCContext.js');
|
|
43
9
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
10
|
+
function useWidget(param) {
|
|
11
|
+
var widget = param.widget, parentIndex = param.parentIndex, props = param.props, shouldSsr = param.shouldSsr, skipSuspense = param.skipSuspense;
|
|
12
|
+
var _waitForResultsRef_current, _waitForResultsRef_current1;
|
|
13
|
+
var _useRSCContext = useRSCContext.useRSCContext(), waitForResultsRef = _useRSCContext.waitForResultsRef, countRef = _useRSCContext.countRef; _useRSCContext.ignoreMultipleHooksWarning;
|
|
14
|
+
var prevPropsRef = React.useRef(props);
|
|
15
|
+
React.useEffect(function() {
|
|
16
|
+
prevPropsRef.current = props;
|
|
17
|
+
}, [
|
|
18
|
+
props
|
|
19
|
+
]);
|
|
20
|
+
var prevWidgetRef = React.useRef(widget);
|
|
21
|
+
React.useEffect(function() {
|
|
22
|
+
prevWidgetRef.current = widget;
|
|
23
|
+
}, [
|
|
24
|
+
widget
|
|
25
|
+
]);
|
|
26
|
+
var cleanupTimerRef = React.useRef(null);
|
|
27
|
+
var shouldAddWidgetEarly = shouldSsr && !parentIndex.getWidgets().includes(widget);
|
|
28
|
+
var search = useInstantSearchContext.useInstantSearchContext();
|
|
29
|
+
// This effect is responsible for adding, removing, and updating the widget.
|
|
30
|
+
// We need to support scenarios where the widget is remounted quickly, like in
|
|
31
|
+
// Strict Mode, so that we don't lose its state, and therefore that we don't
|
|
32
|
+
// break routing.
|
|
33
|
+
useIsomorphicLayoutEffect.useIsomorphicLayoutEffect(function() {
|
|
34
|
+
var previousWidget = prevWidgetRef.current;
|
|
35
|
+
// Scenario 1: the widget is added for the first time.
|
|
36
|
+
if (!cleanupTimerRef.current) {
|
|
37
|
+
if (!shouldSsr) {
|
|
38
|
+
parentIndex.addWidgets([
|
|
39
|
+
widget
|
|
40
|
+
]);
|
|
41
|
+
}
|
|
42
|
+
} else {
|
|
43
|
+
// We cancel the original effect cleanup because it may not be necessary if
|
|
44
|
+
// props haven't changed. (We manually call it if it is below.)
|
|
45
|
+
clearTimeout(cleanupTimerRef.current);
|
|
46
|
+
// Warning: if an unstable function prop is provided, `dequal` is not able
|
|
47
|
+
// to keep its reference and therefore will consider that props did change.
|
|
48
|
+
// This could unsollicitely remove/add the widget, therefore forget its state,
|
|
49
|
+
// and could be a source of confusion.
|
|
50
|
+
// If users face this issue, we should advise them to provide stable function
|
|
51
|
+
// references.
|
|
52
|
+
var arePropsEqual = dequal.dequal(props, prevPropsRef.current);
|
|
53
|
+
// If props did change, then we execute the cleanup function instantly
|
|
54
|
+
// and then add the widget back. This lets us add the widget without
|
|
55
|
+
// waiting for the scheduled cleanup function to finish (that we canceled
|
|
56
|
+
// above).
|
|
57
|
+
if (!arePropsEqual) {
|
|
58
|
+
parentIndex.removeWidgets([
|
|
59
|
+
previousWidget
|
|
60
|
+
]);
|
|
61
|
+
parentIndex.addWidgets([
|
|
62
|
+
widget
|
|
63
|
+
]);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return function() {
|
|
67
|
+
// We don't remove the widget right away, but rather schedule it so that
|
|
68
|
+
// we're able to cancel it in the next effect.
|
|
69
|
+
cleanupTimerRef.current = setTimeout(function() {
|
|
70
|
+
search._schedule(function() {
|
|
71
|
+
if (search._preventWidgetCleanup) return;
|
|
72
|
+
parentIndex.removeWidgets([
|
|
73
|
+
previousWidget
|
|
74
|
+
]);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
}, [
|
|
79
|
+
parentIndex,
|
|
80
|
+
widget,
|
|
81
|
+
shouldSsr,
|
|
82
|
+
search,
|
|
83
|
+
props
|
|
84
|
+
]);
|
|
85
|
+
if (shouldAddWidgetEarly || (waitForResultsRef === null || waitForResultsRef === void 0 ? void 0 : (_waitForResultsRef_current = waitForResultsRef.current) === null || _waitForResultsRef_current === void 0 ? void 0 : _waitForResultsRef_current.status) === 'pending') {
|
|
86
|
+
parentIndex.addWidgets([
|
|
87
|
+
widget
|
|
88
|
+
]);
|
|
49
89
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
// This could unsollicitely remove/add the widget, therefore forget its state,
|
|
59
|
-
// and could be a source of confusion.
|
|
60
|
-
// If users face this issue, we should advise them to provide stable function
|
|
61
|
-
// references.
|
|
62
|
-
var arePropsEqual = (0, _dequal.dequal)(props, prevPropsRef.current);
|
|
63
|
-
|
|
64
|
-
// If props did change, then we execute the cleanup function instantly
|
|
65
|
-
// and then add the widget back. This lets us add the widget without
|
|
66
|
-
// waiting for the scheduled cleanup function to finish (that we canceled
|
|
67
|
-
// above).
|
|
68
|
-
if (!arePropsEqual) {
|
|
69
|
-
parentIndex.removeWidgets([previousWidget]);
|
|
70
|
-
parentIndex.addWidgets([widget]);
|
|
71
|
-
}
|
|
90
|
+
if ((waitForResultsRef === null || waitForResultsRef === void 0 ? void 0 : waitForResultsRef.current) && !skipSuspense) {
|
|
91
|
+
var _search_helper;
|
|
92
|
+
use.use(waitForResultsRef.current);
|
|
93
|
+
// If we made a second request because of DynamicWidgets, we need to wait for the second result,
|
|
94
|
+
// except for DynamicWidgets itself which needs to render its children after the first result.
|
|
95
|
+
if (widget.$$type !== 'ais.dynamicWidgets' && ((_search_helper = search.helper) === null || _search_helper === void 0 ? void 0 : _search_helper.lastResults)) {
|
|
96
|
+
use.use(waitForResultsRef.current);
|
|
97
|
+
}
|
|
72
98
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
// we're able to cancel it in the next effect.
|
|
76
|
-
cleanupTimerRef.current = setTimeout(function () {
|
|
77
|
-
search._schedule(function () {
|
|
78
|
-
if (search._preventWidgetCleanup) return;
|
|
79
|
-
parentIndex.removeWidgets([previousWidget]);
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
}, [parentIndex, widget, shouldSsr, search, props]);
|
|
84
|
-
if (shouldAddWidgetEarly || (waitForResultsRef === null || waitForResultsRef === void 0 ? void 0 : (_waitForResultsRef$cu = waitForResultsRef.current) === null || _waitForResultsRef$cu === void 0 ? void 0 : _waitForResultsRef$cu.status) === 'pending') {
|
|
85
|
-
parentIndex.addWidgets([widget]);
|
|
86
|
-
}
|
|
87
|
-
if (waitForResultsRef !== null && waitForResultsRef !== void 0 && waitForResultsRef.current && !skipSuspense) {
|
|
88
|
-
var _search$helper;
|
|
89
|
-
(0, _use.use)(waitForResultsRef.current);
|
|
90
|
-
// If we made a second request because of DynamicWidgets, we need to wait for the second result,
|
|
91
|
-
// except for DynamicWidgets itself which needs to render its children after the first result.
|
|
92
|
-
if (widget.$$type !== 'ais.dynamicWidgets' && (_search$helper = search.helper) !== null && _search$helper !== void 0 && _search$helper.lastResults) {
|
|
93
|
-
(0, _use.use)(waitForResultsRef.current);
|
|
99
|
+
if ((waitForResultsRef === null || waitForResultsRef === void 0 ? void 0 : (_waitForResultsRef_current1 = waitForResultsRef.current) === null || _waitForResultsRef_current1 === void 0 ? void 0 : _waitForResultsRef_current1.status) === 'fulfilled') {
|
|
100
|
+
countRef.current += 1;
|
|
94
101
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
process.env.NODE_ENV === 'development' ? (0, _warn.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;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
exports.useWidget = useWidget;
|
package/dist/cjs/lib/warn.js
CHANGED
|
@@ -1,40 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.warn = warn;
|
|
7
|
-
exports.warnCache = void 0;
|
|
8
|
-
/* eslint-disable no-console, no-empty */
|
|
9
|
-
|
|
10
|
-
var warnCache = exports.warnCache = {
|
|
11
|
-
current: {}
|
|
3
|
+
/* eslint-disable no-console, no-empty */ var warnCache = {
|
|
4
|
+
current: {}
|
|
12
5
|
};
|
|
13
|
-
|
|
14
6
|
/**
|
|
15
7
|
* Logs a warning if the condition is not met.
|
|
16
8
|
* This is used to log issues in development environment only.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
var sanitizedMessage = message.trim();
|
|
26
|
-
var hasAlreadyPrinted = warnCache.current[sanitizedMessage];
|
|
27
|
-
if (!hasAlreadyPrinted) {
|
|
28
|
-
warnCache.current[sanitizedMessage] = true;
|
|
29
|
-
var warning = "[InstantSearch] ".concat(sanitizedMessage);
|
|
30
|
-
console.warn(warning);
|
|
31
|
-
try {
|
|
32
|
-
// Welcome to debugging InstantSearch.
|
|
33
|
-
//
|
|
34
|
-
// This error was thrown as a convenience so that you can find the source
|
|
35
|
-
// of the warning that appears in the console by enabling "Pause on exceptions"
|
|
36
|
-
// in your debugger.
|
|
37
|
-
throw new Error(warning);
|
|
38
|
-
} catch (error) {}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
9
|
+
*/ function warn(condition, message) {
|
|
10
|
+
{
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
exports.warn = warn;
|
|
16
|
+
exports.warnCache = warnCache;
|
|
@@ -1,32 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.wrapPromiseWithState = wrapPromiseWithState;
|
|
7
3
|
// This is needed in order to work with RSC Suspense, perhaps they will later provide a wrapper.
|
|
8
|
-
|
|
9
4
|
function isStatefulPromise(promise) {
|
|
10
|
-
|
|
5
|
+
return 'status' in promise;
|
|
11
6
|
}
|
|
12
7
|
function wrapPromiseWithState(promise) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
var pendingPromise = promise;
|
|
17
|
-
pendingPromise.status = 'pending';
|
|
18
|
-
pendingPromise.then(function (value) {
|
|
19
|
-
if (pendingPromise.status === 'pending') {
|
|
20
|
-
var fulfilledPromise = pendingPromise;
|
|
21
|
-
fulfilledPromise.status = 'fulfilled';
|
|
22
|
-
fulfilledPromise.value = value;
|
|
23
|
-
}
|
|
24
|
-
}, function (reason) {
|
|
25
|
-
if (pendingPromise.status === 'pending') {
|
|
26
|
-
var rejectedPromise = pendingPromise;
|
|
27
|
-
rejectedPromise.status = 'rejected';
|
|
28
|
-
rejectedPromise.reason = reason;
|
|
8
|
+
if (isStatefulPromise(promise)) {
|
|
9
|
+
return promise;
|
|
29
10
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
11
|
+
var pendingPromise = promise;
|
|
12
|
+
pendingPromise.status = 'pending';
|
|
13
|
+
pendingPromise.then(function(value) {
|
|
14
|
+
if (pendingPromise.status === 'pending') {
|
|
15
|
+
var fulfilledPromise = pendingPromise;
|
|
16
|
+
fulfilledPromise.status = 'fulfilled';
|
|
17
|
+
fulfilledPromise.value = value;
|
|
18
|
+
}
|
|
19
|
+
}, function(reason) {
|
|
20
|
+
if (pendingPromise.status === 'pending') {
|
|
21
|
+
var rejectedPromise = pendingPromise;
|
|
22
|
+
rejectedPromise.status = 'rejected';
|
|
23
|
+
rejectedPromise.reason = reason;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return promise;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
exports.wrapPromiseWithState = wrapPromiseWithState;
|
package/dist/cjs/package.json
CHANGED