react-instantsearch-nextjs 1.0.15 → 1.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/README.md +1 -6
- package/dist/cjs/InitializePromise.js +92 -97
- package/dist/cjs/InstantSearchNext.js +76 -85
- package/dist/cjs/TriggerSearch.js +40 -43
- package/dist/cjs/createInsertHTML.js +21 -25
- package/dist/cjs/htmlEscape.js +14 -18
- package/dist/cjs/index.js +7 -15
- package/dist/cjs/package.json +4 -1
- package/dist/cjs/useDynamicRouteWarning.js +17 -31
- package/dist/cjs/useInstantSearchRouting.js +61 -64
- package/dist/cjs/useNextHeaders.js +16 -21
- package/dist/es/InitializePromise.js +89 -90
- package/dist/es/InstantSearchNext.js +74 -77
- package/dist/es/TriggerSearch.js +37 -36
- package/dist/es/createInsertHTML.js +19 -18
- package/dist/es/htmlEscape.js +13 -13
- package/dist/es/index.js +1 -1
- package/dist/es/package.json +4 -0
- package/dist/es/useDynamicRouteWarning.js +15 -26
- package/dist/es/useInstantSearchRouting.js +60 -58
- package/dist/es/useNextHeaders.d.ts +9 -2
- package/dist/es/useNextHeaders.js +14 -15
- package/package.json +12 -20
- package/dist/cjs/warn.js +0 -40
- package/dist/es/warn.js +0 -33
package/README.md
CHANGED
|
@@ -17,9 +17,6 @@
|
|
|
17
17
|
|
|
18
18
|
This package provides server-side rendering for [React InstantSearch](https://www.algolia.com/doc/guides/building-search-ui/what-is-instantsearch/react/) that is compatible with [Next.js 13 App Router](https://nextjs.org/docs/app).
|
|
19
19
|
|
|
20
|
-
> [!WARNING]
|
|
21
|
-
> **This package is experimental.**
|
|
22
|
-
|
|
23
20
|
## Installation
|
|
24
21
|
|
|
25
22
|
```sh
|
|
@@ -30,8 +27,7 @@ npm install react-instantsearch-nextjs
|
|
|
30
27
|
|
|
31
28
|
## Usage
|
|
32
29
|
|
|
33
|
-
> [!NOTE]
|
|
34
|
-
> You can check this documentation on [Algolia's Documentation website](https://www.algolia.com/doc/guides/building-search-ui/going-further/server-side-rendering/react/#app-router-experimental).
|
|
30
|
+
> [!NOTE] You can check this documentation on [Algolia's Documentation website](https://www.algolia.com/doc/guides/building-search-ui/going-further/server-side-rendering/react/#app-router-experimental).
|
|
35
31
|
|
|
36
32
|
Your search component must be in its own file, and it shouldn't be named `page.js` or `page.tsx`.
|
|
37
33
|
|
|
@@ -59,7 +55,6 @@ export function Search() {
|
|
|
59
55
|
|
|
60
56
|
Import the `<InstantSearchNext>` component from the `react-instantsearch-nextjs` package, and replace the [`<InstantSearch>`](https://www.algolia.com/doc/api-reference/widgets/instantsearch/react/) component with it, without changing the props.
|
|
61
57
|
|
|
62
|
-
|
|
63
58
|
```diff
|
|
64
59
|
'use client';
|
|
65
60
|
import { liteClient as algoliasearch } from 'algoliasearch/lite';
|
|
@@ -1,101 +1,96 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var _reactInstantsearchCore = require("react-instantsearch-core");
|
|
12
|
-
var _createInsertHTML = require("./createInsertHTML");
|
|
13
|
-
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); }
|
|
14
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
15
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
16
|
-
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
17
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
18
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
19
|
-
function InitializePromise(_ref) {
|
|
20
|
-
var nonce = _ref.nonce;
|
|
21
|
-
var _search = (0, _reactInstantsearchCore.useInstantSearchContext)();
|
|
22
|
-
var _useRSCContext = (0, _reactInstantsearchCore.useRSCContext)(),
|
|
23
|
-
waitForResultsRef = _useRSCContext.waitForResultsRef;
|
|
24
|
-
var insertHTML = (0, _react.useContext)(_navigation.ServerInsertedHTMLContext) || function () {
|
|
25
|
-
throw new Error('Missing ServerInsertedHTMLContext');
|
|
26
|
-
};
|
|
3
|
+
var _object_spread = require('@swc/helpers/_/_object_spread');
|
|
4
|
+
var _object_spread_props = require('@swc/helpers/_/_object_spread_props');
|
|
5
|
+
var server = require('instantsearch.js/cjs/lib/server');
|
|
6
|
+
var utils = require('instantsearch.js/cjs/lib/utils');
|
|
7
|
+
var navigation = require('next/navigation');
|
|
8
|
+
var React = require('react');
|
|
9
|
+
var reactInstantsearchCore = require('react-instantsearch-core');
|
|
10
|
+
var createInsertHTML = require('./createInsertHTML.js');
|
|
27
11
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
requestParamsList = [query.requestBody.params];
|
|
35
|
-
return _search.client.search(query);
|
|
36
|
-
}
|
|
37
|
-
}));
|
|
38
|
-
} else {
|
|
39
|
-
_search.mainHelper.setClient(_objectSpread(_objectSpread({}, _search.mainHelper.getClient()), {}, {
|
|
40
|
-
search: function search(queries) {
|
|
41
|
-
requestParamsList = queries.map(function (_ref2) {
|
|
42
|
-
var params = _ref2.params;
|
|
43
|
-
return params;
|
|
44
|
-
});
|
|
45
|
-
return _search.client.search(queries);
|
|
46
|
-
}
|
|
47
|
-
}));
|
|
48
|
-
}
|
|
49
|
-
(0, _utils.resetWidgetId)();
|
|
50
|
-
var waitForResults = function waitForResults() {
|
|
51
|
-
return new Promise(function (resolve) {
|
|
52
|
-
var searchReceived = false;
|
|
53
|
-
var recommendReceived = false;
|
|
54
|
-
_search.mainHelper.derivedHelpers[0].once('result', function () {
|
|
55
|
-
searchReceived = true;
|
|
56
|
-
if (!_search._hasRecommendWidget || recommendReceived) {
|
|
57
|
-
resolve();
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
_search.mainHelper.derivedHelpers[0].once('recommend:result', function () {
|
|
61
|
-
recommendReceived = true;
|
|
62
|
-
if (!_search._hasSearchWidget || searchReceived) {
|
|
63
|
-
resolve();
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
var injectInitialResults = function injectInitialResults() {
|
|
69
|
-
var options = {
|
|
70
|
-
inserted: false
|
|
12
|
+
function InitializePromise(param) {
|
|
13
|
+
var nonce = param.nonce;
|
|
14
|
+
var search = reactInstantsearchCore.useInstantSearchContext();
|
|
15
|
+
var waitForResultsRef = reactInstantsearchCore.useRSCContext().waitForResultsRef;
|
|
16
|
+
var insertHTML = React.useContext(navigation.ServerInsertedHTMLContext) || function() {
|
|
17
|
+
throw new Error('Missing ServerInsertedHTMLContext');
|
|
71
18
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
19
|
+
// Extract search parameters from the search client to use them
|
|
20
|
+
// later during hydration.
|
|
21
|
+
var requestParamsList;
|
|
22
|
+
if (search.compositionID) {
|
|
23
|
+
search.mainHelper.setClient(_object_spread_props._(_object_spread._({}, search.mainHelper.getClient()), {
|
|
24
|
+
search: function search1(query) {
|
|
25
|
+
requestParamsList = [
|
|
26
|
+
query.requestBody.params
|
|
27
|
+
];
|
|
28
|
+
return search.client.search(query);
|
|
29
|
+
}
|
|
30
|
+
}));
|
|
31
|
+
} else {
|
|
32
|
+
search.mainHelper.setClient(_object_spread_props._(_object_spread._({}, search.mainHelper.getClient()), {
|
|
33
|
+
search: function search1(queries) {
|
|
34
|
+
requestParamsList = queries.map(function(param) {
|
|
35
|
+
var params = param.params;
|
|
36
|
+
return params;
|
|
37
|
+
});
|
|
38
|
+
return search.client.search(queries);
|
|
39
|
+
}
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
utils.resetWidgetId();
|
|
43
|
+
var waitForResults = function waitForResults() {
|
|
44
|
+
return new Promise(function(resolve) {
|
|
45
|
+
var searchReceived = false;
|
|
46
|
+
var recommendReceived = false;
|
|
47
|
+
search.mainHelper.derivedHelpers[0].once('result', function() {
|
|
48
|
+
searchReceived = true;
|
|
49
|
+
if (!search._hasRecommendWidget || recommendReceived) {
|
|
50
|
+
resolve();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
search.mainHelper.derivedHelpers[0].once('recommend:result', function() {
|
|
54
|
+
recommendReceived = true;
|
|
55
|
+
if (!search._hasSearchWidget || searchReceived) {
|
|
56
|
+
resolve();
|
|
57
|
+
}
|
|
58
|
+
});
|
|
85
59
|
});
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
var
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
60
|
+
};
|
|
61
|
+
var injectInitialResults = function injectInitialResults() {
|
|
62
|
+
var options = {
|
|
63
|
+
inserted: false
|
|
64
|
+
};
|
|
65
|
+
var results = server.getInitialResults(search.mainIndex, requestParamsList);
|
|
66
|
+
insertHTML(createInsertHTML.createInsertHTML({
|
|
67
|
+
options: options,
|
|
68
|
+
results: results,
|
|
69
|
+
nonce: nonce
|
|
70
|
+
}));
|
|
71
|
+
};
|
|
72
|
+
if ((waitForResultsRef === null || waitForResultsRef === void 0 ? void 0 : waitForResultsRef.current) === null) {
|
|
73
|
+
waitForResultsRef.current = reactInstantsearchCore.wrapPromiseWithState(waitForResults().then(function() {
|
|
74
|
+
var shouldRefetch = false;
|
|
75
|
+
utils.walkIndex(search.mainIndex, function(index) {
|
|
76
|
+
shouldRefetch = index.getWidgets().some(function(widget) {
|
|
77
|
+
return widget.$$type === 'ais.dynamicWidgets';
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
if (shouldRefetch) {
|
|
81
|
+
var _search__resetScheduleSearch;
|
|
82
|
+
(_search__resetScheduleSearch = search._resetScheduleSearch) === null || _search__resetScheduleSearch === void 0 ? void 0 : _search__resetScheduleSearch.call(search);
|
|
83
|
+
waitForResultsRef.current = reactInstantsearchCore.wrapPromiseWithState(waitForResults().then(injectInitialResults));
|
|
84
|
+
}
|
|
85
|
+
return shouldRefetch;
|
|
86
|
+
}).then(function(shouldRefetch) {
|
|
87
|
+
if (shouldRefetch) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
injectInitialResults();
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
exports.InitializePromise = InitializePromise;
|
|
@@ -1,90 +1,81 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _object_spread = require('@swc/helpers/_/_object_spread');
|
|
4
|
+
var _object_spread_props = require('@swc/helpers/_/_object_spread_props');
|
|
5
|
+
var _object_without_properties = require('@swc/helpers/_/_object_without_properties');
|
|
6
|
+
var utils = require('instantsearch.js/cjs/lib/utils');
|
|
7
|
+
var React = require('react');
|
|
8
|
+
var reactInstantsearchCore = require('react-instantsearch-core');
|
|
9
|
+
var InitializePromise = require('./InitializePromise.js');
|
|
10
|
+
var TriggerSearch = require('./TriggerSearch.js');
|
|
11
|
+
var useDynamicRouteWarning = require('./useDynamicRouteWarning.js');
|
|
12
|
+
var useInstantSearchRouting = require('./useInstantSearchRouting.js');
|
|
13
|
+
var useNextHeaders = require('./useNextHeaders.js');
|
|
2
14
|
|
|
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); }
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.InstantSearchNext = InstantSearchNext;
|
|
8
|
-
exports.createInstantSearchNextInstance = createInstantSearchNextInstance;
|
|
9
|
-
var _utils = require("instantsearch.js/cjs/lib/utils");
|
|
10
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
-
var _reactInstantsearchCore = require("react-instantsearch-core");
|
|
12
|
-
var _InitializePromise = require("./InitializePromise");
|
|
13
|
-
var _TriggerSearch = require("./TriggerSearch");
|
|
14
|
-
var _useDynamicRouteWarning = require("./useDynamicRouteWarning");
|
|
15
|
-
var _useInstantSearchRouting = require("./useInstantSearchRouting");
|
|
16
|
-
var _useNextHeaders = require("./useNextHeaders");
|
|
17
|
-
var _warn = require("./warn");
|
|
18
|
-
var _excluded = ["children", "routing", "instance", "ignoreMultipleHooksWarning"];
|
|
19
|
-
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
20
|
-
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
21
|
-
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
22
|
-
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
23
15
|
var InstantSearchInitialResults = Symbol.for('InstantSearchInitialResults');
|
|
24
16
|
function createInstantSearchNextInstance() {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
17
|
+
return {
|
|
18
|
+
current: null
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function InstantSearchNext(_0) {
|
|
22
|
+
var children = _0.children, passedRouting = _0.routing, instance = _0.instance, _0_ignoreMultipleHooksWarning = _0.ignoreMultipleHooksWarning, ignoreMultipleHooksWarning = _0_ignoreMultipleHooksWarning === void 0 ? false : _0_ignoreMultipleHooksWarning, instantSearchProps = _object_without_properties._(_0, [
|
|
23
|
+
"children",
|
|
24
|
+
"routing",
|
|
25
|
+
"instance",
|
|
26
|
+
"ignoreMultipleHooksWarning"
|
|
27
|
+
]);
|
|
28
|
+
var isMounting = React.useRef(true);
|
|
29
|
+
var isServer = typeof window === 'undefined';
|
|
30
|
+
React.useEffect(function() {
|
|
31
|
+
isMounting.current = false;
|
|
32
|
+
}, []);
|
|
33
|
+
var headers = useNextHeaders.useNextHeaders();
|
|
34
|
+
var nonce = utils.safelyRunOnBrowser(function() {
|
|
35
|
+
return undefined;
|
|
36
|
+
}, {
|
|
37
|
+
fallback: function fallback() {
|
|
38
|
+
return (headers === null || headers === void 0 ? void 0 : headers.get('x-nonce')) || undefined;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
useDynamicRouteWarning.useDynamicRouteWarning({
|
|
42
|
+
isServer: isServer,
|
|
43
|
+
isMounting: isMounting,
|
|
44
|
+
instance: instance
|
|
45
|
+
});
|
|
46
|
+
var routing = useInstantSearchRouting.useInstantSearchRouting(passedRouting, isMounting);
|
|
47
|
+
return /*#__PURE__*/ React.createElement(ServerOrHydrationProvider, {
|
|
48
|
+
isServer: isServer,
|
|
49
|
+
instance: instance,
|
|
50
|
+
ignoreMultipleHooksWarning: ignoreMultipleHooksWarning
|
|
51
|
+
}, /*#__PURE__*/ React.createElement(reactInstantsearchCore.InstantSearch, _object_spread_props._(_object_spread._({}, instantSearchProps), {
|
|
52
|
+
routing: routing
|
|
53
|
+
}), isServer && /*#__PURE__*/ React.createElement(InitializePromise.InitializePromise, {
|
|
54
|
+
nonce: nonce
|
|
55
|
+
}), children, isServer && /*#__PURE__*/ React.createElement(TriggerSearch.TriggerSearch, {
|
|
56
|
+
nonce: nonce
|
|
57
|
+
})));
|
|
28
58
|
}
|
|
29
|
-
function
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
(0, _useDynamicRouteWarning.useDynamicRouteWarning)({
|
|
50
|
-
isServer: isServer,
|
|
51
|
-
isMounting: isMounting,
|
|
52
|
-
instance: instance
|
|
53
|
-
});
|
|
54
|
-
var routing = (0, _useInstantSearchRouting.useInstantSearchRouting)(passedRouting, isMounting);
|
|
55
|
-
process.env.NODE_ENV === 'development' ? (0, _warn.warn)(false, "InstantSearchNext relies on experimental APIs and may break in the future.\nThis message will only be displayed in development mode.") : void 0;
|
|
56
|
-
return /*#__PURE__*/_react.default.createElement(ServerOrHydrationProvider, {
|
|
57
|
-
isServer: isServer,
|
|
58
|
-
instance: instance,
|
|
59
|
-
ignoreMultipleHooksWarning: ignoreMultipleHooksWarning
|
|
60
|
-
}, /*#__PURE__*/_react.default.createElement(_reactInstantsearchCore.InstantSearch, _extends({}, instantSearchProps, {
|
|
61
|
-
routing: routing
|
|
62
|
-
}), isServer && /*#__PURE__*/_react.default.createElement(_InitializePromise.InitializePromise, {
|
|
63
|
-
nonce: nonce
|
|
64
|
-
}), children, isServer && /*#__PURE__*/_react.default.createElement(_TriggerSearch.TriggerSearch, {
|
|
65
|
-
nonce: nonce
|
|
66
|
-
})));
|
|
59
|
+
function ServerOrHydrationProvider(param) {
|
|
60
|
+
var isServer = param.isServer, children = param.children, instance = param.instance, ignoreMultipleHooksWarning = param.ignoreMultipleHooksWarning;
|
|
61
|
+
var promiseRef = React.useRef(null);
|
|
62
|
+
var countRef = React.useRef(0);
|
|
63
|
+
var initialResults = utils.safelyRunOnBrowser(function() {
|
|
64
|
+
return window[InstantSearchInitialResults];
|
|
65
|
+
});
|
|
66
|
+
return /*#__PURE__*/ React.createElement(reactInstantsearchCore.InstantSearchRSCContext.Provider, {
|
|
67
|
+
value: {
|
|
68
|
+
waitForResultsRef: promiseRef,
|
|
69
|
+
countRef: countRef,
|
|
70
|
+
ignoreMultipleHooksWarning: ignoreMultipleHooksWarning
|
|
71
|
+
}
|
|
72
|
+
}, /*#__PURE__*/ React.createElement(reactInstantsearchCore.InstantSearchSSRContext.Provider, {
|
|
73
|
+
value: {
|
|
74
|
+
initialResults: initialResults,
|
|
75
|
+
ssrSearchRef: isServer ? undefined : instance
|
|
76
|
+
}
|
|
77
|
+
}, children));
|
|
67
78
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
instance = _ref2.instance,
|
|
72
|
-
ignoreMultipleHooksWarning = _ref2.ignoreMultipleHooksWarning;
|
|
73
|
-
var promiseRef = (0, _react.useRef)(null);
|
|
74
|
-
var countRef = (0, _react.useRef)(0);
|
|
75
|
-
var initialResults = (0, _utils.safelyRunOnBrowser)(function () {
|
|
76
|
-
return window[InstantSearchInitialResults];
|
|
77
|
-
});
|
|
78
|
-
return /*#__PURE__*/_react.default.createElement(_reactInstantsearchCore.InstantSearchRSCContext.Provider, {
|
|
79
|
-
value: {
|
|
80
|
-
waitForResultsRef: promiseRef,
|
|
81
|
-
countRef: countRef,
|
|
82
|
-
ignoreMultipleHooksWarning: ignoreMultipleHooksWarning
|
|
83
|
-
}
|
|
84
|
-
}, /*#__PURE__*/_react.default.createElement(_reactInstantsearchCore.InstantSearchSSRContext.Provider, {
|
|
85
|
-
value: {
|
|
86
|
-
initialResults: initialResults,
|
|
87
|
-
ssrSearchRef: isServer ? undefined : instance
|
|
88
|
-
}
|
|
89
|
-
}, children));
|
|
90
|
-
}
|
|
79
|
+
|
|
80
|
+
exports.InstantSearchNext = InstantSearchNext;
|
|
81
|
+
exports.createInstantSearchNextInstance = createInstantSearchNextInstance;
|
|
@@ -1,46 +1,43 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var _navigation = require("next/navigation");
|
|
8
|
-
var _react = require("react");
|
|
9
|
-
var _reactInstantsearchCore = require("react-instantsearch-core");
|
|
10
|
-
var _createInsertHTML = require("./createInsertHTML");
|
|
11
|
-
function TriggerSearch(_ref) {
|
|
12
|
-
var _waitForResultsRef$cu;
|
|
13
|
-
var nonce = _ref.nonce;
|
|
14
|
-
var instantsearch = (0, _reactInstantsearchCore.useInstantSearchContext)();
|
|
15
|
-
var _useRSCContext = (0, _reactInstantsearchCore.useRSCContext)(),
|
|
16
|
-
waitForResultsRef = _useRSCContext.waitForResultsRef;
|
|
17
|
-
var insertHTML = (0, _react.useContext)(_navigation.ServerInsertedHTMLContext) || function () {
|
|
18
|
-
throw new Error('Missing ServerInsertedHTMLContext');
|
|
19
|
-
};
|
|
20
|
-
if ((waitForResultsRef === null || waitForResultsRef === void 0 ? void 0 : (_waitForResultsRef$cu = waitForResultsRef.current) === null || _waitForResultsRef$cu === void 0 ? void 0 : _waitForResultsRef$cu.status) === 'pending') {
|
|
21
|
-
var _instantsearch$mainHe3;
|
|
22
|
-
if (instantsearch._hasSearchWidget) {
|
|
23
|
-
if (instantsearch.compositionID) {
|
|
24
|
-
var _instantsearch$mainHe;
|
|
25
|
-
(_instantsearch$mainHe = instantsearch.mainHelper) === null || _instantsearch$mainHe === void 0 ? void 0 : _instantsearch$mainHe.searchWithComposition();
|
|
26
|
-
} else {
|
|
27
|
-
var _instantsearch$mainHe2;
|
|
28
|
-
(_instantsearch$mainHe2 = instantsearch.mainHelper) === null || _instantsearch$mainHe2 === void 0 ? void 0 : _instantsearch$mainHe2.searchOnlyWithDerivedHelpers();
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
instantsearch._hasRecommendWidget && ((_instantsearch$mainHe3 = instantsearch.mainHelper) === null || _instantsearch$mainHe3 === void 0 ? void 0 : _instantsearch$mainHe3.recommend());
|
|
3
|
+
var navigation = require('next/navigation');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var reactInstantsearchCore = require('react-instantsearch-core');
|
|
6
|
+
var createInsertHTML = require('./createInsertHTML.js');
|
|
32
7
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
8
|
+
function TriggerSearch(param) {
|
|
9
|
+
var nonce = param.nonce;
|
|
10
|
+
var _waitForResultsRef_current;
|
|
11
|
+
var instantsearch = reactInstantsearchCore.useInstantSearchContext();
|
|
12
|
+
var waitForResultsRef = reactInstantsearchCore.useRSCContext().waitForResultsRef;
|
|
13
|
+
var insertHTML = React.useContext(navigation.ServerInsertedHTMLContext) || function() {
|
|
14
|
+
throw new Error('Missing ServerInsertedHTMLContext');
|
|
15
|
+
};
|
|
16
|
+
if ((waitForResultsRef === null || waitForResultsRef === void 0 ? void 0 : (_waitForResultsRef_current = waitForResultsRef.current) === null || _waitForResultsRef_current === void 0 ? void 0 : _waitForResultsRef_current.status) === 'pending') {
|
|
17
|
+
var _instantsearch_mainHelper;
|
|
18
|
+
if (instantsearch._hasSearchWidget) {
|
|
19
|
+
if (instantsearch.compositionID) {
|
|
20
|
+
var _instantsearch_mainHelper1;
|
|
21
|
+
(_instantsearch_mainHelper1 = instantsearch.mainHelper) === null || _instantsearch_mainHelper1 === void 0 ? void 0 : _instantsearch_mainHelper1.searchWithComposition();
|
|
22
|
+
} else {
|
|
23
|
+
var _instantsearch_mainHelper2;
|
|
24
|
+
(_instantsearch_mainHelper2 = instantsearch.mainHelper) === null || _instantsearch_mainHelper2 === void 0 ? void 0 : _instantsearch_mainHelper2.searchOnlyWithDerivedHelpers();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
instantsearch._hasRecommendWidget && ((_instantsearch_mainHelper = instantsearch.mainHelper) === null || _instantsearch_mainHelper === void 0 ? void 0 : _instantsearch_mainHelper.recommend());
|
|
28
|
+
// If there are no widgets, we inject empty initial results instantly
|
|
29
|
+
if (!instantsearch._hasSearchWidget && !instantsearch._hasRecommendWidget) {
|
|
30
|
+
var options = {
|
|
31
|
+
inserted: false
|
|
32
|
+
};
|
|
33
|
+
insertHTML(createInsertHTML.createInsertHTML({
|
|
34
|
+
options: options,
|
|
35
|
+
results: {},
|
|
36
|
+
nonce: nonce
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
43
39
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
exports.TriggerSearch = TriggerSearch;
|
|
@@ -1,26 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
};
|
|
26
|
-
};
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var htmlEscape = require('./htmlEscape.js');
|
|
5
|
+
|
|
6
|
+
var createInsertHTML = function createInsertHTML(param) {
|
|
7
|
+
var options = param.options, results = param.results, nonce = param.nonce;
|
|
8
|
+
return function() {
|
|
9
|
+
if (options.inserted) {
|
|
10
|
+
return /*#__PURE__*/ React.createElement(React.Fragment, null);
|
|
11
|
+
}
|
|
12
|
+
options.inserted = true;
|
|
13
|
+
return /*#__PURE__*/ React.createElement("script", {
|
|
14
|
+
nonce: nonce,
|
|
15
|
+
dangerouslySetInnerHTML: {
|
|
16
|
+
__html: 'window[Symbol.for("InstantSearchInitialResults")] = '.concat(htmlEscape.htmlEscapeJsonString(JSON.stringify(results)))
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
exports.createInsertHTML = createInsertHTML;
|
package/dist/cjs/htmlEscape.js
CHANGED
|
@@ -1,26 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.ESCAPE_REGEX = void 0;
|
|
7
|
-
exports.htmlEscapeJsonString = htmlEscapeJsonString;
|
|
8
3
|
// This file was taken from the Next.js repo : https://github.com/vercel/next.js/blob/754fadacf30c145009506662bfbd2a4ccebb377d/packages/next/src/server/htmlescape.ts
|
|
9
4
|
// License: https://github.com/vercel/next.js/blob/754fadacf30c145009506662bfbd2a4ccebb377d/license.md
|
|
10
|
-
|
|
11
5
|
// This utility is based on https://github.com/zertosh/htmlescape
|
|
12
6
|
// License: https://github.com/zertosh/htmlescape/blob/0527ca7156a524d256101bb310a9f970f63078ad/LICENSE
|
|
13
|
-
|
|
14
7
|
var ESCAPE_LOOKUP = {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
8
|
+
'&': '\\u0026',
|
|
9
|
+
'>': '\\u003e',
|
|
10
|
+
'<': '\\u003c',
|
|
11
|
+
'\u2028': '\\u2028',
|
|
12
|
+
'\u2029': '\\u2029'
|
|
20
13
|
};
|
|
21
|
-
var ESCAPE_REGEX =
|
|
14
|
+
var ESCAPE_REGEX = /[&><\u2028\u2029]/g;
|
|
22
15
|
function htmlEscapeJsonString(str) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
16
|
+
return str.replace(ESCAPE_REGEX, function(match) {
|
|
17
|
+
return ESCAPE_LOOKUP[match];
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
exports.ESCAPE_REGEX = ESCAPE_REGEX;
|
|
22
|
+
exports.htmlEscapeJsonString = htmlEscapeJsonString;
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (key in exports && exports[key] === _InstantSearchNext[key]) return;
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function get() {
|
|
13
|
-
return _InstantSearchNext[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
3
|
+
var InstantSearchNext = require('./InstantSearchNext.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
exports.InstantSearchNext = InstantSearchNext.InstantSearchNext;
|
|
8
|
+
exports.createInstantSearchNextInstance = InstantSearchNext.createInstantSearchNextInstance;
|
package/dist/cjs/package.json
CHANGED