react-instantsearch-nextjs 0.3.18 → 0.3.20
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.
|
@@ -26,6 +26,21 @@ function InstantSearchNext(_ref) {
|
|
|
26
26
|
passedRouting = _ref.routing,
|
|
27
27
|
instantSearchProps = _objectWithoutProperties(_ref, _excluded);
|
|
28
28
|
var isMounting = (0, _react.useRef)(true);
|
|
29
|
+
var isServer = typeof window === 'undefined';
|
|
30
|
+
var hasRouteChanged = (0, _react.useMemo)(function () {
|
|
31
|
+
// On server, always return false
|
|
32
|
+
if (isServer) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// On client, route has changed if initialResults have been cleaned up
|
|
37
|
+
var hasInitialResults = window[InstantSearchInitialResults] !== undefined;
|
|
38
|
+
return !hasInitialResults;
|
|
39
|
+
}, [isServer]);
|
|
40
|
+
|
|
41
|
+
// We only want to trigger a search from a server environment
|
|
42
|
+
// or if a Next.js route change has happened on the client
|
|
43
|
+
var shouldTriggerSearch = isServer || hasRouteChanged;
|
|
29
44
|
(0, _react.useEffect)(function () {
|
|
30
45
|
isMounting.current = false;
|
|
31
46
|
return function () {
|
|
@@ -52,7 +67,7 @@ function InstantSearchNext(_ref) {
|
|
|
52
67
|
initialResults: initialResults
|
|
53
68
|
}, /*#__PURE__*/_react.default.createElement(_reactInstantsearchCore.InstantSearch, _extends({}, instantSearchProps, {
|
|
54
69
|
routing: routing
|
|
55
|
-
}),
|
|
70
|
+
}), shouldTriggerSearch && /*#__PURE__*/_react.default.createElement(_InitializePromise.InitializePromise, {
|
|
56
71
|
nonce: nonce
|
|
57
|
-
}), children,
|
|
72
|
+
}), children, shouldTriggerSearch && _ref2)));
|
|
58
73
|
}
|
|
@@ -4,7 +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 React, { useEffect, useRef } from 'react';
|
|
7
|
+
import React, { useEffect, useMemo, useRef } from 'react';
|
|
8
8
|
import { InstantSearch, InstantSearchRSCContext, InstantSearchSSRProvider } from 'react-instantsearch-core';
|
|
9
9
|
import { InitializePromise } from "./InitializePromise.js";
|
|
10
10
|
import { TriggerSearch } from "./TriggerSearch.js";
|
|
@@ -17,6 +17,21 @@ export function InstantSearchNext(_ref) {
|
|
|
17
17
|
passedRouting = _ref.routing,
|
|
18
18
|
instantSearchProps = _objectWithoutProperties(_ref, _excluded);
|
|
19
19
|
var isMounting = useRef(true);
|
|
20
|
+
var isServer = typeof window === 'undefined';
|
|
21
|
+
var hasRouteChanged = useMemo(function () {
|
|
22
|
+
// On server, always return false
|
|
23
|
+
if (isServer) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// On client, route has changed if initialResults have been cleaned up
|
|
28
|
+
var hasInitialResults = window[InstantSearchInitialResults] !== undefined;
|
|
29
|
+
return !hasInitialResults;
|
|
30
|
+
}, [isServer]);
|
|
31
|
+
|
|
32
|
+
// We only want to trigger a search from a server environment
|
|
33
|
+
// or if a Next.js route change has happened on the client
|
|
34
|
+
var shouldTriggerSearch = isServer || hasRouteChanged;
|
|
20
35
|
useEffect(function () {
|
|
21
36
|
isMounting.current = false;
|
|
22
37
|
return function () {
|
|
@@ -43,7 +58,7 @@ export function InstantSearchNext(_ref) {
|
|
|
43
58
|
initialResults: initialResults
|
|
44
59
|
}, /*#__PURE__*/React.createElement(InstantSearch, _extends({}, instantSearchProps, {
|
|
45
60
|
routing: routing
|
|
46
|
-
}),
|
|
61
|
+
}), shouldTriggerSearch && /*#__PURE__*/React.createElement(InitializePromise, {
|
|
47
62
|
nonce: nonce
|
|
48
|
-
}), children,
|
|
63
|
+
}), children, shouldTriggerSearch && _ref2)));
|
|
49
64
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-instantsearch-nextjs",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.20",
|
|
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": "66a9711dcde3df863f6438c96f63694b5d8d3a69"
|
|
61
61
|
}
|