react-instantsearch-nextjs 0.4.9 → 1.0.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 +4 -1
- package/dist/cjs/InstantSearchNext.js +33 -15
- package/dist/cjs/TriggerSearch.js +2 -1
- package/dist/cjs/useDynamicRouteWarning.js +34 -0
- package/dist/es/InitializePromise.js +4 -1
- package/dist/es/InstantSearchNext.d.ts +6 -2
- package/dist/es/InstantSearchNext.js +33 -16
- package/dist/es/TriggerSearch.js +2 -1
- package/dist/es/useDynamicRouteWarning.d.ts +6 -0
- package/dist/es/useDynamicRouteWarning.js +29 -0
- package/package.json +17 -4
|
@@ -19,7 +19,8 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
19
19
|
function InitializePromise(_ref) {
|
|
20
20
|
var nonce = _ref.nonce;
|
|
21
21
|
var _search = (0, _reactInstantsearchCore.useInstantSearchContext)();
|
|
22
|
-
var
|
|
22
|
+
var _useRSCContext = (0, _reactInstantsearchCore.useRSCContext)(),
|
|
23
|
+
waitForResultsRef = _useRSCContext.waitForResultsRef;
|
|
23
24
|
var insertHTML = (0, _react.useContext)(_navigation.ServerInsertedHTMLContext) || function () {
|
|
24
25
|
throw new Error('Missing ServerInsertedHTMLContext');
|
|
25
26
|
};
|
|
@@ -84,6 +85,8 @@ function InitializePromise(_ref) {
|
|
|
84
85
|
});
|
|
85
86
|
});
|
|
86
87
|
if (shouldRefetch) {
|
|
88
|
+
var _search$_resetSchedul;
|
|
89
|
+
(_search$_resetSchedul = _search._resetScheduleSearch) === null || _search$_resetSchedul === void 0 ? void 0 : _search$_resetSchedul.call(_search);
|
|
87
90
|
waitForResultsRef.current = (0, _reactInstantsearchCore.wrapPromiseWithState)(waitForResults().then(injectInitialResults));
|
|
88
91
|
}
|
|
89
92
|
return shouldRefetch;
|
|
@@ -5,33 +5,39 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.InstantSearchNext = InstantSearchNext;
|
|
8
|
+
exports.createInstantSearchNextInstance = createInstantSearchNextInstance;
|
|
8
9
|
var _utils = require("instantsearch.js/cjs/lib/utils");
|
|
9
10
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
11
|
var _reactInstantsearchCore = require("react-instantsearch-core");
|
|
11
12
|
var _InitializePromise = require("./InitializePromise");
|
|
12
13
|
var _TriggerSearch = require("./TriggerSearch");
|
|
14
|
+
var _useDynamicRouteWarning = require("./useDynamicRouteWarning");
|
|
13
15
|
var _useInstantSearchRouting = require("./useInstantSearchRouting");
|
|
14
16
|
var _useNextHeaders = require("./useNextHeaders");
|
|
15
17
|
var _warn = require("./warn");
|
|
16
|
-
var _excluded = ["children", "routing"];
|
|
18
|
+
var _excluded = ["children", "routing", "instance", "ignoreMultipleHooksWarning"];
|
|
17
19
|
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
20
|
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
21
|
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
22
|
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
23
|
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; }
|
|
22
24
|
var InstantSearchInitialResults = Symbol.for('InstantSearchInitialResults');
|
|
25
|
+
function createInstantSearchNextInstance() {
|
|
26
|
+
return {
|
|
27
|
+
current: null
|
|
28
|
+
};
|
|
29
|
+
}
|
|
23
30
|
function InstantSearchNext(_ref) {
|
|
24
31
|
var children = _ref.children,
|
|
25
32
|
passedRouting = _ref.routing,
|
|
33
|
+
instance = _ref.instance,
|
|
34
|
+
_ref$ignoreMultipleHo = _ref.ignoreMultipleHooksWarning,
|
|
35
|
+
ignoreMultipleHooksWarning = _ref$ignoreMultipleHo === void 0 ? false : _ref$ignoreMultipleHo,
|
|
26
36
|
instantSearchProps = _objectWithoutProperties(_ref, _excluded);
|
|
27
37
|
var isMounting = (0, _react.useRef)(true);
|
|
28
38
|
var isServer = typeof window === 'undefined';
|
|
29
39
|
(0, _react.useEffect)(function () {
|
|
30
40
|
isMounting.current = false;
|
|
31
|
-
return function () {
|
|
32
|
-
// This is to make sure that they're not reused if mounting again on a different route
|
|
33
|
-
delete window[InstantSearchInitialResults];
|
|
34
|
-
};
|
|
35
41
|
}, []);
|
|
36
42
|
var headers = (0, _useNextHeaders.useNextHeaders)();
|
|
37
43
|
var nonce = (0, _utils.safelyRunOnBrowser)(function () {
|
|
@@ -41,10 +47,17 @@ function InstantSearchNext(_ref) {
|
|
|
41
47
|
return (headers === null || headers === void 0 ? void 0 : headers.get('x-nonce')) || undefined;
|
|
42
48
|
}
|
|
43
49
|
});
|
|
50
|
+
(0, _useDynamicRouteWarning.useDynamicRouteWarning)({
|
|
51
|
+
isServer: isServer,
|
|
52
|
+
isMounting: isMounting,
|
|
53
|
+
instance: instance
|
|
54
|
+
});
|
|
44
55
|
var routing = (0, _useInstantSearchRouting.useInstantSearchRouting)(passedRouting, isMounting);
|
|
45
56
|
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;
|
|
46
57
|
return /*#__PURE__*/_react.default.createElement(ServerOrHydrationProvider, {
|
|
47
|
-
isServer: isServer
|
|
58
|
+
isServer: isServer,
|
|
59
|
+
instance: instance,
|
|
60
|
+
ignoreMultipleHooksWarning: ignoreMultipleHooksWarning
|
|
48
61
|
}, /*#__PURE__*/_react.default.createElement(_reactInstantsearchCore.InstantSearch, _extends({}, instantSearchProps, {
|
|
49
62
|
routing: routing
|
|
50
63
|
}), isServer && /*#__PURE__*/_react.default.createElement(_InitializePromise.InitializePromise, {
|
|
@@ -55,19 +68,24 @@ function InstantSearchNext(_ref) {
|
|
|
55
68
|
}
|
|
56
69
|
function ServerOrHydrationProvider(_ref2) {
|
|
57
70
|
var isServer = _ref2.isServer,
|
|
58
|
-
children = _ref2.children
|
|
71
|
+
children = _ref2.children,
|
|
72
|
+
instance = _ref2.instance,
|
|
73
|
+
ignoreMultipleHooksWarning = _ref2.ignoreMultipleHooksWarning;
|
|
59
74
|
var promiseRef = (0, _react.useRef)(null);
|
|
75
|
+
var countRef = (0, _react.useRef)(0);
|
|
60
76
|
var initialResults = (0, _utils.safelyRunOnBrowser)(function () {
|
|
61
77
|
return window[InstantSearchInitialResults];
|
|
62
78
|
});
|
|
63
|
-
|
|
64
|
-
// If we're not on the server and we don't need to hydrate, we don't need SSR context
|
|
65
|
-
if (!isServer && !initialResults) {
|
|
66
|
-
return children;
|
|
67
|
-
}
|
|
68
79
|
return /*#__PURE__*/_react.default.createElement(_reactInstantsearchCore.InstantSearchRSCContext.Provider, {
|
|
69
|
-
value:
|
|
70
|
-
|
|
71
|
-
|
|
80
|
+
value: {
|
|
81
|
+
waitForResultsRef: promiseRef,
|
|
82
|
+
countRef: countRef,
|
|
83
|
+
ignoreMultipleHooksWarning: ignoreMultipleHooksWarning
|
|
84
|
+
}
|
|
85
|
+
}, /*#__PURE__*/_react.default.createElement(_reactInstantsearchCore.InstantSearchSSRContext.Provider, {
|
|
86
|
+
value: {
|
|
87
|
+
initialResults: initialResults,
|
|
88
|
+
ssrSearchRef: isServer ? undefined : instance
|
|
89
|
+
}
|
|
72
90
|
}, children));
|
|
73
91
|
}
|
|
@@ -12,7 +12,8 @@ function TriggerSearch(_ref) {
|
|
|
12
12
|
var _waitForResultsRef$cu;
|
|
13
13
|
var nonce = _ref.nonce;
|
|
14
14
|
var instantsearch = (0, _reactInstantsearchCore.useInstantSearchContext)();
|
|
15
|
-
var
|
|
15
|
+
var _useRSCContext = (0, _reactInstantsearchCore.useRSCContext)(),
|
|
16
|
+
waitForResultsRef = _useRSCContext.waitForResultsRef;
|
|
16
17
|
var insertHTML = (0, _react.useContext)(_navigation.ServerInsertedHTMLContext) || function () {
|
|
17
18
|
throw new Error('Missing ServerInsertedHTMLContext');
|
|
18
19
|
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.useDynamicRouteWarning = useDynamicRouteWarning;
|
|
8
|
+
var _navigation = require("next/navigation");
|
|
9
|
+
var _warn = require("./warn");
|
|
10
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
11
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
12
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
13
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
14
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
15
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
16
|
+
var lastParams = null;
|
|
17
|
+
function useDynamicRouteWarning(_ref) {
|
|
18
|
+
var isServer = _ref.isServer,
|
|
19
|
+
isMounting = _ref.isMounting,
|
|
20
|
+
instance = _ref.instance;
|
|
21
|
+
var params = (0, _navigation.useParams)();
|
|
22
|
+
if (!isServer && isMounting.current && !instance) {
|
|
23
|
+
// Warn if lastParams and current params have the same keys but different values
|
|
24
|
+
if (lastParams && Object.keys(lastParams).length === Object.keys(params).length && Object.entries(lastParams).some(function (_ref2) {
|
|
25
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
26
|
+
key = _ref3[0],
|
|
27
|
+
value = _ref3[1];
|
|
28
|
+
return params[key] !== value;
|
|
29
|
+
})) {
|
|
30
|
+
process.env.NODE_ENV === 'development' ? (0, _warn.warn)(false, "\nWe detected you may be using `<InstantSearchNext>` on a dynamic route.\n\nThis can lead to unexpected behavior, we recommend passing an `instance` prop to <InstantSearchNext>, created from the `createInstantSearchNextInstance` function.\n\nThis message can be safely ignored if you are not using dynamic routes.\n\nFor more information, see https://www.algolia.com/doc/guides/building-search-ui/going-further/server-side-rendering/react/#dynamic-routes\n") : void 0;
|
|
31
|
+
}
|
|
32
|
+
lastParams = params;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -13,7 +13,8 @@ import { createInsertHTML } from "./createInsertHTML.js";
|
|
|
13
13
|
export function InitializePromise(_ref) {
|
|
14
14
|
var nonce = _ref.nonce;
|
|
15
15
|
var _search = useInstantSearchContext();
|
|
16
|
-
var
|
|
16
|
+
var _useRSCContext = useRSCContext(),
|
|
17
|
+
waitForResultsRef = _useRSCContext.waitForResultsRef;
|
|
17
18
|
var insertHTML = useContext(ServerInsertedHTMLContext) || function () {
|
|
18
19
|
throw new Error('Missing ServerInsertedHTMLContext');
|
|
19
20
|
};
|
|
@@ -78,6 +79,8 @@ export function InitializePromise(_ref) {
|
|
|
78
79
|
});
|
|
79
80
|
});
|
|
80
81
|
if (shouldRefetch) {
|
|
82
|
+
var _search$_resetSchedul;
|
|
83
|
+
(_search$_resetSchedul = _search._resetScheduleSearch) === null || _search$_resetSchedul === void 0 ? void 0 : _search$_resetSchedul.call(_search);
|
|
81
84
|
waitForResultsRef.current = wrapPromiseWithState(waitForResults().then(injectInitialResults));
|
|
82
85
|
}
|
|
83
86
|
return shouldRefetch;
|
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { InitialResults, StateMapping, UiState } from 'instantsearch.js';
|
|
3
3
|
import type { BrowserHistoryArgs } from 'instantsearch.js/es/lib/routers/history';
|
|
4
|
-
import type { InstantSearchProps } from 'react-instantsearch-core';
|
|
4
|
+
import type { InstantSearchProps, InstantSearchSSRContextApi } from 'react-instantsearch-core';
|
|
5
5
|
declare const InstantSearchInitialResults: unique symbol;
|
|
6
6
|
declare global {
|
|
7
7
|
interface Window {
|
|
8
8
|
[InstantSearchInitialResults]?: InitialResults;
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
+
export type InstantSearchNextInstance = InstantSearchSSRContextApi<UiState>['ssrSearchRef'];
|
|
12
|
+
export declare function createInstantSearchNextInstance(): InstantSearchNextInstance;
|
|
11
13
|
export type InstantSearchNextRouting<TUiState, TRouteState> = {
|
|
12
14
|
router?: Partial<BrowserHistoryArgs<TRouteState>>;
|
|
13
15
|
stateMapping?: StateMapping<TUiState, TRouteState>;
|
|
14
16
|
};
|
|
15
17
|
export type InstantSearchNextProps<TUiState extends UiState = UiState, TRouteState = TUiState> = Omit<InstantSearchProps<TUiState, TRouteState>, 'routing'> & {
|
|
16
18
|
routing?: InstantSearchNextRouting<TUiState, TRouteState> | boolean;
|
|
19
|
+
instance?: InstantSearchNextInstance;
|
|
20
|
+
ignoreMultipleHooksWarning?: boolean;
|
|
17
21
|
};
|
|
18
|
-
export declare function InstantSearchNext<TUiState extends UiState = UiState, TRouteState = TUiState>({ children, routing: passedRouting, ...instantSearchProps }: InstantSearchNextProps<TUiState, TRouteState>): React.JSX.Element;
|
|
22
|
+
export declare function InstantSearchNext<TUiState extends UiState = UiState, TRouteState = TUiState>({ children, routing: passedRouting, instance, ignoreMultipleHooksWarning, ...instantSearchProps }: InstantSearchNextProps<TUiState, TRouteState>): React.JSX.Element;
|
|
19
23
|
export {};
|
|
@@ -1,28 +1,33 @@
|
|
|
1
|
-
var _excluded = ["children", "routing"];
|
|
1
|
+
var _excluded = ["children", "routing", "instance", "ignoreMultipleHooksWarning"];
|
|
2
2
|
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); }
|
|
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
6
|
import React, { useEffect, useRef } from 'react';
|
|
7
|
-
import { InstantSearch, InstantSearchRSCContext,
|
|
7
|
+
import { InstantSearch, InstantSearchRSCContext, InstantSearchSSRContext } from 'react-instantsearch-core';
|
|
8
8
|
import { InitializePromise } from "./InitializePromise.js";
|
|
9
9
|
import { TriggerSearch } from "./TriggerSearch.js";
|
|
10
|
+
import { useDynamicRouteWarning } from "./useDynamicRouteWarning.js";
|
|
10
11
|
import { useInstantSearchRouting } from "./useInstantSearchRouting.js";
|
|
11
12
|
import { useNextHeaders } from "./useNextHeaders.js";
|
|
12
13
|
import { warn } from "./warn.js";
|
|
13
14
|
var InstantSearchInitialResults = Symbol.for('InstantSearchInitialResults');
|
|
15
|
+
export function createInstantSearchNextInstance() {
|
|
16
|
+
return {
|
|
17
|
+
current: null
|
|
18
|
+
};
|
|
19
|
+
}
|
|
14
20
|
export function InstantSearchNext(_ref) {
|
|
15
21
|
var children = _ref.children,
|
|
16
22
|
passedRouting = _ref.routing,
|
|
23
|
+
instance = _ref.instance,
|
|
24
|
+
_ref$ignoreMultipleHo = _ref.ignoreMultipleHooksWarning,
|
|
25
|
+
ignoreMultipleHooksWarning = _ref$ignoreMultipleHo === void 0 ? false : _ref$ignoreMultipleHo,
|
|
17
26
|
instantSearchProps = _objectWithoutProperties(_ref, _excluded);
|
|
18
27
|
var isMounting = useRef(true);
|
|
19
28
|
var isServer = typeof window === 'undefined';
|
|
20
29
|
useEffect(function () {
|
|
21
30
|
isMounting.current = false;
|
|
22
|
-
return function () {
|
|
23
|
-
// This is to make sure that they're not reused if mounting again on a different route
|
|
24
|
-
delete window[InstantSearchInitialResults];
|
|
25
|
-
};
|
|
26
31
|
}, []);
|
|
27
32
|
var headers = useNextHeaders();
|
|
28
33
|
var nonce = safelyRunOnBrowser(function () {
|
|
@@ -32,10 +37,17 @@ export function InstantSearchNext(_ref) {
|
|
|
32
37
|
return (headers === null || headers === void 0 ? void 0 : headers.get('x-nonce')) || undefined;
|
|
33
38
|
}
|
|
34
39
|
});
|
|
40
|
+
useDynamicRouteWarning({
|
|
41
|
+
isServer: isServer,
|
|
42
|
+
isMounting: isMounting,
|
|
43
|
+
instance: instance
|
|
44
|
+
});
|
|
35
45
|
var routing = useInstantSearchRouting(passedRouting, isMounting);
|
|
36
46
|
process.env.NODE_ENV === 'development' ? warn(false, "InstantSearchNext relies on experimental APIs and may break in the future.\nThis message will only be displayed in development mode.") : void 0;
|
|
37
47
|
return /*#__PURE__*/React.createElement(ServerOrHydrationProvider, {
|
|
38
|
-
isServer: isServer
|
|
48
|
+
isServer: isServer,
|
|
49
|
+
instance: instance,
|
|
50
|
+
ignoreMultipleHooksWarning: ignoreMultipleHooksWarning
|
|
39
51
|
}, /*#__PURE__*/React.createElement(InstantSearch, _extends({}, instantSearchProps, {
|
|
40
52
|
routing: routing
|
|
41
53
|
}), isServer && /*#__PURE__*/React.createElement(InitializePromise, {
|
|
@@ -46,19 +58,24 @@ export function InstantSearchNext(_ref) {
|
|
|
46
58
|
}
|
|
47
59
|
function ServerOrHydrationProvider(_ref2) {
|
|
48
60
|
var isServer = _ref2.isServer,
|
|
49
|
-
children = _ref2.children
|
|
61
|
+
children = _ref2.children,
|
|
62
|
+
instance = _ref2.instance,
|
|
63
|
+
ignoreMultipleHooksWarning = _ref2.ignoreMultipleHooksWarning;
|
|
50
64
|
var promiseRef = useRef(null);
|
|
65
|
+
var countRef = useRef(0);
|
|
51
66
|
var initialResults = safelyRunOnBrowser(function () {
|
|
52
67
|
return window[InstantSearchInitialResults];
|
|
53
68
|
});
|
|
54
|
-
|
|
55
|
-
// If we're not on the server and we don't need to hydrate, we don't need SSR context
|
|
56
|
-
if (!isServer && !initialResults) {
|
|
57
|
-
return children;
|
|
58
|
-
}
|
|
59
69
|
return /*#__PURE__*/React.createElement(InstantSearchRSCContext.Provider, {
|
|
60
|
-
value:
|
|
61
|
-
|
|
62
|
-
|
|
70
|
+
value: {
|
|
71
|
+
waitForResultsRef: promiseRef,
|
|
72
|
+
countRef: countRef,
|
|
73
|
+
ignoreMultipleHooksWarning: ignoreMultipleHooksWarning
|
|
74
|
+
}
|
|
75
|
+
}, /*#__PURE__*/React.createElement(InstantSearchSSRContext.Provider, {
|
|
76
|
+
value: {
|
|
77
|
+
initialResults: initialResults,
|
|
78
|
+
ssrSearchRef: isServer ? undefined : instance
|
|
79
|
+
}
|
|
63
80
|
}, children));
|
|
64
81
|
}
|
package/dist/es/TriggerSearch.js
CHANGED
|
@@ -6,7 +6,8 @@ export function TriggerSearch(_ref) {
|
|
|
6
6
|
var _waitForResultsRef$cu;
|
|
7
7
|
var nonce = _ref.nonce;
|
|
8
8
|
var instantsearch = useInstantSearchContext();
|
|
9
|
-
var
|
|
9
|
+
var _useRSCContext = useRSCContext(),
|
|
10
|
+
waitForResultsRef = _useRSCContext.waitForResultsRef;
|
|
10
11
|
var insertHTML = useContext(ServerInsertedHTMLContext) || function () {
|
|
11
12
|
throw new Error('Missing ServerInsertedHTMLContext');
|
|
12
13
|
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { InstantSearchNextInstance } from './InstantSearchNext';
|
|
2
|
+
export declare function useDynamicRouteWarning({ isServer, isMounting, instance, }: {
|
|
3
|
+
isServer: boolean;
|
|
4
|
+
isMounting: React.RefObject<boolean>;
|
|
5
|
+
instance?: InstantSearchNextInstance;
|
|
6
|
+
}): void;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
4
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
5
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
7
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
8
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
9
|
+
import { useParams } from "next/navigation.js";
|
|
10
|
+
import { warn } from "./warn.js";
|
|
11
|
+
var lastParams = null;
|
|
12
|
+
export function useDynamicRouteWarning(_ref) {
|
|
13
|
+
var isServer = _ref.isServer,
|
|
14
|
+
isMounting = _ref.isMounting,
|
|
15
|
+
instance = _ref.instance;
|
|
16
|
+
var params = useParams();
|
|
17
|
+
if (!isServer && isMounting.current && !instance) {
|
|
18
|
+
// Warn if lastParams and current params have the same keys but different values
|
|
19
|
+
if (lastParams && Object.keys(lastParams).length === Object.keys(params).length && Object.entries(lastParams).some(function (_ref2) {
|
|
20
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
21
|
+
key = _ref3[0],
|
|
22
|
+
value = _ref3[1];
|
|
23
|
+
return params[key] !== value;
|
|
24
|
+
})) {
|
|
25
|
+
process.env.NODE_ENV === 'development' ? warn(false, "\nWe detected you may be using `<InstantSearchNext>` on a dynamic route.\n\nThis can lead to unexpected behavior, we recommend passing an `instance` prop to <InstantSearchNext>, created from the `createInstantSearchNextInstance` function.\n\nThis message can be safely ignored if you are not using dynamic routes.\n\nFor more information, see https://www.algolia.com/doc/guides/building-search-ui/going-further/server-side-rendering/react/#dynamic-routes\n") : void 0;
|
|
26
|
+
}
|
|
27
|
+
lastParams = params;
|
|
28
|
+
}
|
|
29
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-instantsearch-nextjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.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",
|
|
@@ -45,17 +45,30 @@
|
|
|
45
45
|
"build:es:base": "BABEL_ENV=es babel src --root-mode upward --extensions '.js,.ts,.tsx' --out-dir dist/es --ignore '**/__tests__/**/*','**/__mocks__/**/*'",
|
|
46
46
|
"build:es": "yarn build:es:base --quiet",
|
|
47
47
|
"build:types": "tsc -p ./tsconfig.declaration.json --outDir ./dist/es",
|
|
48
|
+
"test:start-server": "yarn workspace example-react-instantsearch-next-app-dir-example build && yarn workspace example-react-instantsearch-next-app-dir-example start",
|
|
49
|
+
"test:e2e": "start-server-and-test test:start-server 3000 'wdio run ./wdio.conf.cjs'",
|
|
50
|
+
"test:e2e:saucelabs": "start-server-and-test test:start-server 3000 'wdio run ./wdio.saucelabs.conf.cjs'",
|
|
48
51
|
"test:exports": "node ./__tests__/module/is-es-module.mjs && node ./__tests__/module/is-cjs-module.cjs",
|
|
49
52
|
"watch:es": "yarn --silent build:es:base --watch"
|
|
50
53
|
},
|
|
51
54
|
"devDependencies": {
|
|
52
|
-
"
|
|
55
|
+
"@types/jasmine": "3.3.16",
|
|
56
|
+
"@wdio/cli": "5.16.9",
|
|
57
|
+
"@wdio/jasmine-framework": "5.16.5",
|
|
58
|
+
"@wdio/junit-reporter": "5.16.11",
|
|
59
|
+
"@wdio/local-runner": "5.16.9",
|
|
60
|
+
"@wdio/sauce-service": "5.16.5",
|
|
61
|
+
"@wdio/selenium-standalone-service": "5.16.5",
|
|
62
|
+
"@wdio/spec-reporter": "5.16.5",
|
|
63
|
+
"instantsearch.js": "4.79.1",
|
|
53
64
|
"next": "15.1.4",
|
|
54
|
-
"react-instantsearch-core": "7.
|
|
65
|
+
"react-instantsearch-core": "7.16.1",
|
|
66
|
+
"start-server-and-test": "1.15.3",
|
|
67
|
+
"ts-node": "8.4.1"
|
|
55
68
|
},
|
|
56
69
|
"peerDependencies": {
|
|
57
70
|
"next": ">= 13.4 < 16",
|
|
58
71
|
"react-instantsearch": ">= 7.1.0 < 8"
|
|
59
72
|
},
|
|
60
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "d0486032831c0b2ee22169aa1f5052b88b9543b0"
|
|
61
74
|
}
|