react-instantsearch-core 7.0.3 → 7.1.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/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 +17 -6
- package/dist/cjs/lib/useRSCContext.js +11 -0
- 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/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 +17 -6
- package/dist/es/lib/useRSCContext.d.ts +1 -0
- package/dist/es/lib/useRSCContext.js +5 -0
- 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 +65 -8
- 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/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;
|
|
@@ -7,10 +7,11 @@ exports.useInstantSearchApi = useInstantSearchApi;
|
|
|
7
7
|
var _InstantSearch = _interopRequireDefault(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"));
|
|
13
11
|
var _useForceUpdate = require("./useForceUpdate");
|
|
12
|
+
var _useInstantSearchServerContext = require("./useInstantSearchServerContext");
|
|
13
|
+
var _useInstantSearchSSRContext = require("./useInstantSearchSSRContext");
|
|
14
|
+
var _useRSCContext = require("./useRSCContext");
|
|
14
15
|
var _warn = require("./warn");
|
|
15
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
17
|
var defaultUserAgents = ["react (".concat(_react.version, ")"), "react-instantsearch (".concat(_version.default, ")"), "react-instantsearch-core (".concat(_version.default, ")")];
|
|
@@ -22,8 +23,10 @@ function useInstantSearchApi(props) {
|
|
|
22
23
|
var forceUpdate = (0, _useForceUpdate.useForceUpdate)();
|
|
23
24
|
var serverContext = (0, _useInstantSearchServerContext.useInstantSearchServerContext)();
|
|
24
25
|
var serverState = (0, _useInstantSearchSSRContext.useInstantSearchSSRContext)();
|
|
26
|
+
var waitingForResultsRef = (0, _useRSCContext.useRSCContext)();
|
|
25
27
|
var initialResults = serverState === null || serverState === void 0 ? void 0 : serverState.initialResults;
|
|
26
28
|
var prevPropsRef = (0, _react.useRef)(props);
|
|
29
|
+
var shouldRenderAtOnce = serverContext || initialResults || waitingForResultsRef;
|
|
27
30
|
var searchRef = (0, _react.useRef)(null);
|
|
28
31
|
// As we need to render on mount with SSR, using the local ref above in `StrictMode` will
|
|
29
32
|
// create and start two instances of InstantSearch. To avoid this, we instead discard it and use
|
|
@@ -47,7 +50,7 @@ function useInstantSearchApi(props) {
|
|
|
47
50
|
}, 0);
|
|
48
51
|
};
|
|
49
52
|
search._schedule.queue = [];
|
|
50
|
-
if (
|
|
53
|
+
if (shouldRenderAtOnce) {
|
|
51
54
|
// InstantSearch.js has a private Initial Results API that lets us inject
|
|
52
55
|
// results on the search instance.
|
|
53
56
|
// On the server, we default the initial results to an empty object so that
|
|
@@ -61,7 +64,7 @@ function useInstantSearchApi(props) {
|
|
|
61
64
|
// On the server, we start the search early to compute the search parameters.
|
|
62
65
|
// On SSR, we start the search early to directly catch up with the lifecycle
|
|
63
66
|
// and render.
|
|
64
|
-
if (
|
|
67
|
+
if (shouldRenderAtOnce) {
|
|
65
68
|
search.start();
|
|
66
69
|
}
|
|
67
70
|
if (serverContext) {
|
|
@@ -72,6 +75,7 @@ function useInstantSearchApi(props) {
|
|
|
72
75
|
});
|
|
73
76
|
}
|
|
74
77
|
warnNextRouter(props.routing);
|
|
78
|
+
warnNextAppDir(Boolean(waitingForResultsRef));
|
|
75
79
|
searchRef.current = search;
|
|
76
80
|
}
|
|
77
81
|
{
|
|
@@ -179,6 +183,13 @@ function warnNextRouter(routing) {
|
|
|
179
183
|
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
184
|
}
|
|
181
185
|
}
|
|
186
|
+
function warnNextAppDir(isRscContextDefined) {
|
|
187
|
+
var _next;
|
|
188
|
+
if (!(process.env.NODE_ENV === 'development') || typeof window === 'undefined' || isRscContextDefined) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
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;
|
|
192
|
+
}
|
|
182
193
|
|
|
183
194
|
/**
|
|
184
195
|
* Gets the version of Next.js if it is available in the `window` object,
|
|
@@ -186,6 +197,6 @@ function warnNextRouter(routing) {
|
|
|
186
197
|
* which is either `nodejs` or `edge`.
|
|
187
198
|
*/
|
|
188
199
|
function getNextVersion() {
|
|
189
|
-
var
|
|
190
|
-
return typeof window !== 'undefined' && ((
|
|
200
|
+
var _next2, _process$env;
|
|
201
|
+
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
202
|
}
|
|
@@ -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
|
+
}
|
|
@@ -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
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,11 @@
|
|
|
1
1
|
import InstantSearch from "instantsearch.js/es/lib/InstantSearch.js";
|
|
2
2
|
import { useCallback, useRef, version as ReactVersion } from 'react';
|
|
3
3
|
import { useSyncExternalStore } from "use-sync-external-store/shim/index.js";
|
|
4
|
-
import { useInstantSearchServerContext } from "./useInstantSearchServerContext.js";
|
|
5
|
-
import { useInstantSearchSSRContext } from "./useInstantSearchSSRContext.js";
|
|
6
4
|
import version from "../version.js";
|
|
7
5
|
import { useForceUpdate } from "./useForceUpdate.js";
|
|
6
|
+
import { useInstantSearchServerContext } from "./useInstantSearchServerContext.js";
|
|
7
|
+
import { useInstantSearchSSRContext } from "./useInstantSearchSSRContext.js";
|
|
8
|
+
import { useRSCContext } from "./useRSCContext.js";
|
|
8
9
|
import { warn } from "./warn.js";
|
|
9
10
|
var defaultUserAgents = ["react (".concat(ReactVersion, ")"), "react-instantsearch (".concat(version, ")"), "react-instantsearch-core (".concat(version, ")")];
|
|
10
11
|
var serverUserAgent = "react-instantsearch-server (".concat(version, ")");
|
|
@@ -15,8 +16,10 @@ export function useInstantSearchApi(props) {
|
|
|
15
16
|
var forceUpdate = useForceUpdate();
|
|
16
17
|
var serverContext = useInstantSearchServerContext();
|
|
17
18
|
var serverState = useInstantSearchSSRContext();
|
|
19
|
+
var waitingForResultsRef = useRSCContext();
|
|
18
20
|
var initialResults = serverState === null || serverState === void 0 ? void 0 : serverState.initialResults;
|
|
19
21
|
var prevPropsRef = useRef(props);
|
|
22
|
+
var shouldRenderAtOnce = serverContext || initialResults || waitingForResultsRef;
|
|
20
23
|
var searchRef = useRef(null);
|
|
21
24
|
// As we need to render on mount with SSR, using the local ref above in `StrictMode` will
|
|
22
25
|
// create and start two instances of InstantSearch. To avoid this, we instead discard it and use
|
|
@@ -40,7 +43,7 @@ export function useInstantSearchApi(props) {
|
|
|
40
43
|
}, 0);
|
|
41
44
|
};
|
|
42
45
|
search._schedule.queue = [];
|
|
43
|
-
if (
|
|
46
|
+
if (shouldRenderAtOnce) {
|
|
44
47
|
// InstantSearch.js has a private Initial Results API that lets us inject
|
|
45
48
|
// results on the search instance.
|
|
46
49
|
// On the server, we default the initial results to an empty object so that
|
|
@@ -54,7 +57,7 @@ export function useInstantSearchApi(props) {
|
|
|
54
57
|
// On the server, we start the search early to compute the search parameters.
|
|
55
58
|
// On SSR, we start the search early to directly catch up with the lifecycle
|
|
56
59
|
// and render.
|
|
57
|
-
if (
|
|
60
|
+
if (shouldRenderAtOnce) {
|
|
58
61
|
search.start();
|
|
59
62
|
}
|
|
60
63
|
if (serverContext) {
|
|
@@ -65,6 +68,7 @@ export function useInstantSearchApi(props) {
|
|
|
65
68
|
});
|
|
66
69
|
}
|
|
67
70
|
warnNextRouter(props.routing);
|
|
71
|
+
warnNextAppDir(Boolean(waitingForResultsRef));
|
|
68
72
|
searchRef.current = search;
|
|
69
73
|
}
|
|
70
74
|
{
|
|
@@ -172,6 +176,13 @@ function warnNextRouter(routing) {
|
|
|
172
176
|
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
177
|
}
|
|
174
178
|
}
|
|
179
|
+
function warnNextAppDir(isRscContextDefined) {
|
|
180
|
+
var _next;
|
|
181
|
+
if (!(process.env.NODE_ENV === 'development') || typeof window === 'undefined' || isRscContextDefined) {
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
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;
|
|
185
|
+
}
|
|
175
186
|
|
|
176
187
|
/**
|
|
177
188
|
* Gets the version of Next.js if it is available in the `window` object,
|
|
@@ -179,6 +190,6 @@ function warnNextRouter(routing) {
|
|
|
179
190
|
* which is either `nodejs` or `edge`.
|
|
180
191
|
*/
|
|
181
192
|
function getNextVersion() {
|
|
182
|
-
var
|
|
183
|
-
return typeof window !== 'undefined' && ((
|
|
193
|
+
var _next2, _process$env;
|
|
194
|
+
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
195
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useRSCContext(): import("./InstantSearchRSCContext").InstantSearchRSCContextApi;
|
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.1.0";
|
|
2
2
|
export default _default;
|
package/dist/es/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '7.0
|
|
1
|
+
export default '7.1.0';
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
var React__default = 'default' in React ? React['default'] : React;
|
|
9
9
|
|
|
10
|
-
var version = '7.0
|
|
10
|
+
var version = '7.1.0';
|
|
11
11
|
|
|
12
12
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
13
13
|
//
|
|
@@ -4327,7 +4327,7 @@
|
|
|
4327
4327
|
|
|
4328
4328
|
var SearchResults_1 = SearchResults;
|
|
4329
4329
|
|
|
4330
|
-
var version$1 = '3.14.
|
|
4330
|
+
var version$1 = '3.14.2';
|
|
4331
4331
|
|
|
4332
4332
|
var escapeFacetValue$3 = escapeFacetValue_1.escapeFacetValue;
|
|
4333
4333
|
|
|
@@ -8045,6 +8045,11 @@
|
|
|
8045
8045
|
return stableValue;
|
|
8046
8046
|
}
|
|
8047
8047
|
|
|
8048
|
+
var useKey = 'use';
|
|
8049
|
+
|
|
8050
|
+
// @TODO: Remove this file and import directly from React when available.
|
|
8051
|
+
var use = React[useKey];
|
|
8052
|
+
|
|
8048
8053
|
/**
|
|
8049
8054
|
* `useLayoutEffect` that doesn't show a warning when server-side rendering.
|
|
8050
8055
|
*
|
|
@@ -8052,11 +8057,19 @@
|
|
|
8052
8057
|
*/
|
|
8053
8058
|
var useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
|
|
8054
8059
|
|
|
8060
|
+
var InstantSearchRSCContext = /*#__PURE__*/React.createContext(null);
|
|
8061
|
+
|
|
8062
|
+
function useRSCContext() {
|
|
8063
|
+
return React.useContext(InstantSearchRSCContext);
|
|
8064
|
+
}
|
|
8065
|
+
|
|
8055
8066
|
function useWidget(_ref) {
|
|
8067
|
+
var _waitingForResultsRef;
|
|
8056
8068
|
var widget = _ref.widget,
|
|
8057
8069
|
parentIndex = _ref.parentIndex,
|
|
8058
8070
|
props = _ref.props,
|
|
8059
8071
|
shouldSsr = _ref.shouldSsr;
|
|
8072
|
+
var waitingForResultsRef = useRSCContext();
|
|
8060
8073
|
var prevPropsRef = React.useRef(props);
|
|
8061
8074
|
React.useEffect(function () {
|
|
8062
8075
|
prevPropsRef.current = props;
|
|
@@ -8116,9 +8129,20 @@
|
|
|
8116
8129
|
});
|
|
8117
8130
|
};
|
|
8118
8131
|
}, [parentIndex, widget, shouldAddWidgetEarly, search, props]);
|
|
8119
|
-
if (shouldAddWidgetEarly) {
|
|
8132
|
+
if (shouldAddWidgetEarly || (waitingForResultsRef === null || waitingForResultsRef === void 0 ? void 0 : (_waitingForResultsRef = waitingForResultsRef.current) === null || _waitingForResultsRef === void 0 ? void 0 : _waitingForResultsRef.status) === 'pending') {
|
|
8120
8133
|
parentIndex.addWidgets([widget]);
|
|
8121
8134
|
}
|
|
8135
|
+
if (typeof window === 'undefined' && waitingForResultsRef !== null && waitingForResultsRef !== void 0 && waitingForResultsRef.current &&
|
|
8136
|
+
// We need the widgets contained in the index to be added before we trigger the search request.
|
|
8137
|
+
widget.$$type !== 'ais.index') {
|
|
8138
|
+
var _search$helper;
|
|
8139
|
+
use(waitingForResultsRef.current);
|
|
8140
|
+
// If we made a second request because of DynamicWidgets, we need to wait for the second result,
|
|
8141
|
+
// except for DynamicWidgets itself which needs to render its children after the first result.
|
|
8142
|
+
if (widget.$$type !== 'ais.dynamicWidgets' && (_search$helper = search.helper) !== null && _search$helper !== void 0 && _search$helper.lastResults) {
|
|
8143
|
+
use(waitingForResultsRef.current);
|
|
8144
|
+
}
|
|
8145
|
+
}
|
|
8122
8146
|
}
|
|
8123
8147
|
|
|
8124
8148
|
var _excluded$1 = ["instantSearchInstance", "widgetParams"],
|
|
@@ -11262,7 +11286,7 @@
|
|
|
11262
11286
|
};
|
|
11263
11287
|
}
|
|
11264
11288
|
|
|
11265
|
-
var version$2 = '4.
|
|
11289
|
+
var version$2 = '4.57.0';
|
|
11266
11290
|
|
|
11267
11291
|
function _typeof$j(obj) {
|
|
11268
11292
|
"@babel/helpers - typeof";
|
|
@@ -11988,8 +12012,10 @@
|
|
|
11988
12012
|
var forceUpdate = useForceUpdate();
|
|
11989
12013
|
var serverContext = useInstantSearchServerContext();
|
|
11990
12014
|
var serverState = useInstantSearchSSRContext();
|
|
12015
|
+
var waitingForResultsRef = useRSCContext();
|
|
11991
12016
|
var initialResults = serverState === null || serverState === void 0 ? void 0 : serverState.initialResults;
|
|
11992
12017
|
var prevPropsRef = React.useRef(props);
|
|
12018
|
+
var shouldRenderAtOnce = serverContext || initialResults || waitingForResultsRef;
|
|
11993
12019
|
var searchRef = React.useRef(null);
|
|
11994
12020
|
// As we need to render on mount with SSR, using the local ref above in `StrictMode` will
|
|
11995
12021
|
// create and start two instances of InstantSearch. To avoid this, we instead discard it and use
|
|
@@ -12013,7 +12039,7 @@
|
|
|
12013
12039
|
}, 0);
|
|
12014
12040
|
};
|
|
12015
12041
|
search._schedule.queue = [];
|
|
12016
|
-
if (
|
|
12042
|
+
if (shouldRenderAtOnce) {
|
|
12017
12043
|
// InstantSearch.js has a private Initial Results API that lets us inject
|
|
12018
12044
|
// results on the search instance.
|
|
12019
12045
|
// On the server, we default the initial results to an empty object so that
|
|
@@ -12027,7 +12053,7 @@
|
|
|
12027
12053
|
// On the server, we start the search early to compute the search parameters.
|
|
12028
12054
|
// On SSR, we start the search early to directly catch up with the lifecycle
|
|
12029
12055
|
// and render.
|
|
12030
|
-
if (
|
|
12056
|
+
if (shouldRenderAtOnce) {
|
|
12031
12057
|
search.start();
|
|
12032
12058
|
}
|
|
12033
12059
|
if (serverContext) {
|
|
@@ -12141,8 +12167,8 @@
|
|
|
12141
12167
|
* which is either `nodejs` or `edge`.
|
|
12142
12168
|
*/
|
|
12143
12169
|
function getNextVersion() {
|
|
12144
|
-
var
|
|
12145
|
-
return typeof window !== 'undefined' && ((
|
|
12170
|
+
var _next2, _process$env;
|
|
12171
|
+
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);
|
|
12146
12172
|
}
|
|
12147
12173
|
|
|
12148
12174
|
var _excluded$6 = ["children"];
|
|
@@ -17304,6 +17330,33 @@
|
|
|
17304
17330
|
};
|
|
17305
17331
|
}
|
|
17306
17332
|
|
|
17333
|
+
// This is needed in order to work with RSC Suspense, perhaps they will later provide a wrapper.
|
|
17334
|
+
|
|
17335
|
+
function isStatefulPromise(promise) {
|
|
17336
|
+
return 'status' in promise;
|
|
17337
|
+
}
|
|
17338
|
+
function wrapPromiseWithState(promise) {
|
|
17339
|
+
if (isStatefulPromise(promise)) {
|
|
17340
|
+
return promise;
|
|
17341
|
+
}
|
|
17342
|
+
var pendingPromise = promise;
|
|
17343
|
+
pendingPromise.status = 'pending';
|
|
17344
|
+
pendingPromise.then(function (value) {
|
|
17345
|
+
if (pendingPromise.status === 'pending') {
|
|
17346
|
+
var fulfilledPromise = pendingPromise;
|
|
17347
|
+
fulfilledPromise.status = 'fulfilled';
|
|
17348
|
+
fulfilledPromise.value = value;
|
|
17349
|
+
}
|
|
17350
|
+
}, function (reason) {
|
|
17351
|
+
if (pendingPromise.status === 'pending') {
|
|
17352
|
+
var rejectedPromise = pendingPromise;
|
|
17353
|
+
rejectedPromise.status = 'rejected';
|
|
17354
|
+
rejectedPromise.reason = reason;
|
|
17355
|
+
}
|
|
17356
|
+
});
|
|
17357
|
+
return promise;
|
|
17358
|
+
}
|
|
17359
|
+
|
|
17307
17360
|
function _typeof$D(obj) {
|
|
17308
17361
|
"@babel/helpers - typeof";
|
|
17309
17362
|
|
|
@@ -17501,6 +17554,7 @@
|
|
|
17501
17554
|
exports.DynamicWidgets = DynamicWidgets;
|
|
17502
17555
|
exports.Index = Index;
|
|
17503
17556
|
exports.InstantSearch = InstantSearch$1;
|
|
17557
|
+
exports.InstantSearchRSCContext = InstantSearchRSCContext;
|
|
17504
17558
|
exports.InstantSearchSSRProvider = InstantSearchSSRProvider;
|
|
17505
17559
|
exports.InstantSearchServerContext = InstantSearchServerContext;
|
|
17506
17560
|
exports.getServerState = getServerState;
|
|
@@ -17516,11 +17570,13 @@
|
|
|
17516
17570
|
exports.useHitsPerPage = useHitsPerPage;
|
|
17517
17571
|
exports.useInfiniteHits = useInfiniteHits;
|
|
17518
17572
|
exports.useInstantSearch = useInstantSearch;
|
|
17573
|
+
exports.useInstantSearchContext = useInstantSearchContext;
|
|
17519
17574
|
exports.useMenu = useMenu;
|
|
17520
17575
|
exports.useNumericMenu = useNumericMenu;
|
|
17521
17576
|
exports.usePagination = usePagination;
|
|
17522
17577
|
exports.usePoweredBy = usePoweredBy;
|
|
17523
17578
|
exports.useQueryRules = useQueryRules;
|
|
17579
|
+
exports.useRSCContext = useRSCContext;
|
|
17524
17580
|
exports.useRange = useRange;
|
|
17525
17581
|
exports.useRefinementList = useRefinementList;
|
|
17526
17582
|
exports.useSearchBox = useSearchBox;
|
|
@@ -17528,6 +17584,7 @@
|
|
|
17528
17584
|
exports.useStats = useStats;
|
|
17529
17585
|
exports.useToggleRefinement = useToggleRefinement;
|
|
17530
17586
|
exports.version = version;
|
|
17587
|
+
exports.wrapPromiseWithState = wrapPromiseWithState;
|
|
17531
17588
|
|
|
17532
17589
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
17533
17590
|
|