react-instantsearch-nextjs 0.1.9 → 0.1.10
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.
|
@@ -12,26 +12,39 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
12
12
|
var _reactInstantsearchCore = require("react-instantsearch-core");
|
|
13
13
|
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); }
|
|
14
14
|
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; }
|
|
15
|
-
var
|
|
15
|
+
var _ref2 = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null);
|
|
16
16
|
function InitializePromise() {
|
|
17
|
-
var
|
|
17
|
+
var _search = (0, _reactInstantsearchCore.useInstantSearchContext)();
|
|
18
18
|
var waitForResultsRef = (0, _reactInstantsearchCore.useRSCContext)();
|
|
19
19
|
var insertHTML = (0, _react.useContext)(_navigation.ServerInsertedHTMLContext) || function () {
|
|
20
20
|
throw new Error('Missing ServerInsertedHTMLContext');
|
|
21
21
|
};
|
|
22
|
+
|
|
23
|
+
// Extract search parameters from the search client to use them
|
|
24
|
+
// later during hydration.
|
|
25
|
+
var requestParamsList;
|
|
26
|
+
_search.mainHelper.setClient({
|
|
27
|
+
search: function search(queries) {
|
|
28
|
+
requestParamsList = queries.map(function (_ref) {
|
|
29
|
+
var params = _ref.params;
|
|
30
|
+
return params;
|
|
31
|
+
});
|
|
32
|
+
return _search.client.search(queries);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
22
35
|
var waitForResults = function waitForResults() {
|
|
23
36
|
return new Promise(function (resolve) {
|
|
24
|
-
|
|
37
|
+
_search.mainHelper.derivedHelpers[0].on('result', function () {
|
|
25
38
|
resolve();
|
|
26
39
|
});
|
|
27
40
|
});
|
|
28
41
|
};
|
|
29
42
|
var injectInitialResults = function injectInitialResults() {
|
|
30
43
|
var inserted = false;
|
|
31
|
-
var results = (0, _server.getInitialResults)(
|
|
44
|
+
var results = (0, _server.getInitialResults)(_search.mainIndex, requestParamsList);
|
|
32
45
|
insertHTML(function () {
|
|
33
46
|
if (inserted) {
|
|
34
|
-
return
|
|
47
|
+
return _ref2;
|
|
35
48
|
}
|
|
36
49
|
inserted = true;
|
|
37
50
|
return /*#__PURE__*/_react.default.createElement("script", {
|
|
@@ -44,7 +57,7 @@ function InitializePromise() {
|
|
|
44
57
|
if ((waitForResultsRef === null || waitForResultsRef === void 0 ? void 0 : waitForResultsRef.current) === null) {
|
|
45
58
|
waitForResultsRef.current = (0, _reactInstantsearchCore.wrapPromiseWithState)(waitForResults().then(function () {
|
|
46
59
|
var shouldRefetch = false;
|
|
47
|
-
(0, _utils.walkIndex)(
|
|
60
|
+
(0, _utils.walkIndex)(_search.mainIndex, function (index) {
|
|
48
61
|
shouldRefetch = index.getWidgets().some(function (widget) {
|
|
49
62
|
return widget.$$type === 'ais.dynamicWidgets';
|
|
50
63
|
});
|
|
@@ -3,26 +3,39 @@ import { walkIndex } from "instantsearch.js/es/lib/utils/index.js";
|
|
|
3
3
|
import { ServerInsertedHTMLContext } from "next/navigation.js";
|
|
4
4
|
import React, { useContext } from 'react';
|
|
5
5
|
import { useInstantSearchContext, useRSCContext, wrapPromiseWithState } from 'react-instantsearch-core';
|
|
6
|
-
var
|
|
6
|
+
var _ref2 = /*#__PURE__*/React.createElement(React.Fragment, null);
|
|
7
7
|
export function InitializePromise() {
|
|
8
|
-
var
|
|
8
|
+
var _search = useInstantSearchContext();
|
|
9
9
|
var waitForResultsRef = useRSCContext();
|
|
10
10
|
var insertHTML = useContext(ServerInsertedHTMLContext) || function () {
|
|
11
11
|
throw new Error('Missing ServerInsertedHTMLContext');
|
|
12
12
|
};
|
|
13
|
+
|
|
14
|
+
// Extract search parameters from the search client to use them
|
|
15
|
+
// later during hydration.
|
|
16
|
+
var requestParamsList;
|
|
17
|
+
_search.mainHelper.setClient({
|
|
18
|
+
search: function search(queries) {
|
|
19
|
+
requestParamsList = queries.map(function (_ref) {
|
|
20
|
+
var params = _ref.params;
|
|
21
|
+
return params;
|
|
22
|
+
});
|
|
23
|
+
return _search.client.search(queries);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
13
26
|
var waitForResults = function waitForResults() {
|
|
14
27
|
return new Promise(function (resolve) {
|
|
15
|
-
|
|
28
|
+
_search.mainHelper.derivedHelpers[0].on('result', function () {
|
|
16
29
|
resolve();
|
|
17
30
|
});
|
|
18
31
|
});
|
|
19
32
|
};
|
|
20
33
|
var injectInitialResults = function injectInitialResults() {
|
|
21
34
|
var inserted = false;
|
|
22
|
-
var results = getInitialResults(
|
|
35
|
+
var results = getInitialResults(_search.mainIndex, requestParamsList);
|
|
23
36
|
insertHTML(function () {
|
|
24
37
|
if (inserted) {
|
|
25
|
-
return
|
|
38
|
+
return _ref2;
|
|
26
39
|
}
|
|
27
40
|
inserted = true;
|
|
28
41
|
return /*#__PURE__*/React.createElement("script", {
|
|
@@ -35,7 +48,7 @@ export function InitializePromise() {
|
|
|
35
48
|
if ((waitForResultsRef === null || waitForResultsRef === void 0 ? void 0 : waitForResultsRef.current) === null) {
|
|
36
49
|
waitForResultsRef.current = wrapPromiseWithState(waitForResults().then(function () {
|
|
37
50
|
var shouldRefetch = false;
|
|
38
|
-
walkIndex(
|
|
51
|
+
walkIndex(_search.mainIndex, function (index) {
|
|
39
52
|
shouldRefetch = index.getWidgets().some(function (widget) {
|
|
40
53
|
return widget.$$type === 'ais.dynamicWidgets';
|
|
41
54
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-instantsearch-nextjs",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"description": "React InstantSearch SSR utilities for Next.js",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"types": "dist/es/index.d.ts",
|
|
@@ -48,13 +48,13 @@
|
|
|
48
48
|
"test:exports": "node ./__tests__/module/is-es-module.mjs && node ./__tests__/module/is-cjs-module.cjs"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"instantsearch.js": "4.64.
|
|
51
|
+
"instantsearch.js": "4.64.1",
|
|
52
52
|
"next": "13.5.1",
|
|
53
|
-
"react-instantsearch-core": "7.5.
|
|
53
|
+
"react-instantsearch-core": "7.5.3"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"next": ">= 13.4 && < 15",
|
|
57
57
|
"react-instantsearch": ">= 7.1.0 && < 8"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "3f061b181adf4358629406027eec8f79d2577196"
|
|
60
60
|
}
|