react-instantsearch-nextjs 0.3.19 → 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.
|
@@ -7,7 +7,6 @@ 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");
|
|
11
10
|
var _react = _interopRequireWildcard(require("react"));
|
|
12
11
|
var _reactInstantsearchCore = require("react-instantsearch-core");
|
|
13
12
|
var _InitializePromise = require("./InitializePromise");
|
|
@@ -21,7 +20,6 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
|
21
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; }
|
|
22
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; }
|
|
23
22
|
var InstantSearchInitialResults = Symbol.for('InstantSearchInitialResults');
|
|
24
|
-
var InstantSearchLastPath = Symbol.for('InstantSearchLastPath');
|
|
25
23
|
var _ref2 = /*#__PURE__*/_react.default.createElement(_TriggerSearch.TriggerSearch, null);
|
|
26
24
|
function InstantSearchNext(_ref) {
|
|
27
25
|
var children = _ref.children,
|
|
@@ -29,8 +27,16 @@ function InstantSearchNext(_ref) {
|
|
|
29
27
|
instantSearchProps = _objectWithoutProperties(_ref, _excluded);
|
|
30
28
|
var isMounting = (0, _react.useRef)(true);
|
|
31
29
|
var isServer = typeof window === 'undefined';
|
|
32
|
-
var
|
|
33
|
-
|
|
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]);
|
|
34
40
|
|
|
35
41
|
// We only want to trigger a search from a server environment
|
|
36
42
|
// or if a Next.js route change has happened on the client
|
|
@@ -42,9 +48,6 @@ function InstantSearchNext(_ref) {
|
|
|
42
48
|
delete window[InstantSearchInitialResults];
|
|
43
49
|
};
|
|
44
50
|
}, []);
|
|
45
|
-
(0, _react.useEffect)(function () {
|
|
46
|
-
window[InstantSearchLastPath] = pathname;
|
|
47
|
-
}, [pathname]);
|
|
48
51
|
var nonce = (0, _utils.safelyRunOnBrowser)(function () {
|
|
49
52
|
return undefined;
|
|
50
53
|
}, {
|
|
@@ -2,11 +2,9 @@ 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;
|
|
6
5
|
declare global {
|
|
7
6
|
interface Window {
|
|
8
7
|
[InstantSearchInitialResults]?: InitialResults;
|
|
9
|
-
[InstantSearchLastPath]?: string;
|
|
10
8
|
}
|
|
11
9
|
}
|
|
12
10
|
export type InstantSearchNextRouting<TUiState, TRouteState> = {
|
|
@@ -4,15 +4,13 @@ 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 {
|
|
8
|
-
import React, { useEffect, useRef } from 'react';
|
|
7
|
+
import React, { useEffect, useMemo, useRef } from 'react';
|
|
9
8
|
import { InstantSearch, InstantSearchRSCContext, InstantSearchSSRProvider } from 'react-instantsearch-core';
|
|
10
9
|
import { InitializePromise } from "./InitializePromise.js";
|
|
11
10
|
import { TriggerSearch } from "./TriggerSearch.js";
|
|
12
11
|
import { useInstantSearchRouting } from "./useInstantSearchRouting.js";
|
|
13
12
|
import { warn } from "./warn.js";
|
|
14
13
|
var InstantSearchInitialResults = Symbol.for('InstantSearchInitialResults');
|
|
15
|
-
var InstantSearchLastPath = Symbol.for('InstantSearchLastPath');
|
|
16
14
|
var _ref2 = /*#__PURE__*/React.createElement(TriggerSearch, null);
|
|
17
15
|
export function InstantSearchNext(_ref) {
|
|
18
16
|
var children = _ref.children,
|
|
@@ -20,8 +18,16 @@ export function InstantSearchNext(_ref) {
|
|
|
20
18
|
instantSearchProps = _objectWithoutProperties(_ref, _excluded);
|
|
21
19
|
var isMounting = useRef(true);
|
|
22
20
|
var isServer = typeof window === 'undefined';
|
|
23
|
-
var
|
|
24
|
-
|
|
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]);
|
|
25
31
|
|
|
26
32
|
// We only want to trigger a search from a server environment
|
|
27
33
|
// or if a Next.js route change has happened on the client
|
|
@@ -33,9 +39,6 @@ export function InstantSearchNext(_ref) {
|
|
|
33
39
|
delete window[InstantSearchInitialResults];
|
|
34
40
|
};
|
|
35
41
|
}, []);
|
|
36
|
-
useEffect(function () {
|
|
37
|
-
window[InstantSearchLastPath] = pathname;
|
|
38
|
-
}, [pathname]);
|
|
39
42
|
var nonce = safelyRunOnBrowser(function () {
|
|
40
43
|
return undefined;
|
|
41
44
|
}, {
|
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",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"next": ">= 13.4 < 15",
|
|
58
58
|
"react-instantsearch": ">= 7.1.0 < 8"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "66a9711dcde3df863f6438c96f63694b5d8d3a69"
|
|
61
61
|
}
|