react-instantsearch-core 7.15.8 → 7.16.1
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/InstantSearch.js +16 -3
- package/dist/cjs/hooks/useConnector.js +11 -6
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/lib/InstantSearchRSCContext.js +7 -1
- package/dist/cjs/lib/useIndex.js +2 -1
- package/dist/cjs/lib/useInstantSearchApi.js +15 -8
- package/dist/cjs/lib/useWidget.js +17 -10
- package/dist/cjs/version.js +1 -1
- package/dist/es/components/InstantSearch.js +13 -2
- package/dist/es/hooks/useConnector.d.ts +4 -2
- package/dist/es/hooks/useConnector.js +11 -6
- package/dist/es/index.d.ts +1 -0
- package/dist/es/index.js +1 -0
- package/dist/es/lib/InstantSearchRSCContext.d.ts +6 -2
- package/dist/es/lib/InstantSearchRSCContext.js +7 -1
- package/dist/es/lib/useIndex.js +2 -1
- package/dist/es/lib/useInstantSearchApi.js +14 -7
- package/dist/es/lib/useWidget.d.ts +2 -1
- package/dist/es/lib/useWidget.js +16 -9
- package/dist/es/version.d.ts +1 -1
- package/dist/es/version.js +1 -1
- package/dist/umd/ReactInstantSearchCore.js +104 -39
- package/dist/umd/ReactInstantSearchCore.js.map +1 -1
- package/dist/umd/ReactInstantSearchCore.min.js +1 -1
- package/dist/umd/ReactInstantSearchCore.min.js.map +1 -1
- package/package.json +5 -5
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
6
7
|
exports.InstantSearch = InstantSearch;
|
|
7
|
-
var _react =
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
8
9
|
var _IndexContext = require("../lib/IndexContext");
|
|
9
10
|
var _InstantSearchContext = require("../lib/InstantSearchContext");
|
|
10
11
|
var _useInstantSearchApi = require("../lib/useInstantSearchApi");
|
|
11
12
|
var _excluded = ["children"];
|
|
12
|
-
function
|
|
13
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
14
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
13
15
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
14
16
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
15
17
|
function InstantSearch(_ref) {
|
|
@@ -23,5 +25,16 @@ function InstantSearch(_ref) {
|
|
|
23
25
|
value: search
|
|
24
26
|
}, /*#__PURE__*/_react.default.createElement(_IndexContext.IndexContext.Provider, {
|
|
25
27
|
value: search.mainIndex
|
|
26
|
-
}, children
|
|
28
|
+
}, children, /*#__PURE__*/_react.default.createElement(ResetScheduleSearch, {
|
|
29
|
+
search: search
|
|
30
|
+
})));
|
|
31
|
+
}
|
|
32
|
+
function ResetScheduleSearch(_ref2) {
|
|
33
|
+
var search = _ref2.search;
|
|
34
|
+
(0, _react.useEffect)(function () {
|
|
35
|
+
if (search._resetScheduleSearch) {
|
|
36
|
+
search._resetScheduleSearch();
|
|
37
|
+
}
|
|
38
|
+
}, [search]);
|
|
39
|
+
return null;
|
|
27
40
|
}
|
|
@@ -14,8 +14,9 @@ var _useInstantSearchServerContext = require("../lib/useInstantSearchServerConte
|
|
|
14
14
|
var _useInstantSearchSSRContext = require("../lib/useInstantSearchSSRContext");
|
|
15
15
|
var _useStableValue = require("../lib/useStableValue");
|
|
16
16
|
var _useWidget = require("../lib/useWidget");
|
|
17
|
-
var _excluded = ["
|
|
18
|
-
_excluded2 = ["widgetParams"]
|
|
17
|
+
var _excluded = ["skipSuspense"],
|
|
18
|
+
_excluded2 = ["instantSearchInstance", "widgetParams"],
|
|
19
|
+
_excluded3 = ["widgetParams"];
|
|
19
20
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
20
21
|
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."); }
|
|
21
22
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -31,7 +32,10 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
|
|
|
31
32
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
32
33
|
function useConnector(connector) {
|
|
33
34
|
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
34
|
-
var
|
|
35
|
+
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
|
36
|
+
_ref$skipSuspense = _ref.skipSuspense,
|
|
37
|
+
skipSuspense = _ref$skipSuspense === void 0 ? false : _ref$skipSuspense,
|
|
38
|
+
additionalWidgetProperties = _objectWithoutProperties(_ref, _excluded);
|
|
35
39
|
var serverContext = (0, _useInstantSearchServerContext.useInstantSearchServerContext)();
|
|
36
40
|
var ssrContext = (0, _useInstantSearchSSRContext.useInstantSearchSSRContext)();
|
|
37
41
|
var search = (0, _useInstantSearchContext.useInstantSearchContext)();
|
|
@@ -65,7 +69,7 @@ function useConnector(connector) {
|
|
|
65
69
|
if (shouldSetStateRef.current) {
|
|
66
70
|
var instantSearchInstance = connectorState.instantSearchInstance,
|
|
67
71
|
widgetParams = connectorState.widgetParams,
|
|
68
|
-
renderState = _objectWithoutProperties(connectorState,
|
|
72
|
+
renderState = _objectWithoutProperties(connectorState, _excluded2);
|
|
69
73
|
|
|
70
74
|
// We only update the state when a widget render state param changes,
|
|
71
75
|
// except for functions. We ignore function reference changes to avoid
|
|
@@ -121,7 +125,7 @@ function useConnector(connector) {
|
|
|
121
125
|
error: search.error
|
|
122
126
|
}),
|
|
123
127
|
widgetParams = _widget$getWidgetRend.widgetParams,
|
|
124
|
-
renderState = _objectWithoutProperties(_widget$getWidgetRend,
|
|
128
|
+
renderState = _objectWithoutProperties(_widget$getWidgetRend, _excluded3);
|
|
125
129
|
return renderState;
|
|
126
130
|
}
|
|
127
131
|
return {};
|
|
@@ -133,7 +137,8 @@ function useConnector(connector) {
|
|
|
133
137
|
widget: widget,
|
|
134
138
|
parentIndex: parentIndex,
|
|
135
139
|
props: stableProps,
|
|
136
|
-
shouldSsr: Boolean(serverContext)
|
|
140
|
+
shouldSsr: Boolean(serverContext),
|
|
141
|
+
skipSuspense: skipSuspense
|
|
137
142
|
});
|
|
138
143
|
return state;
|
|
139
144
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -457,6 +457,18 @@ Object.keys(_InstantSearchRSCContext).forEach(function (key) {
|
|
|
457
457
|
}
|
|
458
458
|
});
|
|
459
459
|
});
|
|
460
|
+
var _InstantSearchSSRContext = require("./lib/InstantSearchSSRContext");
|
|
461
|
+
Object.keys(_InstantSearchSSRContext).forEach(function (key) {
|
|
462
|
+
if (key === "default" || key === "__esModule") return;
|
|
463
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
464
|
+
if (key in exports && exports[key] === _InstantSearchSSRContext[key]) return;
|
|
465
|
+
Object.defineProperty(exports, key, {
|
|
466
|
+
enumerable: true,
|
|
467
|
+
get: function get() {
|
|
468
|
+
return _InstantSearchSSRContext[key];
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
});
|
|
460
472
|
var _server = require("./server");
|
|
461
473
|
Object.keys(_server).forEach(function (key) {
|
|
462
474
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -5,4 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.InstantSearchRSCContext = void 0;
|
|
7
7
|
var _react = require("react");
|
|
8
|
-
var InstantSearchRSCContext = exports.InstantSearchRSCContext = /*#__PURE__*/(0, _react.createContext)(
|
|
8
|
+
var InstantSearchRSCContext = exports.InstantSearchRSCContext = /*#__PURE__*/(0, _react.createContext)({
|
|
9
|
+
countRef: {
|
|
10
|
+
current: 0
|
|
11
|
+
},
|
|
12
|
+
waitForResultsRef: null,
|
|
13
|
+
ignoreMultipleHooksWarning: false
|
|
14
|
+
});
|
package/dist/cjs/lib/useIndex.js
CHANGED
|
@@ -32,7 +32,8 @@ function useIndex(props) {
|
|
|
32
32
|
widget: indexWidget,
|
|
33
33
|
parentIndex: parentIndex,
|
|
34
34
|
props: stableProps,
|
|
35
|
-
shouldSsr: Boolean(serverContext || initialResults)
|
|
35
|
+
shouldSsr: Boolean(serverContext || initialResults),
|
|
36
|
+
skipSuspense: true
|
|
36
37
|
});
|
|
37
38
|
return indexWidget;
|
|
38
39
|
}
|
|
@@ -12,7 +12,7 @@ var _dequal = require("./dequal");
|
|
|
12
12
|
var _useForceUpdate = require("./useForceUpdate");
|
|
13
13
|
var _useInstantSearchServerContext = require("./useInstantSearchServerContext");
|
|
14
14
|
var _useInstantSearchSSRContext = require("./useInstantSearchSSRContext");
|
|
15
|
-
var
|
|
15
|
+
var _useRSCContext2 = require("./useRSCContext");
|
|
16
16
|
var _warn = require("./warn");
|
|
17
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
18
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
@@ -32,15 +32,16 @@ function useInstantSearchApi(props) {
|
|
|
32
32
|
var forceUpdate = (0, _useForceUpdate.useForceUpdate)();
|
|
33
33
|
var serverContext = (0, _useInstantSearchServerContext.useInstantSearchServerContext)();
|
|
34
34
|
var serverState = (0, _useInstantSearchSSRContext.useInstantSearchSSRContext)();
|
|
35
|
-
var
|
|
35
|
+
var _useRSCContext = (0, _useRSCContext2.useRSCContext)(),
|
|
36
|
+
waitForResultsRef = _useRSCContext.waitForResultsRef;
|
|
36
37
|
var initialResults = serverState === null || serverState === void 0 ? void 0 : serverState.initialResults;
|
|
37
38
|
var prevPropsRef = (0, _react.useRef)(props);
|
|
38
|
-
var shouldRenderAtOnce = serverContext || initialResults ||
|
|
39
|
+
var shouldRenderAtOnce = serverContext || initialResults || waitForResultsRef;
|
|
39
40
|
var searchRef = (0, _react.useRef)(null);
|
|
40
41
|
// As we need to render on mount with SSR, using the local ref above in `StrictMode` will
|
|
41
42
|
// create and start two instances of InstantSearch. To avoid this, we instead discard it and use
|
|
42
43
|
// an upward ref from `InstantSearchSSRContext` as it has already been mounted a second time at this point.
|
|
43
|
-
if (serverState) {
|
|
44
|
+
if (serverState !== null && serverState !== void 0 && serverState.ssrSearchRef) {
|
|
44
45
|
searchRef = serverState.ssrSearchRef;
|
|
45
46
|
}
|
|
46
47
|
if (searchRef.current === null) {
|
|
@@ -67,6 +68,10 @@ function useInstantSearchApi(props) {
|
|
|
67
68
|
// an additional network request. (This is equivalent to monkey-patching
|
|
68
69
|
// `scheduleSearch` to a noop.)
|
|
69
70
|
search._initialResults = initialResults || {};
|
|
71
|
+
// We don't rely on the `defer` to reset the schedule search, but will call
|
|
72
|
+
// `search._resetScheduleSearch()` manually in the effect after children
|
|
73
|
+
// mount in `InstantSearch`.
|
|
74
|
+
search._manuallyResetScheduleSearch = true;
|
|
70
75
|
}
|
|
71
76
|
addAlgoliaAgents(props.searchClient, [].concat(defaultUserAgents, [serverContext && serverUserAgent, nextUserAgent(getNextVersion())]));
|
|
72
77
|
|
|
@@ -84,7 +89,7 @@ function useInstantSearchApi(props) {
|
|
|
84
89
|
});
|
|
85
90
|
}
|
|
86
91
|
warnNextRouter(props.routing);
|
|
87
|
-
warnNextAppDir(Boolean(
|
|
92
|
+
warnNextAppDir(Boolean(waitForResultsRef));
|
|
88
93
|
searchRef.current = search;
|
|
89
94
|
}
|
|
90
95
|
{
|
|
@@ -151,6 +156,9 @@ function useInstantSearchApi(props) {
|
|
|
151
156
|
search._preventWidgetCleanup = false;
|
|
152
157
|
}
|
|
153
158
|
return function () {
|
|
159
|
+
if (serverState !== null && serverState !== void 0 && serverState.ssrSearchRef) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
154
162
|
function cleanup() {
|
|
155
163
|
search.dispose();
|
|
156
164
|
}
|
|
@@ -162,13 +170,12 @@ function useInstantSearchApi(props) {
|
|
|
162
170
|
// in the next effect.
|
|
163
171
|
// (There might be better ways to do this.)
|
|
164
172
|
cleanupTimerRef.current = setTimeout(cleanup);
|
|
165
|
-
|
|
166
173
|
// We need to prevent the `useWidget` cleanup function so that widgets
|
|
167
174
|
// are not removed before the instance is disposed, triggering
|
|
168
175
|
// an unwanted search request.
|
|
169
176
|
search._preventWidgetCleanup = true;
|
|
170
177
|
};
|
|
171
|
-
}, [forceUpdate]), function () {
|
|
178
|
+
}, [forceUpdate, serverState]), function () {
|
|
172
179
|
return searchRef.current;
|
|
173
180
|
}, function () {
|
|
174
181
|
return searchRef.current;
|
|
@@ -200,7 +207,7 @@ function warnNextAppDir(isRscContextDefined) {
|
|
|
200
207
|
if (!(process.env.NODE_ENV === 'development') || typeof window === 'undefined' || isRscContextDefined) {
|
|
201
208
|
return;
|
|
202
209
|
}
|
|
203
|
-
process.env.NODE_ENV === 'development' ? (0, _warn.warn)(Boolean((_next = window.next) === null || _next === void 0 ? void 0 : _next.appDir) === false, "\nWe've detected you are using Next.js with the App Router.\nWe released
|
|
210
|
+
process.env.NODE_ENV === 'development' ? (0, _warn.warn)(Boolean((_next = window.next) === null || _next === void 0 ? void 0 : _next.appDir) === false, "\nWe've detected you are using Next.js with the App Router.\nWe released a package called \"react-instantsearch-nextjs\" that makes SSR work with the App Router.\nPlease check its usage instructions: https://www.algolia.com/doc/guides/building-search-ui/going-further/server-side-rendering/react/#with-nextjs-app-router\n\nThis warning will not be outputted in production builds.") : void 0;
|
|
204
211
|
}
|
|
205
212
|
|
|
206
213
|
/**
|
|
@@ -9,14 +9,19 @@ var _dequal = require("./dequal");
|
|
|
9
9
|
var _use = require("./use");
|
|
10
10
|
var _useInstantSearchContext = require("./useInstantSearchContext");
|
|
11
11
|
var _useIsomorphicLayoutEffect = require("./useIsomorphicLayoutEffect");
|
|
12
|
-
var
|
|
12
|
+
var _useRSCContext2 = require("./useRSCContext");
|
|
13
|
+
var _warn = require("./warn");
|
|
13
14
|
function useWidget(_ref) {
|
|
14
|
-
var
|
|
15
|
+
var _waitForResultsRef$cu, _waitForResultsRef$cu2;
|
|
15
16
|
var widget = _ref.widget,
|
|
16
17
|
parentIndex = _ref.parentIndex,
|
|
17
18
|
props = _ref.props,
|
|
18
|
-
shouldSsr = _ref.shouldSsr
|
|
19
|
-
|
|
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;
|
|
20
25
|
var prevPropsRef = (0, _react.useRef)(props);
|
|
21
26
|
(0, _react.useEffect)(function () {
|
|
22
27
|
prevPropsRef.current = props;
|
|
@@ -76,18 +81,20 @@ function useWidget(_ref) {
|
|
|
76
81
|
});
|
|
77
82
|
};
|
|
78
83
|
}, [parentIndex, widget, shouldSsr, search, props]);
|
|
79
|
-
if (shouldAddWidgetEarly || (
|
|
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') {
|
|
80
85
|
parentIndex.addWidgets([widget]);
|
|
81
86
|
}
|
|
82
|
-
if (
|
|
83
|
-
// We need the widgets contained in the index to be added before we trigger the search request.
|
|
84
|
-
widget.$$type !== 'ais.index') {
|
|
87
|
+
if (waitForResultsRef !== null && waitForResultsRef !== void 0 && waitForResultsRef.current && !skipSuspense) {
|
|
85
88
|
var _search$helper;
|
|
86
|
-
(0, _use.use)(
|
|
89
|
+
(0, _use.use)(waitForResultsRef.current);
|
|
87
90
|
// If we made a second request because of DynamicWidgets, we need to wait for the second result,
|
|
88
91
|
// except for DynamicWidgets itself which needs to render its children after the first result.
|
|
89
92
|
if (widget.$$type !== 'ais.dynamicWidgets' && (_search$helper = search.helper) !== null && _search$helper !== void 0 && _search$helper.lastResults) {
|
|
90
|
-
(0, _use.use)(
|
|
93
|
+
(0, _use.use)(waitForResultsRef.current);
|
|
91
94
|
}
|
|
92
95
|
}
|
|
96
|
+
if ((waitForResultsRef === null || waitForResultsRef === void 0 ? void 0 : (_waitForResultsRef$cu2 = waitForResultsRef.current) === null || _waitForResultsRef$cu2 === void 0 ? void 0 : _waitForResultsRef$cu2.status) === 'fulfilled') {
|
|
97
|
+
countRef.current += 1;
|
|
98
|
+
process.env.NODE_ENV === 'development' ? (0, _warn.warn)(countRef.current > parentIndex.getWidgets().length && !ignoreMultipleHooksWarning, "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
|
+
}
|
|
93
100
|
}
|
package/dist/cjs/version.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var _excluded = ["children"];
|
|
2
2
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
3
3
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
4
|
-
import React from 'react';
|
|
4
|
+
import React, { useEffect } from 'react';
|
|
5
5
|
import { IndexContext } from "../lib/IndexContext.js";
|
|
6
6
|
import { InstantSearchContext } from "../lib/InstantSearchContext.js";
|
|
7
7
|
import { useInstantSearchApi } from "../lib/useInstantSearchApi.js";
|
|
@@ -16,5 +16,16 @@ export function InstantSearch(_ref) {
|
|
|
16
16
|
value: search
|
|
17
17
|
}, /*#__PURE__*/React.createElement(IndexContext.Provider, {
|
|
18
18
|
value: search.mainIndex
|
|
19
|
-
}, children
|
|
19
|
+
}, children, /*#__PURE__*/React.createElement(ResetScheduleSearch, {
|
|
20
|
+
search: search
|
|
21
|
+
})));
|
|
22
|
+
}
|
|
23
|
+
function ResetScheduleSearch(_ref2) {
|
|
24
|
+
var search = _ref2.search;
|
|
25
|
+
useEffect(function () {
|
|
26
|
+
if (search._resetScheduleSearch) {
|
|
27
|
+
search._resetScheduleSearch();
|
|
28
|
+
}
|
|
29
|
+
}, [search]);
|
|
30
|
+
return null;
|
|
20
31
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import type { Connector, Widget, WidgetDescription } from 'instantsearch.js';
|
|
2
|
-
export type AdditionalWidgetProperties = Partial<Widget<WidgetDescription
|
|
3
|
-
|
|
2
|
+
export type AdditionalWidgetProperties = Partial<Widget<WidgetDescription>> & {
|
|
3
|
+
skipSuspense?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export declare function useConnector<TProps extends Record<string, unknown>, TDescription extends WidgetDescription>(connector: Connector<TDescription, TProps>, props?: TProps, { skipSuspense, ...additionalWidgetProperties }?: AdditionalWidgetProperties): TDescription['renderState'];
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
var _excluded = ["
|
|
3
|
-
_excluded2 = ["widgetParams"]
|
|
2
|
+
var _excluded = ["skipSuspense"],
|
|
3
|
+
_excluded2 = ["instantSearchInstance", "widgetParams"],
|
|
4
|
+
_excluded3 = ["widgetParams"];
|
|
4
5
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
5
6
|
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."); }
|
|
6
7
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -25,7 +26,10 @@ import { useStableValue } from "../lib/useStableValue.js";
|
|
|
25
26
|
import { useWidget } from "../lib/useWidget.js";
|
|
26
27
|
export function useConnector(connector) {
|
|
27
28
|
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
28
|
-
var
|
|
29
|
+
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
|
30
|
+
_ref$skipSuspense = _ref.skipSuspense,
|
|
31
|
+
skipSuspense = _ref$skipSuspense === void 0 ? false : _ref$skipSuspense,
|
|
32
|
+
additionalWidgetProperties = _objectWithoutProperties(_ref, _excluded);
|
|
29
33
|
var serverContext = useInstantSearchServerContext();
|
|
30
34
|
var ssrContext = useInstantSearchSSRContext();
|
|
31
35
|
var search = useInstantSearchContext();
|
|
@@ -59,7 +63,7 @@ export function useConnector(connector) {
|
|
|
59
63
|
if (shouldSetStateRef.current) {
|
|
60
64
|
var instantSearchInstance = connectorState.instantSearchInstance,
|
|
61
65
|
widgetParams = connectorState.widgetParams,
|
|
62
|
-
renderState = _objectWithoutProperties(connectorState,
|
|
66
|
+
renderState = _objectWithoutProperties(connectorState, _excluded2);
|
|
63
67
|
|
|
64
68
|
// We only update the state when a widget render state param changes,
|
|
65
69
|
// except for functions. We ignore function reference changes to avoid
|
|
@@ -115,7 +119,7 @@ export function useConnector(connector) {
|
|
|
115
119
|
error: search.error
|
|
116
120
|
}),
|
|
117
121
|
widgetParams = _widget$getWidgetRend.widgetParams,
|
|
118
|
-
renderState = _objectWithoutProperties(_widget$getWidgetRend,
|
|
122
|
+
renderState = _objectWithoutProperties(_widget$getWidgetRend, _excluded3);
|
|
119
123
|
return renderState;
|
|
120
124
|
}
|
|
121
125
|
return {};
|
|
@@ -127,7 +131,8 @@ export function useConnector(connector) {
|
|
|
127
131
|
widget: widget,
|
|
128
132
|
parentIndex: parentIndex,
|
|
129
133
|
props: stableProps,
|
|
130
|
-
shouldSsr: Boolean(serverContext)
|
|
134
|
+
shouldSsr: Boolean(serverContext),
|
|
135
|
+
skipSuspense: skipSuspense
|
|
131
136
|
});
|
|
132
137
|
return state;
|
|
133
138
|
}
|
package/dist/es/index.d.ts
CHANGED
package/dist/es/index.js
CHANGED
|
@@ -36,4 +36,5 @@ export * from "./lib/wrapPromiseWithState.js";
|
|
|
36
36
|
export * from "./lib/useInstantSearchContext.js";
|
|
37
37
|
export * from "./lib/useRSCContext.js";
|
|
38
38
|
export * from "./lib/InstantSearchRSCContext.js";
|
|
39
|
+
export * from "./lib/InstantSearchSSRContext.js";
|
|
39
40
|
export * from "./server/index.js";
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import type { PromiseWithState } from './wrapPromiseWithState';
|
|
2
|
-
import type {
|
|
3
|
-
export type InstantSearchRSCContextApi =
|
|
2
|
+
import type { RefObject } from 'react';
|
|
3
|
+
export type InstantSearchRSCContextApi = {
|
|
4
|
+
waitForResultsRef: RefObject<PromiseWithState<void> | null> | null;
|
|
5
|
+
countRef: RefObject<number>;
|
|
6
|
+
ignoreMultipleHooksWarning: boolean;
|
|
7
|
+
};
|
|
4
8
|
export declare const InstantSearchRSCContext: import("react").Context<InstantSearchRSCContextApi>;
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import { createContext } from 'react';
|
|
2
|
-
export var InstantSearchRSCContext = /*#__PURE__*/createContext(
|
|
2
|
+
export var InstantSearchRSCContext = /*#__PURE__*/createContext({
|
|
3
|
+
countRef: {
|
|
4
|
+
current: 0
|
|
5
|
+
},
|
|
6
|
+
waitForResultsRef: null,
|
|
7
|
+
ignoreMultipleHooksWarning: false
|
|
8
|
+
});
|
package/dist/es/lib/useIndex.js
CHANGED
|
@@ -25,7 +25,8 @@ export function useIndex(props) {
|
|
|
25
25
|
widget: indexWidget,
|
|
26
26
|
parentIndex: parentIndex,
|
|
27
27
|
props: stableProps,
|
|
28
|
-
shouldSsr: Boolean(serverContext || initialResults)
|
|
28
|
+
shouldSsr: Boolean(serverContext || initialResults),
|
|
29
|
+
skipSuspense: true
|
|
29
30
|
});
|
|
30
31
|
return indexWidget;
|
|
31
32
|
}
|
|
@@ -23,15 +23,16 @@ export function useInstantSearchApi(props) {
|
|
|
23
23
|
var forceUpdate = useForceUpdate();
|
|
24
24
|
var serverContext = useInstantSearchServerContext();
|
|
25
25
|
var serverState = useInstantSearchSSRContext();
|
|
26
|
-
var
|
|
26
|
+
var _useRSCContext = useRSCContext(),
|
|
27
|
+
waitForResultsRef = _useRSCContext.waitForResultsRef;
|
|
27
28
|
var initialResults = serverState === null || serverState === void 0 ? void 0 : serverState.initialResults;
|
|
28
29
|
var prevPropsRef = useRef(props);
|
|
29
|
-
var shouldRenderAtOnce = serverContext || initialResults ||
|
|
30
|
+
var shouldRenderAtOnce = serverContext || initialResults || waitForResultsRef;
|
|
30
31
|
var searchRef = useRef(null);
|
|
31
32
|
// As we need to render on mount with SSR, using the local ref above in `StrictMode` will
|
|
32
33
|
// create and start two instances of InstantSearch. To avoid this, we instead discard it and use
|
|
33
34
|
// an upward ref from `InstantSearchSSRContext` as it has already been mounted a second time at this point.
|
|
34
|
-
if (serverState) {
|
|
35
|
+
if (serverState !== null && serverState !== void 0 && serverState.ssrSearchRef) {
|
|
35
36
|
searchRef = serverState.ssrSearchRef;
|
|
36
37
|
}
|
|
37
38
|
if (searchRef.current === null) {
|
|
@@ -58,6 +59,10 @@ export function useInstantSearchApi(props) {
|
|
|
58
59
|
// an additional network request. (This is equivalent to monkey-patching
|
|
59
60
|
// `scheduleSearch` to a noop.)
|
|
60
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;
|
|
61
66
|
}
|
|
62
67
|
addAlgoliaAgents(props.searchClient, [].concat(defaultUserAgents, [serverContext && serverUserAgent, nextUserAgent(getNextVersion())]));
|
|
63
68
|
|
|
@@ -75,7 +80,7 @@ export function useInstantSearchApi(props) {
|
|
|
75
80
|
});
|
|
76
81
|
}
|
|
77
82
|
warnNextRouter(props.routing);
|
|
78
|
-
warnNextAppDir(Boolean(
|
|
83
|
+
warnNextAppDir(Boolean(waitForResultsRef));
|
|
79
84
|
searchRef.current = search;
|
|
80
85
|
}
|
|
81
86
|
{
|
|
@@ -142,6 +147,9 @@ export function useInstantSearchApi(props) {
|
|
|
142
147
|
search._preventWidgetCleanup = false;
|
|
143
148
|
}
|
|
144
149
|
return function () {
|
|
150
|
+
if (serverState !== null && serverState !== void 0 && serverState.ssrSearchRef) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
145
153
|
function cleanup() {
|
|
146
154
|
search.dispose();
|
|
147
155
|
}
|
|
@@ -153,13 +161,12 @@ export function useInstantSearchApi(props) {
|
|
|
153
161
|
// in the next effect.
|
|
154
162
|
// (There might be better ways to do this.)
|
|
155
163
|
cleanupTimerRef.current = setTimeout(cleanup);
|
|
156
|
-
|
|
157
164
|
// We need to prevent the `useWidget` cleanup function so that widgets
|
|
158
165
|
// are not removed before the instance is disposed, triggering
|
|
159
166
|
// an unwanted search request.
|
|
160
167
|
search._preventWidgetCleanup = true;
|
|
161
168
|
};
|
|
162
|
-
}, [forceUpdate]), function () {
|
|
169
|
+
}, [forceUpdate, serverState]), function () {
|
|
163
170
|
return searchRef.current;
|
|
164
171
|
}, function () {
|
|
165
172
|
return searchRef.current;
|
|
@@ -191,7 +198,7 @@ function warnNextAppDir(isRscContextDefined) {
|
|
|
191
198
|
if (!(process.env.NODE_ENV === 'development') || typeof window === 'undefined' || isRscContextDefined) {
|
|
192
199
|
return;
|
|
193
200
|
}
|
|
194
|
-
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
|
|
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;
|
|
195
202
|
}
|
|
196
203
|
|
|
197
204
|
/**
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { Widget } from 'instantsearch.js';
|
|
2
2
|
import type { IndexWidget } from 'instantsearch.js/es/widgets/index/index';
|
|
3
|
-
export declare function useWidget<TWidget extends Widget | IndexWidget, TProps>({ widget, parentIndex, props, shouldSsr, }: {
|
|
3
|
+
export declare function useWidget<TWidget extends Widget | IndexWidget, TProps>({ widget, parentIndex, props, shouldSsr, skipSuspense, }: {
|
|
4
4
|
widget: TWidget;
|
|
5
5
|
parentIndex: IndexWidget;
|
|
6
6
|
props: TProps;
|
|
7
7
|
shouldSsr: boolean;
|
|
8
|
+
skipSuspense: boolean;
|
|
8
9
|
}): void;
|
package/dist/es/lib/useWidget.js
CHANGED
|
@@ -4,13 +4,18 @@ import { use } from "./use.js";
|
|
|
4
4
|
import { useInstantSearchContext } from "./useInstantSearchContext.js";
|
|
5
5
|
import { useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect.js";
|
|
6
6
|
import { useRSCContext } from "./useRSCContext.js";
|
|
7
|
+
import { warn } from "./warn.js";
|
|
7
8
|
export function useWidget(_ref) {
|
|
8
|
-
var
|
|
9
|
+
var _waitForResultsRef$cu, _waitForResultsRef$cu2;
|
|
9
10
|
var widget = _ref.widget,
|
|
10
11
|
parentIndex = _ref.parentIndex,
|
|
11
12
|
props = _ref.props,
|
|
12
|
-
shouldSsr = _ref.shouldSsr
|
|
13
|
-
|
|
13
|
+
shouldSsr = _ref.shouldSsr,
|
|
14
|
+
skipSuspense = _ref.skipSuspense;
|
|
15
|
+
var _useRSCContext = useRSCContext(),
|
|
16
|
+
waitForResultsRef = _useRSCContext.waitForResultsRef,
|
|
17
|
+
countRef = _useRSCContext.countRef,
|
|
18
|
+
ignoreMultipleHooksWarning = _useRSCContext.ignoreMultipleHooksWarning;
|
|
14
19
|
var prevPropsRef = useRef(props);
|
|
15
20
|
useEffect(function () {
|
|
16
21
|
prevPropsRef.current = props;
|
|
@@ -70,18 +75,20 @@ export function useWidget(_ref) {
|
|
|
70
75
|
});
|
|
71
76
|
};
|
|
72
77
|
}, [parentIndex, widget, shouldSsr, search, props]);
|
|
73
|
-
if (shouldAddWidgetEarly || (
|
|
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') {
|
|
74
79
|
parentIndex.addWidgets([widget]);
|
|
75
80
|
}
|
|
76
|
-
if (
|
|
77
|
-
// We need the widgets contained in the index to be added before we trigger the search request.
|
|
78
|
-
widget.$$type !== 'ais.index') {
|
|
81
|
+
if (waitForResultsRef !== null && waitForResultsRef !== void 0 && waitForResultsRef.current && !skipSuspense) {
|
|
79
82
|
var _search$helper;
|
|
80
|
-
use(
|
|
83
|
+
use(waitForResultsRef.current);
|
|
81
84
|
// If we made a second request because of DynamicWidgets, we need to wait for the second result,
|
|
82
85
|
// except for DynamicWidgets itself which needs to render its children after the first result.
|
|
83
86
|
if (widget.$$type !== 'ais.dynamicWidgets' && (_search$helper = search.helper) !== null && _search$helper !== void 0 && _search$helper.lastResults) {
|
|
84
|
-
use(
|
|
87
|
+
use(waitForResultsRef.current);
|
|
85
88
|
}
|
|
86
89
|
}
|
|
90
|
+
if ((waitForResultsRef === null || waitForResultsRef === void 0 ? void 0 : (_waitForResultsRef$cu2 = waitForResultsRef.current) === null || _waitForResultsRef$cu2 === void 0 ? void 0 : _waitForResultsRef$cu2.status) === 'fulfilled') {
|
|
91
|
+
countRef.current += 1;
|
|
92
|
+
process.env.NODE_ENV === 'development' ? warn(countRef.current > parentIndex.getWidgets().length && !ignoreMultipleHooksWarning, "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
|
+
}
|
|
87
94
|
}
|
package/dist/es/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "7.
|
|
1
|
+
declare const _default: "7.16.1";
|
|
2
2
|
export default _default;
|
package/dist/es/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '7.
|
|
1
|
+
export default '7.16.1';
|