react-instantsearch-nextjs 0.3.18 → 0.3.19
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.
|
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.InstantSearchNext = InstantSearchNext;
|
|
8
8
|
var _utils = require("instantsearch.js/cjs/lib/utils");
|
|
9
9
|
var _headers = require("next/headers");
|
|
10
|
+
var _navigation = require("next/navigation");
|
|
10
11
|
var _react = _interopRequireWildcard(require("react"));
|
|
11
12
|
var _reactInstantsearchCore = require("react-instantsearch-core");
|
|
12
13
|
var _InitializePromise = require("./InitializePromise");
|
|
@@ -20,12 +21,20 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
|
20
21
|
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
22
|
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
23
|
var InstantSearchInitialResults = Symbol.for('InstantSearchInitialResults');
|
|
24
|
+
var InstantSearchLastPath = Symbol.for('InstantSearchLastPath');
|
|
23
25
|
var _ref2 = /*#__PURE__*/_react.default.createElement(_TriggerSearch.TriggerSearch, null);
|
|
24
26
|
function InstantSearchNext(_ref) {
|
|
25
27
|
var children = _ref.children,
|
|
26
28
|
passedRouting = _ref.routing,
|
|
27
29
|
instantSearchProps = _objectWithoutProperties(_ref, _excluded);
|
|
28
30
|
var isMounting = (0, _react.useRef)(true);
|
|
31
|
+
var isServer = typeof window === 'undefined';
|
|
32
|
+
var pathname = (0, _navigation.usePathname)();
|
|
33
|
+
var hasRouteChanged = !isServer && window[InstantSearchLastPath] && window[InstantSearchLastPath] !== pathname;
|
|
34
|
+
|
|
35
|
+
// We only want to trigger a search from a server environment
|
|
36
|
+
// or if a Next.js route change has happened on the client
|
|
37
|
+
var shouldTriggerSearch = isServer || hasRouteChanged;
|
|
29
38
|
(0, _react.useEffect)(function () {
|
|
30
39
|
isMounting.current = false;
|
|
31
40
|
return function () {
|
|
@@ -33,6 +42,9 @@ function InstantSearchNext(_ref) {
|
|
|
33
42
|
delete window[InstantSearchInitialResults];
|
|
34
43
|
};
|
|
35
44
|
}, []);
|
|
45
|
+
(0, _react.useEffect)(function () {
|
|
46
|
+
window[InstantSearchLastPath] = pathname;
|
|
47
|
+
}, [pathname]);
|
|
36
48
|
var nonce = (0, _utils.safelyRunOnBrowser)(function () {
|
|
37
49
|
return undefined;
|
|
38
50
|
}, {
|
|
@@ -52,7 +64,7 @@ function InstantSearchNext(_ref) {
|
|
|
52
64
|
initialResults: initialResults
|
|
53
65
|
}, /*#__PURE__*/_react.default.createElement(_reactInstantsearchCore.InstantSearch, _extends({}, instantSearchProps, {
|
|
54
66
|
routing: routing
|
|
55
|
-
}),
|
|
67
|
+
}), shouldTriggerSearch && /*#__PURE__*/_react.default.createElement(_InitializePromise.InitializePromise, {
|
|
56
68
|
nonce: nonce
|
|
57
|
-
}), children,
|
|
69
|
+
}), children, shouldTriggerSearch && _ref2)));
|
|
58
70
|
}
|
|
@@ -2,9 +2,11 @@ import type { InitialResults, StateMapping, UiState } from 'instantsearch.js';
|
|
|
2
2
|
import type { BrowserHistoryArgs } from 'instantsearch.js/es/lib/routers/history';
|
|
3
3
|
import type { InstantSearchProps } from 'react-instantsearch-core';
|
|
4
4
|
declare const InstantSearchInitialResults: unique symbol;
|
|
5
|
+
declare const InstantSearchLastPath: unique symbol;
|
|
5
6
|
declare global {
|
|
6
7
|
interface Window {
|
|
7
8
|
[InstantSearchInitialResults]?: InitialResults;
|
|
9
|
+
[InstantSearchLastPath]?: string;
|
|
8
10
|
}
|
|
9
11
|
}
|
|
10
12
|
export type InstantSearchNextRouting<TUiState, TRouteState> = {
|
|
@@ -4,6 +4,7 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
|
|
|
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 { headers } from "next/headers.js";
|
|
7
|
+
import { usePathname } from "next/navigation.js";
|
|
7
8
|
import React, { useEffect, useRef } from 'react';
|
|
8
9
|
import { InstantSearch, InstantSearchRSCContext, InstantSearchSSRProvider } from 'react-instantsearch-core';
|
|
9
10
|
import { InitializePromise } from "./InitializePromise.js";
|
|
@@ -11,12 +12,20 @@ import { TriggerSearch } from "./TriggerSearch.js";
|
|
|
11
12
|
import { useInstantSearchRouting } from "./useInstantSearchRouting.js";
|
|
12
13
|
import { warn } from "./warn.js";
|
|
13
14
|
var InstantSearchInitialResults = Symbol.for('InstantSearchInitialResults');
|
|
15
|
+
var InstantSearchLastPath = Symbol.for('InstantSearchLastPath');
|
|
14
16
|
var _ref2 = /*#__PURE__*/React.createElement(TriggerSearch, null);
|
|
15
17
|
export function InstantSearchNext(_ref) {
|
|
16
18
|
var children = _ref.children,
|
|
17
19
|
passedRouting = _ref.routing,
|
|
18
20
|
instantSearchProps = _objectWithoutProperties(_ref, _excluded);
|
|
19
21
|
var isMounting = useRef(true);
|
|
22
|
+
var isServer = typeof window === 'undefined';
|
|
23
|
+
var pathname = usePathname();
|
|
24
|
+
var hasRouteChanged = !isServer && window[InstantSearchLastPath] && window[InstantSearchLastPath] !== pathname;
|
|
25
|
+
|
|
26
|
+
// We only want to trigger a search from a server environment
|
|
27
|
+
// or if a Next.js route change has happened on the client
|
|
28
|
+
var shouldTriggerSearch = isServer || hasRouteChanged;
|
|
20
29
|
useEffect(function () {
|
|
21
30
|
isMounting.current = false;
|
|
22
31
|
return function () {
|
|
@@ -24,6 +33,9 @@ export function InstantSearchNext(_ref) {
|
|
|
24
33
|
delete window[InstantSearchInitialResults];
|
|
25
34
|
};
|
|
26
35
|
}, []);
|
|
36
|
+
useEffect(function () {
|
|
37
|
+
window[InstantSearchLastPath] = pathname;
|
|
38
|
+
}, [pathname]);
|
|
27
39
|
var nonce = safelyRunOnBrowser(function () {
|
|
28
40
|
return undefined;
|
|
29
41
|
}, {
|
|
@@ -43,7 +55,7 @@ export function InstantSearchNext(_ref) {
|
|
|
43
55
|
initialResults: initialResults
|
|
44
56
|
}, /*#__PURE__*/React.createElement(InstantSearch, _extends({}, instantSearchProps, {
|
|
45
57
|
routing: routing
|
|
46
|
-
}),
|
|
58
|
+
}), shouldTriggerSearch && /*#__PURE__*/React.createElement(InitializePromise, {
|
|
47
59
|
nonce: nonce
|
|
48
|
-
}), children,
|
|
60
|
+
}), children, shouldTriggerSearch && _ref2)));
|
|
49
61
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-instantsearch-nextjs",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.19",
|
|
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.75.
|
|
52
|
+
"instantsearch.js": "4.75.6",
|
|
53
53
|
"next": "13.5.1",
|
|
54
|
-
"react-instantsearch-core": "7.13.
|
|
54
|
+
"react-instantsearch-core": "7.13.9"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
57
|
"next": ">= 13.4 < 15",
|
|
58
58
|
"react-instantsearch": ">= 7.1.0 < 8"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "57abee485d8d8f7c0981a3fc9d12bb8537decd74"
|
|
61
61
|
}
|