react-instantsearch-nextjs 1.0.16 → 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/dist/cjs/InitializePromise.js +92 -97
- package/dist/cjs/InstantSearchNext.js +76 -83
- 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 -75
- 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 +9 -9
- package/dist/cjs/warn.js +0 -40
- package/dist/es/warn.js +0 -33
|
@@ -1,67 +1,64 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _object_spread = require('@swc/helpers/_/_object_spread');
|
|
4
|
+
var _type_of = require('@swc/helpers/_/_type_of');
|
|
5
|
+
var historyRouter = require('instantsearch.js/cjs/lib/routers/history');
|
|
6
|
+
var navigation = require('next/navigation');
|
|
7
|
+
var React = require('react');
|
|
8
|
+
var useNextHeaders = require('./useNextHeaders.js');
|
|
2
9
|
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useInstantSearchRouting = useInstantSearchRouting;
|
|
7
|
-
var _history = _interopRequireDefault(require("instantsearch.js/cjs/lib/routers/history"));
|
|
8
|
-
var _navigation = require("next/navigation");
|
|
9
|
-
var _react = require("react");
|
|
10
|
-
var _useNextHeaders = require("./useNextHeaders");
|
|
11
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
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
|
-
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; }
|
|
15
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : 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
10
|
function useInstantSearchRouting(passedRouting, isMounting) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
var
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
11
|
+
var isServer = typeof window === 'undefined';
|
|
12
|
+
var pathname = navigation.usePathname();
|
|
13
|
+
var searchParams = navigation.useSearchParams();
|
|
14
|
+
var routingRef = React.useRef(null);
|
|
15
|
+
var onUpdateRef = React.useRef(null);
|
|
16
|
+
var isUnmounting = React.useRef(false);
|
|
17
|
+
React.useEffect(function() {
|
|
18
|
+
if (onUpdateRef.current) {
|
|
19
|
+
onUpdateRef.current();
|
|
20
|
+
}
|
|
21
|
+
}, [
|
|
22
|
+
pathname,
|
|
23
|
+
searchParams
|
|
24
|
+
]);
|
|
25
|
+
React.useEffect(function() {
|
|
26
|
+
isUnmounting.current = false;
|
|
27
|
+
return function() {
|
|
28
|
+
isUnmounting.current = true;
|
|
29
|
+
};
|
|
30
|
+
});
|
|
31
|
+
var headers = useNextHeaders.useNextHeaders();
|
|
32
|
+
if (passedRouting && !routingRef.current) {
|
|
33
|
+
var browserHistoryOptions = {};
|
|
34
|
+
browserHistoryOptions.getLocation = function() {
|
|
35
|
+
if (isServer) {
|
|
36
|
+
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);
|
|
37
|
+
return new URL(url);
|
|
38
|
+
}
|
|
39
|
+
if (isMounting.current) {
|
|
40
|
+
return new URL("".concat(window.location.protocol, "//").concat(window.location.host).concat(pathname, "?").concat(searchParams));
|
|
41
|
+
}
|
|
42
|
+
return window.location;
|
|
43
|
+
};
|
|
44
|
+
browserHistoryOptions.push = function push(url) {
|
|
45
|
+
// This is to skip the push with empty routeState on dispose as it would clear params set on a <Link>
|
|
46
|
+
if (this.isDisposed && isUnmounting.current) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
history.pushState({}, '', url);
|
|
50
|
+
};
|
|
51
|
+
browserHistoryOptions.start = function start(onUpdate) {
|
|
52
|
+
onUpdateRef.current = onUpdate;
|
|
53
|
+
};
|
|
54
|
+
routingRef.current = {};
|
|
55
|
+
if ((typeof passedRouting === "undefined" ? "undefined" : _type_of._(passedRouting)) === 'object') {
|
|
56
|
+
browserHistoryOptions = _object_spread._({}, browserHistoryOptions, passedRouting.router);
|
|
57
|
+
routingRef.current.stateMapping = passedRouting.stateMapping;
|
|
58
|
+
}
|
|
59
|
+
routingRef.current.router = historyRouter(browserHistoryOptions);
|
|
63
60
|
}
|
|
64
|
-
routingRef.current
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
return routingRef.current;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
exports.useInstantSearchRouting = useInstantSearchRouting;
|
|
@@ -1,25 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _type_of = require('@swc/helpers/_/_type_of');
|
|
4
|
+
var React = require('react');
|
|
2
5
|
|
|
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
6
|
function isPromise(obj) {
|
|
11
|
-
|
|
7
|
+
return obj !== null && ((typeof obj === "undefined" ? "undefined" : _type_of._(obj)) === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
|
|
12
8
|
}
|
|
13
|
-
var useNextHeaders =
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
} else {
|
|
21
|
-
h = nextHeaders; // assert that headers come from the synchronous nextjs function
|
|
9
|
+
var useNextHeaders = function useNextHeaders() {
|
|
10
|
+
var isServer = typeof window === 'undefined';
|
|
11
|
+
if (isServer) {
|
|
12
|
+
// Dynamic require to avoid bundling next/headers in client components
|
|
13
|
+
var nextHeadersModule = require('next/headers');
|
|
14
|
+
var nextHeaders = nextHeadersModule.headers();
|
|
15
|
+
return isPromise(nextHeaders) ? React.use(nextHeaders) : nextHeaders;
|
|
22
16
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
17
|
+
return undefined;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
exports.useNextHeaders = useNextHeaders;
|
|
@@ -1,95 +1,94 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
import { getInitialResults } from "instantsearch.js/es/lib/server.js";
|
|
8
|
-
import { resetWidgetId, walkIndex } from "instantsearch.js/es/lib/utils/index.js";
|
|
9
|
-
import { ServerInsertedHTMLContext } from "next/navigation.js";
|
|
1
|
+
import { _ as _$1 } from '@swc/helpers/cjs/_object_spread.cjs';
|
|
2
|
+
import { _ } from '@swc/helpers/cjs/_object_spread_props.cjs';
|
|
3
|
+
import { getInitialResults } from 'instantsearch.js/es/lib/server.js';
|
|
4
|
+
import { resetWidgetId, walkIndex } from 'instantsearch.js/es/lib/utils/index.js';
|
|
5
|
+
import { ServerInsertedHTMLContext } from 'next/navigation.js';
|
|
10
6
|
import { useContext } from 'react';
|
|
11
7
|
import { useInstantSearchContext, useRSCContext, wrapPromiseWithState } from 'react-instantsearch-core';
|
|
12
|
-
import { createInsertHTML } from
|
|
13
|
-
export function InitializePromise(_ref) {
|
|
14
|
-
var nonce = _ref.nonce;
|
|
15
|
-
var _search = useInstantSearchContext();
|
|
16
|
-
var _useRSCContext = useRSCContext(),
|
|
17
|
-
waitForResultsRef = _useRSCContext.waitForResultsRef;
|
|
18
|
-
var insertHTML = useContext(ServerInsertedHTMLContext) || function () {
|
|
19
|
-
throw new Error('Missing ServerInsertedHTMLContext');
|
|
20
|
-
};
|
|
8
|
+
import { createInsertHTML } from './createInsertHTML.js';
|
|
21
9
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
requestParamsList = [query.requestBody.params];
|
|
29
|
-
return _search.client.search(query);
|
|
30
|
-
}
|
|
31
|
-
}));
|
|
32
|
-
} else {
|
|
33
|
-
_search.mainHelper.setClient(_objectSpread(_objectSpread({}, _search.mainHelper.getClient()), {}, {
|
|
34
|
-
search: function search(queries) {
|
|
35
|
-
requestParamsList = queries.map(function (_ref2) {
|
|
36
|
-
var params = _ref2.params;
|
|
37
|
-
return params;
|
|
38
|
-
});
|
|
39
|
-
return _search.client.search(queries);
|
|
40
|
-
}
|
|
41
|
-
}));
|
|
42
|
-
}
|
|
43
|
-
resetWidgetId();
|
|
44
|
-
var waitForResults = function waitForResults() {
|
|
45
|
-
return new Promise(function (resolve) {
|
|
46
|
-
var searchReceived = false;
|
|
47
|
-
var recommendReceived = false;
|
|
48
|
-
_search.mainHelper.derivedHelpers[0].once('result', function () {
|
|
49
|
-
searchReceived = true;
|
|
50
|
-
if (!_search._hasRecommendWidget || recommendReceived) {
|
|
51
|
-
resolve();
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
_search.mainHelper.derivedHelpers[0].once('recommend:result', function () {
|
|
55
|
-
recommendReceived = true;
|
|
56
|
-
if (!_search._hasSearchWidget || searchReceived) {
|
|
57
|
-
resolve();
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
var injectInitialResults = function injectInitialResults() {
|
|
63
|
-
var options = {
|
|
64
|
-
inserted: false
|
|
10
|
+
function InitializePromise(param) {
|
|
11
|
+
var nonce = param.nonce;
|
|
12
|
+
var search = useInstantSearchContext();
|
|
13
|
+
var waitForResultsRef = useRSCContext().waitForResultsRef;
|
|
14
|
+
var insertHTML = useContext(ServerInsertedHTMLContext) || function() {
|
|
15
|
+
throw new Error('Missing ServerInsertedHTMLContext');
|
|
65
16
|
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
17
|
+
// Extract search parameters from the search client to use them
|
|
18
|
+
// later during hydration.
|
|
19
|
+
var requestParamsList;
|
|
20
|
+
if (search.compositionID) {
|
|
21
|
+
search.mainHelper.setClient(_(_$1({}, search.mainHelper.getClient()), {
|
|
22
|
+
search: function search1(query) {
|
|
23
|
+
requestParamsList = [
|
|
24
|
+
query.requestBody.params
|
|
25
|
+
];
|
|
26
|
+
return search.client.search(query);
|
|
27
|
+
}
|
|
28
|
+
}));
|
|
29
|
+
} else {
|
|
30
|
+
search.mainHelper.setClient(_(_$1({}, search.mainHelper.getClient()), {
|
|
31
|
+
search: function search1(queries) {
|
|
32
|
+
requestParamsList = queries.map(function(param) {
|
|
33
|
+
var params = param.params;
|
|
34
|
+
return params;
|
|
35
|
+
});
|
|
36
|
+
return search.client.search(queries);
|
|
37
|
+
}
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
resetWidgetId();
|
|
41
|
+
var waitForResults = function waitForResults() {
|
|
42
|
+
return new Promise(function(resolve) {
|
|
43
|
+
var searchReceived = false;
|
|
44
|
+
var recommendReceived = false;
|
|
45
|
+
search.mainHelper.derivedHelpers[0].once('result', function() {
|
|
46
|
+
searchReceived = true;
|
|
47
|
+
if (!search._hasRecommendWidget || recommendReceived) {
|
|
48
|
+
resolve();
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
search.mainHelper.derivedHelpers[0].once('recommend:result', function() {
|
|
52
|
+
recommendReceived = true;
|
|
53
|
+
if (!search._hasSearchWidget || searchReceived) {
|
|
54
|
+
resolve();
|
|
55
|
+
}
|
|
56
|
+
});
|
|
79
57
|
});
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
var
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
58
|
+
};
|
|
59
|
+
var injectInitialResults = function injectInitialResults() {
|
|
60
|
+
var options = {
|
|
61
|
+
inserted: false
|
|
62
|
+
};
|
|
63
|
+
var results = getInitialResults(search.mainIndex, requestParamsList);
|
|
64
|
+
insertHTML(createInsertHTML({
|
|
65
|
+
options: options,
|
|
66
|
+
results: results,
|
|
67
|
+
nonce: nonce
|
|
68
|
+
}));
|
|
69
|
+
};
|
|
70
|
+
if ((waitForResultsRef === null || waitForResultsRef === void 0 ? void 0 : waitForResultsRef.current) === null) {
|
|
71
|
+
waitForResultsRef.current = wrapPromiseWithState(waitForResults().then(function() {
|
|
72
|
+
var shouldRefetch = false;
|
|
73
|
+
walkIndex(search.mainIndex, function(index) {
|
|
74
|
+
shouldRefetch = index.getWidgets().some(function(widget) {
|
|
75
|
+
return widget.$$type === 'ais.dynamicWidgets';
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
if (shouldRefetch) {
|
|
79
|
+
var _search__resetScheduleSearch;
|
|
80
|
+
(_search__resetScheduleSearch = search._resetScheduleSearch) === null || _search__resetScheduleSearch === void 0 ? void 0 : _search__resetScheduleSearch.call(search);
|
|
81
|
+
waitForResultsRef.current = wrapPromiseWithState(waitForResults().then(injectInitialResults));
|
|
82
|
+
}
|
|
83
|
+
return shouldRefetch;
|
|
84
|
+
}).then(function(shouldRefetch) {
|
|
85
|
+
if (shouldRefetch) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
injectInitialResults();
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export { InitializePromise };
|
|
@@ -1,79 +1,78 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import React, { useEffect, useRef } from 'react';
|
|
1
|
+
import { _ as _$2 } from '@swc/helpers/cjs/_object_spread.cjs';
|
|
2
|
+
import { _ as _$1 } from '@swc/helpers/cjs/_object_spread_props.cjs';
|
|
3
|
+
import { _ } from '@swc/helpers/cjs/_object_without_properties.cjs';
|
|
4
|
+
import { safelyRunOnBrowser } from 'instantsearch.js/es/lib/utils/index.js';
|
|
5
|
+
import React, { useRef, useEffect } from 'react';
|
|
7
6
|
import { InstantSearch, InstantSearchRSCContext, InstantSearchSSRContext } from 'react-instantsearch-core';
|
|
8
|
-
import { InitializePromise } from
|
|
9
|
-
import { TriggerSearch } from
|
|
10
|
-
import { useDynamicRouteWarning } from
|
|
11
|
-
import { useInstantSearchRouting } from
|
|
12
|
-
import { useNextHeaders } from
|
|
7
|
+
import { InitializePromise } from './InitializePromise.js';
|
|
8
|
+
import { TriggerSearch } from './TriggerSearch.js';
|
|
9
|
+
import { useDynamicRouteWarning } from './useDynamicRouteWarning.js';
|
|
10
|
+
import { useInstantSearchRouting } from './useInstantSearchRouting.js';
|
|
11
|
+
import { useNextHeaders } from './useNextHeaders.js';
|
|
12
|
+
|
|
13
13
|
var InstantSearchInitialResults = Symbol.for('InstantSearchInitialResults');
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
function createInstantSearchNextInstance() {
|
|
15
|
+
return {
|
|
16
|
+
current: null
|
|
17
|
+
};
|
|
18
18
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
19
|
+
function InstantSearchNext(_0) {
|
|
20
|
+
var children = _0.children, passedRouting = _0.routing, instance = _0.instance, _0_ignoreMultipleHooksWarning = _0.ignoreMultipleHooksWarning, ignoreMultipleHooksWarning = _0_ignoreMultipleHooksWarning === void 0 ? false : _0_ignoreMultipleHooksWarning, instantSearchProps = _(_0, [
|
|
21
|
+
"children",
|
|
22
|
+
"routing",
|
|
23
|
+
"instance",
|
|
24
|
+
"ignoreMultipleHooksWarning"
|
|
25
|
+
]);
|
|
26
|
+
var isMounting = useRef(true);
|
|
27
|
+
var isServer = typeof window === 'undefined';
|
|
28
|
+
useEffect(function() {
|
|
29
|
+
isMounting.current = false;
|
|
30
|
+
}, []);
|
|
31
|
+
var headers = useNextHeaders();
|
|
32
|
+
var nonce = safelyRunOnBrowser(function() {
|
|
33
|
+
return undefined;
|
|
34
|
+
}, {
|
|
35
|
+
fallback: function fallback() {
|
|
36
|
+
return (headers === null || headers === void 0 ? void 0 : headers.get('x-nonce')) || undefined;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
useDynamicRouteWarning({
|
|
40
|
+
isServer: isServer,
|
|
41
|
+
isMounting: isMounting,
|
|
42
|
+
instance: instance
|
|
43
|
+
});
|
|
44
|
+
var routing = useInstantSearchRouting(passedRouting, isMounting);
|
|
45
|
+
return /*#__PURE__*/ React.createElement(ServerOrHydrationProvider, {
|
|
46
|
+
isServer: isServer,
|
|
47
|
+
instance: instance,
|
|
48
|
+
ignoreMultipleHooksWarning: ignoreMultipleHooksWarning
|
|
49
|
+
}, /*#__PURE__*/ React.createElement(InstantSearch, _$1(_$2({}, instantSearchProps), {
|
|
50
|
+
routing: routing
|
|
51
|
+
}), isServer && /*#__PURE__*/ React.createElement(InitializePromise, {
|
|
52
|
+
nonce: nonce
|
|
53
|
+
}), children, isServer && /*#__PURE__*/ React.createElement(TriggerSearch, {
|
|
54
|
+
nonce: nonce
|
|
55
|
+
})));
|
|
56
56
|
}
|
|
57
|
-
function ServerOrHydrationProvider(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
57
|
+
function ServerOrHydrationProvider(param) {
|
|
58
|
+
var isServer = param.isServer, children = param.children, instance = param.instance, ignoreMultipleHooksWarning = param.ignoreMultipleHooksWarning;
|
|
59
|
+
var promiseRef = useRef(null);
|
|
60
|
+
var countRef = useRef(0);
|
|
61
|
+
var initialResults = safelyRunOnBrowser(function() {
|
|
62
|
+
return window[InstantSearchInitialResults];
|
|
63
|
+
});
|
|
64
|
+
return /*#__PURE__*/ React.createElement(InstantSearchRSCContext.Provider, {
|
|
65
|
+
value: {
|
|
66
|
+
waitForResultsRef: promiseRef,
|
|
67
|
+
countRef: countRef,
|
|
68
|
+
ignoreMultipleHooksWarning: ignoreMultipleHooksWarning
|
|
69
|
+
}
|
|
70
|
+
}, /*#__PURE__*/ React.createElement(InstantSearchSSRContext.Provider, {
|
|
71
|
+
value: {
|
|
72
|
+
initialResults: initialResults,
|
|
73
|
+
ssrSearchRef: isServer ? undefined : instance
|
|
74
|
+
}
|
|
75
|
+
}, children));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { InstantSearchNext, createInstantSearchNextInstance };
|
package/dist/es/TriggerSearch.js
CHANGED
|
@@ -1,40 +1,41 @@
|
|
|
1
|
-
import { ServerInsertedHTMLContext } from
|
|
1
|
+
import { ServerInsertedHTMLContext } from 'next/navigation.js';
|
|
2
2
|
import { useContext } from 'react';
|
|
3
3
|
import { useInstantSearchContext, useRSCContext } from 'react-instantsearch-core';
|
|
4
|
-
import { createInsertHTML } from
|
|
5
|
-
export function TriggerSearch(_ref) {
|
|
6
|
-
var _waitForResultsRef$cu;
|
|
7
|
-
var nonce = _ref.nonce;
|
|
8
|
-
var instantsearch = useInstantSearchContext();
|
|
9
|
-
var _useRSCContext = useRSCContext(),
|
|
10
|
-
waitForResultsRef = _useRSCContext.waitForResultsRef;
|
|
11
|
-
var insertHTML = useContext(ServerInsertedHTMLContext) || function () {
|
|
12
|
-
throw new Error('Missing ServerInsertedHTMLContext');
|
|
13
|
-
};
|
|
14
|
-
if ((waitForResultsRef === null || waitForResultsRef === void 0 ? void 0 : (_waitForResultsRef$cu = waitForResultsRef.current) === null || _waitForResultsRef$cu === void 0 ? void 0 : _waitForResultsRef$cu.status) === 'pending') {
|
|
15
|
-
var _instantsearch$mainHe3;
|
|
16
|
-
if (instantsearch._hasSearchWidget) {
|
|
17
|
-
if (instantsearch.compositionID) {
|
|
18
|
-
var _instantsearch$mainHe;
|
|
19
|
-
(_instantsearch$mainHe = instantsearch.mainHelper) === null || _instantsearch$mainHe === void 0 ? void 0 : _instantsearch$mainHe.searchWithComposition();
|
|
20
|
-
} else {
|
|
21
|
-
var _instantsearch$mainHe2;
|
|
22
|
-
(_instantsearch$mainHe2 = instantsearch.mainHelper) === null || _instantsearch$mainHe2 === void 0 ? void 0 : _instantsearch$mainHe2.searchOnlyWithDerivedHelpers();
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
instantsearch._hasRecommendWidget && ((_instantsearch$mainHe3 = instantsearch.mainHelper) === null || _instantsearch$mainHe3 === void 0 ? void 0 : _instantsearch$mainHe3.recommend());
|
|
4
|
+
import { createInsertHTML } from './createInsertHTML.js';
|
|
26
5
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
6
|
+
function TriggerSearch(param) {
|
|
7
|
+
var nonce = param.nonce;
|
|
8
|
+
var _waitForResultsRef_current;
|
|
9
|
+
var instantsearch = useInstantSearchContext();
|
|
10
|
+
var waitForResultsRef = useRSCContext().waitForResultsRef;
|
|
11
|
+
var insertHTML = useContext(ServerInsertedHTMLContext) || function() {
|
|
12
|
+
throw new Error('Missing ServerInsertedHTMLContext');
|
|
13
|
+
};
|
|
14
|
+
if ((waitForResultsRef === null || waitForResultsRef === void 0 ? void 0 : (_waitForResultsRef_current = waitForResultsRef.current) === null || _waitForResultsRef_current === void 0 ? void 0 : _waitForResultsRef_current.status) === 'pending') {
|
|
15
|
+
var _instantsearch_mainHelper;
|
|
16
|
+
if (instantsearch._hasSearchWidget) {
|
|
17
|
+
if (instantsearch.compositionID) {
|
|
18
|
+
var _instantsearch_mainHelper1;
|
|
19
|
+
(_instantsearch_mainHelper1 = instantsearch.mainHelper) === null || _instantsearch_mainHelper1 === void 0 ? void 0 : _instantsearch_mainHelper1.searchWithComposition();
|
|
20
|
+
} else {
|
|
21
|
+
var _instantsearch_mainHelper2;
|
|
22
|
+
(_instantsearch_mainHelper2 = instantsearch.mainHelper) === null || _instantsearch_mainHelper2 === void 0 ? void 0 : _instantsearch_mainHelper2.searchOnlyWithDerivedHelpers();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
instantsearch._hasRecommendWidget && ((_instantsearch_mainHelper = instantsearch.mainHelper) === null || _instantsearch_mainHelper === void 0 ? void 0 : _instantsearch_mainHelper.recommend());
|
|
26
|
+
// If there are no widgets, we inject empty initial results instantly
|
|
27
|
+
if (!instantsearch._hasSearchWidget && !instantsearch._hasRecommendWidget) {
|
|
28
|
+
var options = {
|
|
29
|
+
inserted: false
|
|
30
|
+
};
|
|
31
|
+
insertHTML(createInsertHTML({
|
|
32
|
+
options: options,
|
|
33
|
+
results: {},
|
|
34
|
+
nonce: nonce
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { TriggerSearch };
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { htmlEscapeJsonString } from
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
results =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
2
|
+
import { htmlEscapeJsonString } from './htmlEscape.js';
|
|
3
|
+
|
|
4
|
+
var createInsertHTML = function createInsertHTML(param) {
|
|
5
|
+
var options = param.options, results = param.results, nonce = param.nonce;
|
|
6
|
+
return function() {
|
|
7
|
+
if (options.inserted) {
|
|
8
|
+
return /*#__PURE__*/ React.createElement(React.Fragment, null);
|
|
9
|
+
}
|
|
10
|
+
options.inserted = true;
|
|
11
|
+
return /*#__PURE__*/ React.createElement("script", {
|
|
12
|
+
nonce: nonce,
|
|
13
|
+
dangerouslySetInnerHTML: {
|
|
14
|
+
__html: 'window[Symbol.for("InstantSearchInitialResults")] = '.concat(htmlEscapeJsonString(JSON.stringify(results)))
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { createInsertHTML };
|