react-instantsearch-core 7.0.3 → 7.2.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/README.md +0 -1
- package/dist/cjs/hooks/useInstantSearch.js +5 -1
- package/dist/cjs/index.js +48 -0
- package/dist/cjs/lib/InstantSearchRSCContext.js +9 -0
- package/dist/cjs/lib/use.js +15 -0
- package/dist/cjs/lib/useInstantSearchApi.js +31 -7
- package/dist/cjs/lib/useRSCContext.js +11 -0
- package/dist/cjs/lib/useSearchState.js +11 -1
- package/dist/cjs/lib/useWidget.js +16 -1
- package/dist/cjs/lib/wrapPromiseWithState.js +32 -0
- package/dist/cjs/version.js +1 -1
- package/dist/es/hooks/useInstantSearch.js +5 -1
- package/dist/es/index.d.ts +4 -0
- package/dist/es/index.js +4 -0
- package/dist/es/lib/InstantSearchRSCContext.d.ts +4 -0
- package/dist/es/lib/InstantSearchRSCContext.js +2 -0
- package/dist/es/lib/use.d.ts +3 -0
- package/dist/es/lib/use.js +5 -0
- package/dist/es/lib/useInstantSearchApi.js +29 -7
- package/dist/es/lib/useRSCContext.d.ts +1 -0
- package/dist/es/lib/useRSCContext.js +5 -0
- package/dist/es/lib/useSearchState.d.ts +2 -0
- package/dist/es/lib/useSearchState.js +11 -1
- package/dist/es/lib/useWidget.js +16 -1
- package/dist/es/lib/wrapPromiseWithState.d.ts +14 -0
- package/dist/es/lib/wrapPromiseWithState.js +26 -0
- package/dist/es/version.d.ts +1 -1
- package/dist/es/version.js +1 -1
- package/dist/umd/ReactInstantSearchCore.js +111 -19
- 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 +4 -4
package/README.md
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
|
2
2
|
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
|
3
3
|
|
|
4
|
-
|
|
5
4
|
- [react-instantsearch-core](#react-instantsearch-core)
|
|
6
5
|
- [Installation](#installation)
|
|
7
6
|
- [Getting started](#getting-started)
|
|
@@ -17,7 +17,9 @@ function useInstantSearch() {
|
|
|
17
17
|
uiState = _useSearchState.uiState,
|
|
18
18
|
setUiState = _useSearchState.setUiState,
|
|
19
19
|
indexUiState = _useSearchState.indexUiState,
|
|
20
|
-
setIndexUiState = _useSearchState.setIndexUiState
|
|
20
|
+
setIndexUiState = _useSearchState.setIndexUiState,
|
|
21
|
+
renderState = _useSearchState.renderState,
|
|
22
|
+
indexRenderState = _useSearchState.indexRenderState;
|
|
21
23
|
var _useSearchResults = (0, _useSearchResults2.useSearchResults)(),
|
|
22
24
|
results = _useSearchResults.results,
|
|
23
25
|
scopedResults = _useSearchResults.scopedResults;
|
|
@@ -50,6 +52,8 @@ function useInstantSearch() {
|
|
|
50
52
|
setUiState: setUiState,
|
|
51
53
|
indexUiState: indexUiState,
|
|
52
54
|
setIndexUiState: setIndexUiState,
|
|
55
|
+
renderState: renderState,
|
|
56
|
+
indexRenderState: indexRenderState,
|
|
53
57
|
addMiddlewares: addMiddlewares,
|
|
54
58
|
refresh: refresh,
|
|
55
59
|
status: search.status,
|
package/dist/cjs/index.js
CHANGED
|
@@ -361,6 +361,54 @@ Object.keys(_useInstantSearch).forEach(function (key) {
|
|
|
361
361
|
}
|
|
362
362
|
});
|
|
363
363
|
});
|
|
364
|
+
var _wrapPromiseWithState = require("./lib/wrapPromiseWithState");
|
|
365
|
+
Object.keys(_wrapPromiseWithState).forEach(function (key) {
|
|
366
|
+
if (key === "default" || key === "__esModule") return;
|
|
367
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
368
|
+
if (key in exports && exports[key] === _wrapPromiseWithState[key]) return;
|
|
369
|
+
Object.defineProperty(exports, key, {
|
|
370
|
+
enumerable: true,
|
|
371
|
+
get: function get() {
|
|
372
|
+
return _wrapPromiseWithState[key];
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
});
|
|
376
|
+
var _useInstantSearchContext = require("./lib/useInstantSearchContext");
|
|
377
|
+
Object.keys(_useInstantSearchContext).forEach(function (key) {
|
|
378
|
+
if (key === "default" || key === "__esModule") return;
|
|
379
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
380
|
+
if (key in exports && exports[key] === _useInstantSearchContext[key]) return;
|
|
381
|
+
Object.defineProperty(exports, key, {
|
|
382
|
+
enumerable: true,
|
|
383
|
+
get: function get() {
|
|
384
|
+
return _useInstantSearchContext[key];
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
var _useRSCContext = require("./lib/useRSCContext");
|
|
389
|
+
Object.keys(_useRSCContext).forEach(function (key) {
|
|
390
|
+
if (key === "default" || key === "__esModule") return;
|
|
391
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
392
|
+
if (key in exports && exports[key] === _useRSCContext[key]) return;
|
|
393
|
+
Object.defineProperty(exports, key, {
|
|
394
|
+
enumerable: true,
|
|
395
|
+
get: function get() {
|
|
396
|
+
return _useRSCContext[key];
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
});
|
|
400
|
+
var _InstantSearchRSCContext = require("./lib/InstantSearchRSCContext");
|
|
401
|
+
Object.keys(_InstantSearchRSCContext).forEach(function (key) {
|
|
402
|
+
if (key === "default" || key === "__esModule") return;
|
|
403
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
404
|
+
if (key in exports && exports[key] === _InstantSearchRSCContext[key]) return;
|
|
405
|
+
Object.defineProperty(exports, key, {
|
|
406
|
+
enumerable: true,
|
|
407
|
+
get: function get() {
|
|
408
|
+
return _InstantSearchRSCContext[key];
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
});
|
|
364
412
|
var _server = require("./server");
|
|
365
413
|
Object.keys(_server).forEach(function (key) {
|
|
366
414
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.InstantSearchRSCContext = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var InstantSearchRSCContext = /*#__PURE__*/(0, _react.createContext)(null);
|
|
9
|
+
exports.InstantSearchRSCContext = InstantSearchRSCContext;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.use = void 0;
|
|
8
|
+
var React = _interopRequireWildcard(require("react"));
|
|
9
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
10
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
11
|
+
var useKey = 'use';
|
|
12
|
+
|
|
13
|
+
// @TODO: Remove this file and import directly from React when available.
|
|
14
|
+
var use = React[useKey];
|
|
15
|
+
exports.use = use;
|
|
@@ -4,15 +4,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.useInstantSearchApi = useInstantSearchApi;
|
|
7
|
-
var _InstantSearch =
|
|
7
|
+
var _InstantSearch = _interopRequireWildcard(require("instantsearch.js/cjs/lib/InstantSearch"));
|
|
8
8
|
var _react = require("react");
|
|
9
9
|
var _shim = require("use-sync-external-store/shim");
|
|
10
|
-
var _useInstantSearchServerContext = require("../lib/useInstantSearchServerContext");
|
|
11
|
-
var _useInstantSearchSSRContext = require("../lib/useInstantSearchSSRContext");
|
|
12
10
|
var _version = _interopRequireDefault(require("../version"));
|
|
11
|
+
var _dequal = require("./dequal");
|
|
13
12
|
var _useForceUpdate = require("./useForceUpdate");
|
|
13
|
+
var _useInstantSearchServerContext = require("./useInstantSearchServerContext");
|
|
14
|
+
var _useInstantSearchSSRContext = require("./useInstantSearchSSRContext");
|
|
15
|
+
var _useRSCContext = require("./useRSCContext");
|
|
14
16
|
var _warn = require("./warn");
|
|
15
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
20
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
21
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
22
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
23
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
24
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
25
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
16
26
|
var defaultUserAgents = ["react (".concat(_react.version, ")"), "react-instantsearch (".concat(_version.default, ")"), "react-instantsearch-core (".concat(_version.default, ")")];
|
|
17
27
|
var serverUserAgent = "react-instantsearch-server (".concat(_version.default, ")");
|
|
18
28
|
var nextUserAgent = function nextUserAgent(nextVersion) {
|
|
@@ -22,8 +32,10 @@ function useInstantSearchApi(props) {
|
|
|
22
32
|
var forceUpdate = (0, _useForceUpdate.useForceUpdate)();
|
|
23
33
|
var serverContext = (0, _useInstantSearchServerContext.useInstantSearchServerContext)();
|
|
24
34
|
var serverState = (0, _useInstantSearchSSRContext.useInstantSearchSSRContext)();
|
|
35
|
+
var waitingForResultsRef = (0, _useRSCContext.useRSCContext)();
|
|
25
36
|
var initialResults = serverState === null || serverState === void 0 ? void 0 : serverState.initialResults;
|
|
26
37
|
var prevPropsRef = (0, _react.useRef)(props);
|
|
38
|
+
var shouldRenderAtOnce = serverContext || initialResults || waitingForResultsRef;
|
|
27
39
|
var searchRef = (0, _react.useRef)(null);
|
|
28
40
|
// As we need to render on mount with SSR, using the local ref above in `StrictMode` will
|
|
29
41
|
// create and start two instances of InstantSearch. To avoid this, we instead discard it and use
|
|
@@ -47,7 +59,7 @@ function useInstantSearchApi(props) {
|
|
|
47
59
|
}, 0);
|
|
48
60
|
};
|
|
49
61
|
search._schedule.queue = [];
|
|
50
|
-
if (
|
|
62
|
+
if (shouldRenderAtOnce) {
|
|
51
63
|
// InstantSearch.js has a private Initial Results API that lets us inject
|
|
52
64
|
// results on the search instance.
|
|
53
65
|
// On the server, we default the initial results to an empty object so that
|
|
@@ -61,7 +73,7 @@ function useInstantSearchApi(props) {
|
|
|
61
73
|
// On the server, we start the search early to compute the search parameters.
|
|
62
74
|
// On SSR, we start the search early to directly catch up with the lifecycle
|
|
63
75
|
// and render.
|
|
64
|
-
if (
|
|
76
|
+
if (shouldRenderAtOnce) {
|
|
65
77
|
search.start();
|
|
66
78
|
}
|
|
67
79
|
if (serverContext) {
|
|
@@ -72,6 +84,7 @@ function useInstantSearchApi(props) {
|
|
|
72
84
|
});
|
|
73
85
|
}
|
|
74
86
|
warnNextRouter(props.routing);
|
|
87
|
+
warnNextAppDir(Boolean(waitingForResultsRef));
|
|
75
88
|
searchRef.current = search;
|
|
76
89
|
}
|
|
77
90
|
{
|
|
@@ -105,6 +118,10 @@ function useInstantSearchApi(props) {
|
|
|
105
118
|
_search._stalledSearchDelay = (_props$stalledSearchD = props.stalledSearchDelay) !== null && _props$stalledSearchD !== void 0 ? _props$stalledSearchD : 200;
|
|
106
119
|
prevPropsRef.current = props;
|
|
107
120
|
}
|
|
121
|
+
if (!(0, _dequal.dequal)(prevProps.future, props.future)) {
|
|
122
|
+
_search.future = _objectSpread(_objectSpread({}, _InstantSearch.INSTANTSEARCH_FUTURE_DEFAULTS), props.future);
|
|
123
|
+
prevPropsRef.current = props;
|
|
124
|
+
}
|
|
108
125
|
|
|
109
126
|
// Updating the `routing` prop is not supported because InstantSearch.js
|
|
110
127
|
// doesn't let us change it. This might not be a problem though, because `routing`
|
|
@@ -179,6 +196,13 @@ function warnNextRouter(routing) {
|
|
|
179
196
|
process.env.NODE_ENV === 'development' ? (0, _warn.warn)(isUsingNextRouter, "\nYou are using Next.js with InstantSearch without the \"react-instantsearch-router-nextjs\" package.\nThis package is recommended to make the routing work correctly with Next.js.\nPlease check its usage instructions: https://github.com/algolia/instantsearch/tree/master/packages/react-instantsearch-router-nextjs\n\nYou can ignore this warning if you are using a custom router that suits your needs, it won't be outputted in production builds.") : void 0;
|
|
180
197
|
}
|
|
181
198
|
}
|
|
199
|
+
function warnNextAppDir(isRscContextDefined) {
|
|
200
|
+
var _next;
|
|
201
|
+
if (!(process.env.NODE_ENV === 'development') || typeof window === 'undefined' || isRscContextDefined) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
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 an **experimental** 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\n\nThis warning will not be outputted in production builds.") : void 0;
|
|
205
|
+
}
|
|
182
206
|
|
|
183
207
|
/**
|
|
184
208
|
* Gets the version of Next.js if it is available in the `window` object,
|
|
@@ -186,6 +210,6 @@ function warnNextRouter(routing) {
|
|
|
186
210
|
* which is either `nodejs` or `edge`.
|
|
187
211
|
*/
|
|
188
212
|
function getNextVersion() {
|
|
189
|
-
var
|
|
190
|
-
return typeof window !== 'undefined' && ((
|
|
213
|
+
var _next2, _process$env;
|
|
214
|
+
return typeof window !== 'undefined' && ((_next2 = window.next) === null || _next2 === void 0 ? void 0 : _next2.version) || (typeof process !== 'undefined' ? (_process$env = process.env) === null || _process$env === void 0 ? void 0 : _process$env.NEXT_RUNTIME : undefined);
|
|
191
215
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useRSCContext = useRSCContext;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _InstantSearchRSCContext = require("./InstantSearchRSCContext");
|
|
9
|
+
function useRSCContext() {
|
|
10
|
+
return (0, _react.useContext)(_InstantSearchRSCContext.InstantSearchRSCContext);
|
|
11
|
+
}
|
|
@@ -24,6 +24,13 @@ function useSearchState() {
|
|
|
24
24
|
uiState = _useState2[0],
|
|
25
25
|
setLocalUiState = _useState2[1];
|
|
26
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] || {};
|
|
27
34
|
var setUiState = (0, _react.useCallback)(function (nextUiState) {
|
|
28
35
|
search.setUiState(nextUiState);
|
|
29
36
|
}, [search]);
|
|
@@ -33,6 +40,7 @@ function useSearchState() {
|
|
|
33
40
|
(0, _react.useEffect)(function () {
|
|
34
41
|
function handleRender() {
|
|
35
42
|
setLocalUiState(search.getUiState());
|
|
43
|
+
setRenderState(search.renderState);
|
|
36
44
|
}
|
|
37
45
|
search.addListener('render', handleRender);
|
|
38
46
|
return function () {
|
|
@@ -43,6 +51,8 @@ function useSearchState() {
|
|
|
43
51
|
uiState: uiState,
|
|
44
52
|
setUiState: setUiState,
|
|
45
53
|
indexUiState: indexUiState,
|
|
46
|
-
setIndexUiState: setIndexUiState
|
|
54
|
+
setIndexUiState: setIndexUiState,
|
|
55
|
+
renderState: renderState,
|
|
56
|
+
indexRenderState: indexRenderState
|
|
47
57
|
};
|
|
48
58
|
}
|
|
@@ -6,13 +6,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.useWidget = useWidget;
|
|
7
7
|
var _react = require("react");
|
|
8
8
|
var _dequal = require("./dequal");
|
|
9
|
+
var _use = require("./use");
|
|
9
10
|
var _useInstantSearchContext = require("./useInstantSearchContext");
|
|
10
11
|
var _useIsomorphicLayoutEffect = require("./useIsomorphicLayoutEffect");
|
|
12
|
+
var _useRSCContext = require("./useRSCContext");
|
|
11
13
|
function useWidget(_ref) {
|
|
14
|
+
var _waitingForResultsRef;
|
|
12
15
|
var widget = _ref.widget,
|
|
13
16
|
parentIndex = _ref.parentIndex,
|
|
14
17
|
props = _ref.props,
|
|
15
18
|
shouldSsr = _ref.shouldSsr;
|
|
19
|
+
var waitingForResultsRef = (0, _useRSCContext.useRSCContext)();
|
|
16
20
|
var prevPropsRef = (0, _react.useRef)(props);
|
|
17
21
|
(0, _react.useEffect)(function () {
|
|
18
22
|
prevPropsRef.current = props;
|
|
@@ -72,7 +76,18 @@ function useWidget(_ref) {
|
|
|
72
76
|
});
|
|
73
77
|
};
|
|
74
78
|
}, [parentIndex, widget, shouldAddWidgetEarly, search, props]);
|
|
75
|
-
if (shouldAddWidgetEarly) {
|
|
79
|
+
if (shouldAddWidgetEarly || (waitingForResultsRef === null || waitingForResultsRef === void 0 ? void 0 : (_waitingForResultsRef = waitingForResultsRef.current) === null || _waitingForResultsRef === void 0 ? void 0 : _waitingForResultsRef.status) === 'pending') {
|
|
76
80
|
parentIndex.addWidgets([widget]);
|
|
77
81
|
}
|
|
82
|
+
if (typeof window === 'undefined' && waitingForResultsRef !== null && waitingForResultsRef !== void 0 && waitingForResultsRef.current &&
|
|
83
|
+
// We need the widgets contained in the index to be added before we trigger the search request.
|
|
84
|
+
widget.$$type !== 'ais.index') {
|
|
85
|
+
var _search$helper;
|
|
86
|
+
(0, _use.use)(waitingForResultsRef.current);
|
|
87
|
+
// If we made a second request because of DynamicWidgets, we need to wait for the second result,
|
|
88
|
+
// except for DynamicWidgets itself which needs to render its children after the first result.
|
|
89
|
+
if (widget.$$type !== 'ais.dynamicWidgets' && (_search$helper = search.helper) !== null && _search$helper !== void 0 && _search$helper.lastResults) {
|
|
90
|
+
(0, _use.use)(waitingForResultsRef.current);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
78
93
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.wrapPromiseWithState = wrapPromiseWithState;
|
|
7
|
+
// This is needed in order to work with RSC Suspense, perhaps they will later provide a wrapper.
|
|
8
|
+
|
|
9
|
+
function isStatefulPromise(promise) {
|
|
10
|
+
return 'status' in promise;
|
|
11
|
+
}
|
|
12
|
+
function wrapPromiseWithState(promise) {
|
|
13
|
+
if (isStatefulPromise(promise)) {
|
|
14
|
+
return promise;
|
|
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;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return promise;
|
|
32
|
+
}
|
package/dist/cjs/version.js
CHANGED
|
@@ -11,7 +11,9 @@ export function useInstantSearch() {
|
|
|
11
11
|
uiState = _useSearchState.uiState,
|
|
12
12
|
setUiState = _useSearchState.setUiState,
|
|
13
13
|
indexUiState = _useSearchState.indexUiState,
|
|
14
|
-
setIndexUiState = _useSearchState.setIndexUiState
|
|
14
|
+
setIndexUiState = _useSearchState.setIndexUiState,
|
|
15
|
+
renderState = _useSearchState.renderState,
|
|
16
|
+
indexRenderState = _useSearchState.indexRenderState;
|
|
15
17
|
var _useSearchResults = useSearchResults(),
|
|
16
18
|
results = _useSearchResults.results,
|
|
17
19
|
scopedResults = _useSearchResults.scopedResults;
|
|
@@ -44,6 +46,8 @@ export function useInstantSearch() {
|
|
|
44
46
|
setUiState: setUiState,
|
|
45
47
|
indexUiState: indexUiState,
|
|
46
48
|
setIndexUiState: setIndexUiState,
|
|
49
|
+
renderState: renderState,
|
|
50
|
+
indexRenderState: indexRenderState,
|
|
47
51
|
addMiddlewares: addMiddlewares,
|
|
48
52
|
refresh: refresh,
|
|
49
53
|
status: search.status,
|
package/dist/es/index.d.ts
CHANGED
|
@@ -28,4 +28,8 @@ export * from './connectors/useStats';
|
|
|
28
28
|
export * from './connectors/useToggleRefinement';
|
|
29
29
|
export * from './hooks/useConnector';
|
|
30
30
|
export * from './hooks/useInstantSearch';
|
|
31
|
+
export * from './lib/wrapPromiseWithState';
|
|
32
|
+
export * from './lib/useInstantSearchContext';
|
|
33
|
+
export * from './lib/useRSCContext';
|
|
34
|
+
export * from './lib/InstantSearchRSCContext';
|
|
31
35
|
export * from './server';
|
package/dist/es/index.js
CHANGED
|
@@ -28,4 +28,8 @@ export * from "./connectors/useStats.js";
|
|
|
28
28
|
export * from "./connectors/useToggleRefinement.js";
|
|
29
29
|
export * from "./hooks/useConnector.js";
|
|
30
30
|
export * from "./hooks/useInstantSearch.js";
|
|
31
|
+
export * from "./lib/wrapPromiseWithState.js";
|
|
32
|
+
export * from "./lib/useInstantSearchContext.js";
|
|
33
|
+
export * from "./lib/useRSCContext.js";
|
|
34
|
+
export * from "./lib/InstantSearchRSCContext.js";
|
|
31
35
|
export * from "./server/index.js";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { PromiseWithState } from './wrapPromiseWithState';
|
|
2
|
+
import type { MutableRefObject } from 'react';
|
|
3
|
+
export type InstantSearchRSCContextApi = MutableRefObject<PromiseWithState<void> | null> | null;
|
|
4
|
+
export declare const InstantSearchRSCContext: import("react").Context<InstantSearchRSCContextApi>;
|
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
7
|
+
import InstantSearch, { INSTANTSEARCH_FUTURE_DEFAULTS } from "instantsearch.js/es/lib/InstantSearch.js";
|
|
2
8
|
import { useCallback, useRef, version as ReactVersion } from 'react';
|
|
3
9
|
import { useSyncExternalStore } from "use-sync-external-store/shim/index.js";
|
|
4
|
-
import { useInstantSearchServerContext } from "./useInstantSearchServerContext.js";
|
|
5
|
-
import { useInstantSearchSSRContext } from "./useInstantSearchSSRContext.js";
|
|
6
10
|
import version from "../version.js";
|
|
11
|
+
import { dequal } from "./dequal.js";
|
|
7
12
|
import { useForceUpdate } from "./useForceUpdate.js";
|
|
13
|
+
import { useInstantSearchServerContext } from "./useInstantSearchServerContext.js";
|
|
14
|
+
import { useInstantSearchSSRContext } from "./useInstantSearchSSRContext.js";
|
|
15
|
+
import { useRSCContext } from "./useRSCContext.js";
|
|
8
16
|
import { warn } from "./warn.js";
|
|
9
17
|
var defaultUserAgents = ["react (".concat(ReactVersion, ")"), "react-instantsearch (".concat(version, ")"), "react-instantsearch-core (".concat(version, ")")];
|
|
10
18
|
var serverUserAgent = "react-instantsearch-server (".concat(version, ")");
|
|
@@ -15,8 +23,10 @@ export function useInstantSearchApi(props) {
|
|
|
15
23
|
var forceUpdate = useForceUpdate();
|
|
16
24
|
var serverContext = useInstantSearchServerContext();
|
|
17
25
|
var serverState = useInstantSearchSSRContext();
|
|
26
|
+
var waitingForResultsRef = useRSCContext();
|
|
18
27
|
var initialResults = serverState === null || serverState === void 0 ? void 0 : serverState.initialResults;
|
|
19
28
|
var prevPropsRef = useRef(props);
|
|
29
|
+
var shouldRenderAtOnce = serverContext || initialResults || waitingForResultsRef;
|
|
20
30
|
var searchRef = useRef(null);
|
|
21
31
|
// As we need to render on mount with SSR, using the local ref above in `StrictMode` will
|
|
22
32
|
// create and start two instances of InstantSearch. To avoid this, we instead discard it and use
|
|
@@ -40,7 +50,7 @@ export function useInstantSearchApi(props) {
|
|
|
40
50
|
}, 0);
|
|
41
51
|
};
|
|
42
52
|
search._schedule.queue = [];
|
|
43
|
-
if (
|
|
53
|
+
if (shouldRenderAtOnce) {
|
|
44
54
|
// InstantSearch.js has a private Initial Results API that lets us inject
|
|
45
55
|
// results on the search instance.
|
|
46
56
|
// On the server, we default the initial results to an empty object so that
|
|
@@ -54,7 +64,7 @@ export function useInstantSearchApi(props) {
|
|
|
54
64
|
// On the server, we start the search early to compute the search parameters.
|
|
55
65
|
// On SSR, we start the search early to directly catch up with the lifecycle
|
|
56
66
|
// and render.
|
|
57
|
-
if (
|
|
67
|
+
if (shouldRenderAtOnce) {
|
|
58
68
|
search.start();
|
|
59
69
|
}
|
|
60
70
|
if (serverContext) {
|
|
@@ -65,6 +75,7 @@ export function useInstantSearchApi(props) {
|
|
|
65
75
|
});
|
|
66
76
|
}
|
|
67
77
|
warnNextRouter(props.routing);
|
|
78
|
+
warnNextAppDir(Boolean(waitingForResultsRef));
|
|
68
79
|
searchRef.current = search;
|
|
69
80
|
}
|
|
70
81
|
{
|
|
@@ -98,6 +109,10 @@ export function useInstantSearchApi(props) {
|
|
|
98
109
|
_search._stalledSearchDelay = (_props$stalledSearchD = props.stalledSearchDelay) !== null && _props$stalledSearchD !== void 0 ? _props$stalledSearchD : 200;
|
|
99
110
|
prevPropsRef.current = props;
|
|
100
111
|
}
|
|
112
|
+
if (!dequal(prevProps.future, props.future)) {
|
|
113
|
+
_search.future = _objectSpread(_objectSpread({}, INSTANTSEARCH_FUTURE_DEFAULTS), props.future);
|
|
114
|
+
prevPropsRef.current = props;
|
|
115
|
+
}
|
|
101
116
|
|
|
102
117
|
// Updating the `routing` prop is not supported because InstantSearch.js
|
|
103
118
|
// doesn't let us change it. This might not be a problem though, because `routing`
|
|
@@ -172,6 +187,13 @@ function warnNextRouter(routing) {
|
|
|
172
187
|
process.env.NODE_ENV === 'development' ? warn(isUsingNextRouter, "\nYou are using Next.js with InstantSearch without the \"react-instantsearch-router-nextjs\" package.\nThis package is recommended to make the routing work correctly with Next.js.\nPlease check its usage instructions: https://github.com/algolia/instantsearch/tree/master/packages/react-instantsearch-router-nextjs\n\nYou can ignore this warning if you are using a custom router that suits your needs, it won't be outputted in production builds.") : void 0;
|
|
173
188
|
}
|
|
174
189
|
}
|
|
190
|
+
function warnNextAppDir(isRscContextDefined) {
|
|
191
|
+
var _next;
|
|
192
|
+
if (!(process.env.NODE_ENV === 'development') || typeof window === 'undefined' || isRscContextDefined) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
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 an **experimental** 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\n\nThis warning will not be outputted in production builds.") : void 0;
|
|
196
|
+
}
|
|
175
197
|
|
|
176
198
|
/**
|
|
177
199
|
* Gets the version of Next.js if it is available in the `window` object,
|
|
@@ -179,6 +201,6 @@ function warnNextRouter(routing) {
|
|
|
179
201
|
* which is either `nodejs` or `edge`.
|
|
180
202
|
*/
|
|
181
203
|
function getNextVersion() {
|
|
182
|
-
var
|
|
183
|
-
return typeof window !== 'undefined' && ((
|
|
204
|
+
var _next2, _process$env;
|
|
205
|
+
return typeof window !== 'undefined' && ((_next2 = window.next) === null || _next2 === void 0 ? void 0 : _next2.version) || (typeof process !== 'undefined' ? (_process$env = process.env) === null || _process$env === void 0 ? void 0 : _process$env.NEXT_RUNTIME : undefined);
|
|
184
206
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useRSCContext(): import("./InstantSearchRSCContext").InstantSearchRSCContextApi;
|
|
@@ -4,5 +4,7 @@ export type SearchStateApi<TUiState extends UiState> = {
|
|
|
4
4
|
setUiState: InstantSearch<TUiState>['setUiState'];
|
|
5
5
|
indexUiState: TUiState[string];
|
|
6
6
|
setIndexUiState: IndexWidget<TUiState>['setIndexUiState'];
|
|
7
|
+
renderState: InstantSearch<TUiState>['renderState'];
|
|
8
|
+
indexRenderState: InstantSearch<TUiState>['renderState'][string];
|
|
7
9
|
};
|
|
8
10
|
export declare function useSearchState<TUiState extends UiState>(): SearchStateApi<TUiState>;
|
|
@@ -18,6 +18,13 @@ export function useSearchState() {
|
|
|
18
18
|
uiState = _useState2[0],
|
|
19
19
|
setLocalUiState = _useState2[1];
|
|
20
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] || {};
|
|
21
28
|
var setUiState = useCallback(function (nextUiState) {
|
|
22
29
|
search.setUiState(nextUiState);
|
|
23
30
|
}, [search]);
|
|
@@ -27,6 +34,7 @@ export function useSearchState() {
|
|
|
27
34
|
useEffect(function () {
|
|
28
35
|
function handleRender() {
|
|
29
36
|
setLocalUiState(search.getUiState());
|
|
37
|
+
setRenderState(search.renderState);
|
|
30
38
|
}
|
|
31
39
|
search.addListener('render', handleRender);
|
|
32
40
|
return function () {
|
|
@@ -37,6 +45,8 @@ export function useSearchState() {
|
|
|
37
45
|
uiState: uiState,
|
|
38
46
|
setUiState: setUiState,
|
|
39
47
|
indexUiState: indexUiState,
|
|
40
|
-
setIndexUiState: setIndexUiState
|
|
48
|
+
setIndexUiState: setIndexUiState,
|
|
49
|
+
renderState: renderState,
|
|
50
|
+
indexRenderState: indexRenderState
|
|
41
51
|
};
|
|
42
52
|
}
|
package/dist/es/lib/useWidget.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react';
|
|
2
2
|
import { dequal } from "./dequal.js";
|
|
3
|
+
import { use } from "./use.js";
|
|
3
4
|
import { useInstantSearchContext } from "./useInstantSearchContext.js";
|
|
4
5
|
import { useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect.js";
|
|
6
|
+
import { useRSCContext } from "./useRSCContext.js";
|
|
5
7
|
export function useWidget(_ref) {
|
|
8
|
+
var _waitingForResultsRef;
|
|
6
9
|
var widget = _ref.widget,
|
|
7
10
|
parentIndex = _ref.parentIndex,
|
|
8
11
|
props = _ref.props,
|
|
9
12
|
shouldSsr = _ref.shouldSsr;
|
|
13
|
+
var waitingForResultsRef = useRSCContext();
|
|
10
14
|
var prevPropsRef = useRef(props);
|
|
11
15
|
useEffect(function () {
|
|
12
16
|
prevPropsRef.current = props;
|
|
@@ -66,7 +70,18 @@ export function useWidget(_ref) {
|
|
|
66
70
|
});
|
|
67
71
|
};
|
|
68
72
|
}, [parentIndex, widget, shouldAddWidgetEarly, search, props]);
|
|
69
|
-
if (shouldAddWidgetEarly) {
|
|
73
|
+
if (shouldAddWidgetEarly || (waitingForResultsRef === null || waitingForResultsRef === void 0 ? void 0 : (_waitingForResultsRef = waitingForResultsRef.current) === null || _waitingForResultsRef === void 0 ? void 0 : _waitingForResultsRef.status) === 'pending') {
|
|
70
74
|
parentIndex.addWidgets([widget]);
|
|
71
75
|
}
|
|
76
|
+
if (typeof window === 'undefined' && waitingForResultsRef !== null && waitingForResultsRef !== void 0 && waitingForResultsRef.current &&
|
|
77
|
+
// We need the widgets contained in the index to be added before we trigger the search request.
|
|
78
|
+
widget.$$type !== 'ais.index') {
|
|
79
|
+
var _search$helper;
|
|
80
|
+
use(waitingForResultsRef.current);
|
|
81
|
+
// If we made a second request because of DynamicWidgets, we need to wait for the second result,
|
|
82
|
+
// except for DynamicWidgets itself which needs to render its children after the first result.
|
|
83
|
+
if (widget.$$type !== 'ais.dynamicWidgets' && (_search$helper = search.helper) !== null && _search$helper !== void 0 && _search$helper.lastResults) {
|
|
84
|
+
use(waitingForResultsRef.current);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
72
87
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
interface PendingPromise<TValue> extends Promise<TValue> {
|
|
2
|
+
status: 'pending';
|
|
3
|
+
}
|
|
4
|
+
interface FulfilledPromise<TValue> extends Promise<TValue> {
|
|
5
|
+
status: 'fulfilled';
|
|
6
|
+
value: TValue;
|
|
7
|
+
}
|
|
8
|
+
interface RejectedPromise<TValue> extends Promise<TValue> {
|
|
9
|
+
status: 'rejected';
|
|
10
|
+
reason: unknown;
|
|
11
|
+
}
|
|
12
|
+
export type PromiseWithState<TValue> = PendingPromise<TValue> | FulfilledPromise<TValue> | RejectedPromise<TValue>;
|
|
13
|
+
export declare function wrapPromiseWithState<TValue>(promise: Promise<TValue>): PromiseWithState<TValue>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// This is needed in order to work with RSC Suspense, perhaps they will later provide a wrapper.
|
|
2
|
+
|
|
3
|
+
function isStatefulPromise(promise) {
|
|
4
|
+
return 'status' in promise;
|
|
5
|
+
}
|
|
6
|
+
export function wrapPromiseWithState(promise) {
|
|
7
|
+
if (isStatefulPromise(promise)) {
|
|
8
|
+
return promise;
|
|
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;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
return promise;
|
|
26
|
+
}
|
package/dist/es/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "7.0
|
|
1
|
+
declare const _default: "7.2.0";
|
|
2
2
|
export default _default;
|
package/dist/es/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '7.0
|
|
1
|
+
export default '7.2.0';
|