react-instantsearch-nextjs 0.3.21 → 0.4.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/InitializePromise.js +28 -20
- package/dist/cjs/InstantSearchNext.js +6 -5
- package/dist/cjs/TriggerSearch.js +11 -3
- package/dist/cjs/htmlEscape.js +1 -2
- package/dist/cjs/useInstantSearchRouting.js +12 -10
- package/dist/cjs/useNextHeaders.js +25 -0
- package/dist/cjs/warn.js +1 -2
- package/dist/es/InitializePromise.js +26 -18
- package/dist/es/InstantSearchNext.d.ts +2 -1
- package/dist/es/InstantSearchNext.js +3 -2
- package/dist/es/TriggerSearch.js +11 -3
- package/dist/es/useInstantSearchRouting.d.ts +1 -1
- package/dist/es/useInstantSearchRouting.js +12 -10
- package/dist/es/useNextHeaders.d.ts +4 -0
- package/dist/es/useNextHeaders.js +19 -0
- package/package.json +6 -6
|
@@ -10,22 +10,21 @@ var _navigation = require("next/navigation");
|
|
|
10
10
|
var _react = _interopRequireWildcard(require("react"));
|
|
11
11
|
var _reactInstantsearchCore = require("react-instantsearch-core");
|
|
12
12
|
var _htmlEscape = require("./htmlEscape");
|
|
13
|
-
function _getRequireWildcardCache(
|
|
14
|
-
function _interopRequireWildcard(
|
|
15
|
-
function _typeof(
|
|
16
|
-
function ownKeys(
|
|
17
|
-
function _objectSpread(
|
|
13
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
14
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
15
|
+
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); }
|
|
16
|
+
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; }
|
|
17
|
+
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; }
|
|
18
18
|
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; }
|
|
19
|
-
function _toPropertyKey(
|
|
20
|
-
function _toPrimitive(
|
|
21
|
-
var _ref2 = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null);
|
|
19
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
20
|
+
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); }
|
|
22
21
|
var createInsertHTML = function createInsertHTML(_ref) {
|
|
23
22
|
var options = _ref.options,
|
|
24
23
|
results = _ref.results,
|
|
25
24
|
nonce = _ref.nonce;
|
|
26
25
|
return function () {
|
|
27
26
|
if (options.inserted) {
|
|
28
|
-
return
|
|
27
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null);
|
|
29
28
|
}
|
|
30
29
|
options.inserted = true;
|
|
31
30
|
return /*#__PURE__*/_react.default.createElement("script", {
|
|
@@ -36,8 +35,8 @@ var createInsertHTML = function createInsertHTML(_ref) {
|
|
|
36
35
|
});
|
|
37
36
|
};
|
|
38
37
|
};
|
|
39
|
-
function InitializePromise(
|
|
40
|
-
var nonce =
|
|
38
|
+
function InitializePromise(_ref2) {
|
|
39
|
+
var nonce = _ref2.nonce;
|
|
41
40
|
var _search = (0, _reactInstantsearchCore.useInstantSearchContext)();
|
|
42
41
|
var waitForResultsRef = (0, _reactInstantsearchCore.useRSCContext)();
|
|
43
42
|
var insertHTML = (0, _react.useContext)(_navigation.ServerInsertedHTMLContext) || function () {
|
|
@@ -47,15 +46,24 @@ function InitializePromise(_ref3) {
|
|
|
47
46
|
// Extract search parameters from the search client to use them
|
|
48
47
|
// later during hydration.
|
|
49
48
|
var requestParamsList;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
if (_search.compositionID) {
|
|
50
|
+
_search.mainHelper.setClient(_objectSpread(_objectSpread({}, _search.mainHelper.getClient()), {}, {
|
|
51
|
+
search: function search(query) {
|
|
52
|
+
requestParamsList = [query.requestBody.params];
|
|
53
|
+
return _search.client.search(query);
|
|
54
|
+
}
|
|
55
|
+
}));
|
|
56
|
+
} else {
|
|
57
|
+
_search.mainHelper.setClient(_objectSpread(_objectSpread({}, _search.mainHelper.getClient()), {}, {
|
|
58
|
+
search: function search(queries) {
|
|
59
|
+
requestParamsList = queries.map(function (_ref3) {
|
|
60
|
+
var params = _ref3.params;
|
|
61
|
+
return params;
|
|
62
|
+
});
|
|
63
|
+
return _search.client.search(queries);
|
|
64
|
+
}
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
59
67
|
(0, _utils.resetWidgetId)();
|
|
60
68
|
var waitForResults = function waitForResults() {
|
|
61
69
|
return new Promise(function (resolve) {
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(
|
|
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
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.InstantSearchNext = InstantSearchNext;
|
|
8
8
|
var _utils = require("instantsearch.js/cjs/lib/utils");
|
|
9
|
-
var _headers = require("next/headers");
|
|
10
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
11
10
|
var _reactInstantsearchCore = require("react-instantsearch-core");
|
|
12
11
|
var _InitializePromise = require("./InitializePromise");
|
|
13
12
|
var _TriggerSearch = require("./TriggerSearch");
|
|
14
13
|
var _useInstantSearchRouting = require("./useInstantSearchRouting");
|
|
14
|
+
var _useNextHeaders = require("./useNextHeaders");
|
|
15
15
|
var _warn = require("./warn");
|
|
16
16
|
var _excluded = ["children", "routing"];
|
|
17
|
-
function _getRequireWildcardCache(
|
|
18
|
-
function _interopRequireWildcard(
|
|
17
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
18
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
19
19
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
20
20
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
21
21
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
@@ -48,11 +48,12 @@ function InstantSearchNext(_ref) {
|
|
|
48
48
|
delete window[InstantSearchInitialResults];
|
|
49
49
|
};
|
|
50
50
|
}, []);
|
|
51
|
+
var headers = (0, _useNextHeaders.useNextHeaders)();
|
|
51
52
|
var nonce = (0, _utils.safelyRunOnBrowser)(function () {
|
|
52
53
|
return undefined;
|
|
53
54
|
}, {
|
|
54
55
|
fallback: function fallback() {
|
|
55
|
-
return (0
|
|
56
|
+
return (headers === null || headers === void 0 ? void 0 : headers.get('x-nonce')) || undefined;
|
|
56
57
|
}
|
|
57
58
|
});
|
|
58
59
|
var routing = (0, _useInstantSearchRouting.useInstantSearchRouting)(passedRouting, isMounting);
|
|
@@ -10,9 +10,17 @@ function TriggerSearch() {
|
|
|
10
10
|
var instantsearch = (0, _reactInstantsearchCore.useInstantSearchContext)();
|
|
11
11
|
var waitForResultsRef = (0, _reactInstantsearchCore.useRSCContext)();
|
|
12
12
|
if ((waitForResultsRef === null || waitForResultsRef === void 0 ? void 0 : (_waitForResultsRef$cu = waitForResultsRef.current) === null || _waitForResultsRef$cu === void 0 ? void 0 : _waitForResultsRef$cu.status) === 'pending') {
|
|
13
|
-
var _instantsearch$
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
var _instantsearch$mainHe3;
|
|
14
|
+
if (instantsearch._hasSearchWidget) {
|
|
15
|
+
if (instantsearch.compositionID) {
|
|
16
|
+
var _instantsearch$mainHe;
|
|
17
|
+
(_instantsearch$mainHe = instantsearch.mainHelper) === null || _instantsearch$mainHe === void 0 ? void 0 : _instantsearch$mainHe.searchWithComposition();
|
|
18
|
+
} else {
|
|
19
|
+
var _instantsearch$mainHe2;
|
|
20
|
+
(_instantsearch$mainHe2 = instantsearch.mainHelper) === null || _instantsearch$mainHe2 === void 0 ? void 0 : _instantsearch$mainHe2.searchOnlyWithDerivedHelpers();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
instantsearch._hasRecommendWidget && ((_instantsearch$mainHe3 = instantsearch.mainHelper) === null || _instantsearch$mainHe3 === void 0 ? void 0 : _instantsearch$mainHe3.recommend());
|
|
16
24
|
}
|
|
17
25
|
return null;
|
|
18
26
|
}
|
package/dist/cjs/htmlEscape.js
CHANGED
|
@@ -18,8 +18,7 @@ var ESCAPE_LOOKUP = {
|
|
|
18
18
|
"\u2028": "\\u2028",
|
|
19
19
|
"\u2029": "\\u2029"
|
|
20
20
|
};
|
|
21
|
-
var ESCAPE_REGEX = /[&><\u2028\u2029]/g;
|
|
22
|
-
exports.ESCAPE_REGEX = ESCAPE_REGEX;
|
|
21
|
+
var ESCAPE_REGEX = exports.ESCAPE_REGEX = /[&><\u2028\u2029]/g;
|
|
23
22
|
function htmlEscapeJsonString(str) {
|
|
24
23
|
return str.replace(ESCAPE_REGEX, function (match) {
|
|
25
24
|
return ESCAPE_LOOKUP[match];
|
|
@@ -5,31 +5,33 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.useInstantSearchRouting = useInstantSearchRouting;
|
|
7
7
|
var _history = _interopRequireDefault(require("instantsearch.js/cjs/lib/routers/history"));
|
|
8
|
-
var _headers = require("next/headers");
|
|
9
8
|
var _navigation = require("next/navigation");
|
|
10
9
|
var _react = require("react");
|
|
10
|
+
var _useNextHeaders = require("./useNextHeaders");
|
|
11
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
-
function ownKeys(
|
|
13
|
-
function _objectSpread(
|
|
12
|
+
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; }
|
|
13
|
+
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; }
|
|
14
14
|
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; }
|
|
15
|
-
function _toPropertyKey(
|
|
16
|
-
function _toPrimitive(
|
|
17
|
-
function _typeof(
|
|
15
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
16
|
+
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); }
|
|
17
|
+
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); }
|
|
18
18
|
function useInstantSearchRouting(passedRouting, isMounting) {
|
|
19
|
+
var isServer = typeof window === 'undefined';
|
|
19
20
|
var pathname = (0, _navigation.usePathname)();
|
|
20
21
|
var searchParams = (0, _navigation.useSearchParams)();
|
|
21
|
-
var routingRef = (0, _react.useRef)();
|
|
22
|
-
var onUpdateRef = (0, _react.useRef)();
|
|
22
|
+
var routingRef = (0, _react.useRef)(null);
|
|
23
|
+
var onUpdateRef = (0, _react.useRef)(null);
|
|
23
24
|
(0, _react.useEffect)(function () {
|
|
24
25
|
if (onUpdateRef.current) {
|
|
25
26
|
onUpdateRef.current();
|
|
26
27
|
}
|
|
27
28
|
}, [pathname, searchParams]);
|
|
29
|
+
var headers = (0, _useNextHeaders.useNextHeaders)();
|
|
28
30
|
if (passedRouting && !routingRef.current) {
|
|
29
31
|
var browserHistoryOptions = {};
|
|
30
32
|
browserHistoryOptions.getLocation = function () {
|
|
31
|
-
if (
|
|
32
|
-
var url = "".concat((0
|
|
33
|
+
if (isServer) {
|
|
34
|
+
var url = "".concat((headers === null || headers === void 0 ? void 0 : headers.get('x-forwarded-proto')) || 'http', "://").concat(headers === null || headers === void 0 ? void 0 : headers.get('host')).concat(pathname, "?").concat(searchParams);
|
|
33
35
|
return new URL(url);
|
|
34
36
|
}
|
|
35
37
|
if (isMounting.current) {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useNextHeaders = void 0;
|
|
7
|
+
var _headers = require("next/headers");
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
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); }
|
|
10
|
+
function isPromise(obj) {
|
|
11
|
+
return obj && (_typeof(obj) === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
|
|
12
|
+
}
|
|
13
|
+
var useNextHeaders = exports.useNextHeaders = function useNextHeaders() {
|
|
14
|
+
var isServer = typeof window === 'undefined';
|
|
15
|
+
var h;
|
|
16
|
+
if (isServer) {
|
|
17
|
+
var nextHeaders = (0, _headers.headers)();
|
|
18
|
+
if (isPromise((0, _headers.headers)())) {
|
|
19
|
+
h = (0, _react.use)(nextHeaders);
|
|
20
|
+
} else {
|
|
21
|
+
h = nextHeaders; // assert that headers come from the synchronous nextjs function
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return h;
|
|
25
|
+
};
|
package/dist/cjs/warn.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.warn = warn;
|
|
|
7
7
|
exports.warnCache = void 0;
|
|
8
8
|
/* eslint-disable no-console, no-empty */
|
|
9
9
|
|
|
10
|
-
var warnCache = {
|
|
10
|
+
var warnCache = exports.warnCache = {
|
|
11
11
|
current: {}
|
|
12
12
|
};
|
|
13
13
|
|
|
@@ -15,7 +15,6 @@ var warnCache = {
|
|
|
15
15
|
* Logs a warning if the condition is not met.
|
|
16
16
|
* This is used to log issues in development environment only.
|
|
17
17
|
*/
|
|
18
|
-
exports.warnCache = warnCache;
|
|
19
18
|
function warn(condition, message) {
|
|
20
19
|
if (!(process.env.NODE_ENV === 'development')) {
|
|
21
20
|
return;
|
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
function _typeof(
|
|
2
|
-
function ownKeys(
|
|
3
|
-
function _objectSpread(
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
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; }
|
|
3
|
+
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; }
|
|
4
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(
|
|
6
|
-
function _toPrimitive(
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
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); }
|
|
7
7
|
import { getInitialResults } from "instantsearch.js/es/lib/server.js";
|
|
8
8
|
import { resetWidgetId, walkIndex } from "instantsearch.js/es/lib/utils/index.js";
|
|
9
9
|
import { ServerInsertedHTMLContext } from "next/navigation.js";
|
|
10
10
|
import React, { useContext } from 'react';
|
|
11
11
|
import { useInstantSearchContext, useRSCContext, wrapPromiseWithState } from 'react-instantsearch-core';
|
|
12
12
|
import { htmlEscapeJsonString } from "./htmlEscape.js";
|
|
13
|
-
var _ref2 = /*#__PURE__*/React.createElement(React.Fragment, null);
|
|
14
13
|
var createInsertHTML = function createInsertHTML(_ref) {
|
|
15
14
|
var options = _ref.options,
|
|
16
15
|
results = _ref.results,
|
|
17
16
|
nonce = _ref.nonce;
|
|
18
17
|
return function () {
|
|
19
18
|
if (options.inserted) {
|
|
20
|
-
return
|
|
19
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null);
|
|
21
20
|
}
|
|
22
21
|
options.inserted = true;
|
|
23
22
|
return /*#__PURE__*/React.createElement("script", {
|
|
@@ -28,8 +27,8 @@ var createInsertHTML = function createInsertHTML(_ref) {
|
|
|
28
27
|
});
|
|
29
28
|
};
|
|
30
29
|
};
|
|
31
|
-
export function InitializePromise(
|
|
32
|
-
var nonce =
|
|
30
|
+
export function InitializePromise(_ref2) {
|
|
31
|
+
var nonce = _ref2.nonce;
|
|
33
32
|
var _search = useInstantSearchContext();
|
|
34
33
|
var waitForResultsRef = useRSCContext();
|
|
35
34
|
var insertHTML = useContext(ServerInsertedHTMLContext) || function () {
|
|
@@ -39,15 +38,24 @@ export function InitializePromise(_ref3) {
|
|
|
39
38
|
// Extract search parameters from the search client to use them
|
|
40
39
|
// later during hydration.
|
|
41
40
|
var requestParamsList;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
41
|
+
if (_search.compositionID) {
|
|
42
|
+
_search.mainHelper.setClient(_objectSpread(_objectSpread({}, _search.mainHelper.getClient()), {}, {
|
|
43
|
+
search: function search(query) {
|
|
44
|
+
requestParamsList = [query.requestBody.params];
|
|
45
|
+
return _search.client.search(query);
|
|
46
|
+
}
|
|
47
|
+
}));
|
|
48
|
+
} else {
|
|
49
|
+
_search.mainHelper.setClient(_objectSpread(_objectSpread({}, _search.mainHelper.getClient()), {}, {
|
|
50
|
+
search: function search(queries) {
|
|
51
|
+
requestParamsList = queries.map(function (_ref3) {
|
|
52
|
+
var params = _ref3.params;
|
|
53
|
+
return params;
|
|
54
|
+
});
|
|
55
|
+
return _search.client.search(queries);
|
|
56
|
+
}
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
51
59
|
resetWidgetId();
|
|
52
60
|
var waitForResults = function waitForResults() {
|
|
53
61
|
return new Promise(function (resolve) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
import type { InitialResults, StateMapping, UiState } from 'instantsearch.js';
|
|
2
3
|
import type { BrowserHistoryArgs } from 'instantsearch.js/es/lib/routers/history';
|
|
3
4
|
import type { InstantSearchProps } from 'react-instantsearch-core';
|
|
@@ -14,5 +15,5 @@ export type InstantSearchNextRouting<TUiState, TRouteState> = {
|
|
|
14
15
|
export type InstantSearchNextProps<TUiState extends UiState = UiState, TRouteState = TUiState> = Omit<InstantSearchProps<TUiState, TRouteState>, 'routing'> & {
|
|
15
16
|
routing?: InstantSearchNextRouting<TUiState, TRouteState> | boolean;
|
|
16
17
|
};
|
|
17
|
-
export declare function InstantSearchNext<TUiState extends UiState = UiState, TRouteState = TUiState>({ children, routing: passedRouting, ...instantSearchProps }: InstantSearchNextProps<TUiState, TRouteState>): JSX.Element;
|
|
18
|
+
export declare function InstantSearchNext<TUiState extends UiState = UiState, TRouteState = TUiState>({ children, routing: passedRouting, ...instantSearchProps }: InstantSearchNextProps<TUiState, TRouteState>): React.JSX.Element;
|
|
18
19
|
export {};
|
|
@@ -3,12 +3,12 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
|
3
3
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
4
4
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
5
5
|
import { safelyRunOnBrowser } from "instantsearch.js/es/lib/utils/index.js";
|
|
6
|
-
import { headers } from "next/headers.js";
|
|
7
6
|
import React, { useEffect, useMemo, useRef } from 'react';
|
|
8
7
|
import { InstantSearch, InstantSearchRSCContext, InstantSearchSSRProvider } from 'react-instantsearch-core';
|
|
9
8
|
import { InitializePromise } from "./InitializePromise.js";
|
|
10
9
|
import { TriggerSearch } from "./TriggerSearch.js";
|
|
11
10
|
import { useInstantSearchRouting } from "./useInstantSearchRouting.js";
|
|
11
|
+
import { useNextHeaders } from "./useNextHeaders.js";
|
|
12
12
|
import { warn } from "./warn.js";
|
|
13
13
|
var InstantSearchInitialResults = Symbol.for('InstantSearchInitialResults');
|
|
14
14
|
var _ref2 = /*#__PURE__*/React.createElement(TriggerSearch, null);
|
|
@@ -39,11 +39,12 @@ export function InstantSearchNext(_ref) {
|
|
|
39
39
|
delete window[InstantSearchInitialResults];
|
|
40
40
|
};
|
|
41
41
|
}, []);
|
|
42
|
+
var headers = useNextHeaders();
|
|
42
43
|
var nonce = safelyRunOnBrowser(function () {
|
|
43
44
|
return undefined;
|
|
44
45
|
}, {
|
|
45
46
|
fallback: function fallback() {
|
|
46
|
-
return headers
|
|
47
|
+
return (headers === null || headers === void 0 ? void 0 : headers.get('x-nonce')) || undefined;
|
|
47
48
|
}
|
|
48
49
|
});
|
|
49
50
|
var routing = useInstantSearchRouting(passedRouting, isMounting);
|
package/dist/es/TriggerSearch.js
CHANGED
|
@@ -4,9 +4,17 @@ export function TriggerSearch() {
|
|
|
4
4
|
var instantsearch = useInstantSearchContext();
|
|
5
5
|
var waitForResultsRef = useRSCContext();
|
|
6
6
|
if ((waitForResultsRef === null || waitForResultsRef === void 0 ? void 0 : (_waitForResultsRef$cu = waitForResultsRef.current) === null || _waitForResultsRef$cu === void 0 ? void 0 : _waitForResultsRef$cu.status) === 'pending') {
|
|
7
|
-
var _instantsearch$
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
var _instantsearch$mainHe3;
|
|
8
|
+
if (instantsearch._hasSearchWidget) {
|
|
9
|
+
if (instantsearch.compositionID) {
|
|
10
|
+
var _instantsearch$mainHe;
|
|
11
|
+
(_instantsearch$mainHe = instantsearch.mainHelper) === null || _instantsearch$mainHe === void 0 ? void 0 : _instantsearch$mainHe.searchWithComposition();
|
|
12
|
+
} else {
|
|
13
|
+
var _instantsearch$mainHe2;
|
|
14
|
+
(_instantsearch$mainHe2 = instantsearch.mainHelper) === null || _instantsearch$mainHe2 === void 0 ? void 0 : _instantsearch$mainHe2.searchOnlyWithDerivedHelpers();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
instantsearch._hasRecommendWidget && ((_instantsearch$mainHe3 = instantsearch.mainHelper) === null || _instantsearch$mainHe3 === void 0 ? void 0 : _instantsearch$mainHe3.recommend());
|
|
10
18
|
}
|
|
11
19
|
return null;
|
|
12
20
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { InstantSearchNextProps } from './InstantSearchNext';
|
|
2
2
|
import type { UiState } from 'instantsearch.js';
|
|
3
|
-
export declare function useInstantSearchRouting<TUiState extends UiState = UiState, TRouteState = TUiState>(passedRouting: InstantSearchNextProps<TUiState, TRouteState>['routing'], isMounting: React.
|
|
3
|
+
export declare function useInstantSearchRouting<TUiState extends UiState = UiState, TRouteState = TUiState>(passedRouting: InstantSearchNextProps<TUiState, TRouteState>['routing'], isMounting: React.RefObject<boolean>): boolean | import("instantsearch.js/es/middlewares").RouterProps<TUiState, TRouteState> | null | undefined;
|
|
@@ -1,28 +1,30 @@
|
|
|
1
|
-
function ownKeys(
|
|
2
|
-
function _objectSpread(
|
|
1
|
+
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; }
|
|
2
|
+
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; }
|
|
3
3
|
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; }
|
|
4
|
-
function _toPropertyKey(
|
|
5
|
-
function _toPrimitive(
|
|
6
|
-
function _typeof(
|
|
4
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
5
|
+
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); }
|
|
6
|
+
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); }
|
|
7
7
|
import historyRouter from "instantsearch.js/es/lib/routers/history.js";
|
|
8
|
-
import { headers } from "next/headers.js";
|
|
9
8
|
import { usePathname, useSearchParams } from "next/navigation.js";
|
|
10
9
|
import { useRef, useEffect } from 'react';
|
|
10
|
+
import { useNextHeaders } from "./useNextHeaders.js";
|
|
11
11
|
export function useInstantSearchRouting(passedRouting, isMounting) {
|
|
12
|
+
var isServer = typeof window === 'undefined';
|
|
12
13
|
var pathname = usePathname();
|
|
13
14
|
var searchParams = useSearchParams();
|
|
14
|
-
var routingRef = useRef();
|
|
15
|
-
var onUpdateRef = useRef();
|
|
15
|
+
var routingRef = useRef(null);
|
|
16
|
+
var onUpdateRef = useRef(null);
|
|
16
17
|
useEffect(function () {
|
|
17
18
|
if (onUpdateRef.current) {
|
|
18
19
|
onUpdateRef.current();
|
|
19
20
|
}
|
|
20
21
|
}, [pathname, searchParams]);
|
|
22
|
+
var headers = useNextHeaders();
|
|
21
23
|
if (passedRouting && !routingRef.current) {
|
|
22
24
|
var browserHistoryOptions = {};
|
|
23
25
|
browserHistoryOptions.getLocation = function () {
|
|
24
|
-
if (
|
|
25
|
-
var url = "".concat(headers
|
|
26
|
+
if (isServer) {
|
|
27
|
+
var url = "".concat((headers === null || headers === void 0 ? void 0 : headers.get('x-forwarded-proto')) || 'http', "://").concat(headers === null || headers === void 0 ? void 0 : headers.get('host')).concat(pathname, "?").concat(searchParams);
|
|
26
28
|
return new URL(url);
|
|
27
29
|
}
|
|
28
30
|
if (isMounting.current) {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
import { headers } from "next/headers.js";
|
|
3
|
+
import { use } from 'react';
|
|
4
|
+
function isPromise(obj) {
|
|
5
|
+
return obj && (_typeof(obj) === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
|
|
6
|
+
}
|
|
7
|
+
export var useNextHeaders = function useNextHeaders() {
|
|
8
|
+
var isServer = typeof window === 'undefined';
|
|
9
|
+
var h;
|
|
10
|
+
if (isServer) {
|
|
11
|
+
var nextHeaders = headers();
|
|
12
|
+
if (isPromise(headers())) {
|
|
13
|
+
h = use(nextHeaders);
|
|
14
|
+
} else {
|
|
15
|
+
h = nextHeaders; // assert that headers come from the synchronous nextjs function
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return h;
|
|
19
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-instantsearch-nextjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "React InstantSearch SSR utilities for Next.js",
|
|
5
5
|
"types": "dist/es/index.d.ts",
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
@@ -49,13 +49,13 @@
|
|
|
49
49
|
"watch:es": "yarn --silent build:es:base --watch"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"instantsearch.js": "4.
|
|
53
|
-
"next": "
|
|
54
|
-
"react-instantsearch-core": "7.
|
|
52
|
+
"instantsearch.js": "4.76.0",
|
|
53
|
+
"next": "15.1.4",
|
|
54
|
+
"react-instantsearch-core": "7.14.0"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"next": ">= 13.4 <
|
|
57
|
+
"next": ">= 13.4 < 16",
|
|
58
58
|
"react-instantsearch": ">= 7.1.0 < 8"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "8e30cd5859416a1c29e2030a69d52b601fc91fab"
|
|
61
61
|
}
|