react-instantsearch-nextjs 0.4.0 → 0.4.2

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.
@@ -27,20 +27,6 @@ function InstantSearchNext(_ref) {
27
27
  instantSearchProps = _objectWithoutProperties(_ref, _excluded);
28
28
  var isMounting = (0, _react.useRef)(true);
29
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;
44
30
  (0, _react.useEffect)(function () {
45
31
  isMounting.current = false;
46
32
  return function () {
@@ -57,18 +43,30 @@ function InstantSearchNext(_ref) {
57
43
  }
58
44
  });
59
45
  var routing = (0, _useInstantSearchRouting.useInstantSearchRouting)(passedRouting, isMounting);
46
+ 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;
47
+ return /*#__PURE__*/_react.default.createElement(ServerOrHydrationProvider, {
48
+ isServer: isServer
49
+ }, /*#__PURE__*/_react.default.createElement(_reactInstantsearchCore.InstantSearch, _extends({}, instantSearchProps, {
50
+ routing: routing
51
+ }), isServer && /*#__PURE__*/_react.default.createElement(_InitializePromise.InitializePromise, {
52
+ nonce: nonce
53
+ }), children, isServer && _ref2));
54
+ }
55
+ function ServerOrHydrationProvider(_ref3) {
56
+ var isServer = _ref3.isServer,
57
+ children = _ref3.children;
60
58
  var promiseRef = (0, _react.useRef)(null);
61
59
  var initialResults = (0, _utils.safelyRunOnBrowser)(function () {
62
60
  return window[InstantSearchInitialResults];
63
61
  });
64
- 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;
62
+
63
+ // If we're not on the server and we don't need to hydrate, we don't need SSR context
64
+ if (!isServer && !initialResults) {
65
+ return children;
66
+ }
65
67
  return /*#__PURE__*/_react.default.createElement(_reactInstantsearchCore.InstantSearchRSCContext.Provider, {
66
68
  value: promiseRef
67
69
  }, /*#__PURE__*/_react.default.createElement(_reactInstantsearchCore.InstantSearchSSRProvider, {
68
70
  initialResults: initialResults
69
- }, /*#__PURE__*/_react.default.createElement(_reactInstantsearchCore.InstantSearch, _extends({}, instantSearchProps, {
70
- routing: routing
71
- }), shouldTriggerSearch && /*#__PURE__*/_react.default.createElement(_InitializePromise.InitializePromise, {
72
- nonce: nonce
73
- }), children, shouldTriggerSearch && _ref2)));
71
+ }, children));
74
72
  }
@@ -3,7 +3,7 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
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
- import React, { useEffect, useMemo, useRef } from 'react';
6
+ import React, { useEffect, useRef } from 'react';
7
7
  import { InstantSearch, InstantSearchRSCContext, InstantSearchSSRProvider } from 'react-instantsearch-core';
8
8
  import { InitializePromise } from "./InitializePromise.js";
9
9
  import { TriggerSearch } from "./TriggerSearch.js";
@@ -18,20 +18,6 @@ export function InstantSearchNext(_ref) {
18
18
  instantSearchProps = _objectWithoutProperties(_ref, _excluded);
19
19
  var isMounting = useRef(true);
20
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;
35
21
  useEffect(function () {
36
22
  isMounting.current = false;
37
23
  return function () {
@@ -48,18 +34,30 @@ export function InstantSearchNext(_ref) {
48
34
  }
49
35
  });
50
36
  var routing = useInstantSearchRouting(passedRouting, isMounting);
37
+ 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;
38
+ return /*#__PURE__*/React.createElement(ServerOrHydrationProvider, {
39
+ isServer: isServer
40
+ }, /*#__PURE__*/React.createElement(InstantSearch, _extends({}, instantSearchProps, {
41
+ routing: routing
42
+ }), isServer && /*#__PURE__*/React.createElement(InitializePromise, {
43
+ nonce: nonce
44
+ }), children, isServer && _ref2));
45
+ }
46
+ function ServerOrHydrationProvider(_ref3) {
47
+ var isServer = _ref3.isServer,
48
+ children = _ref3.children;
51
49
  var promiseRef = useRef(null);
52
50
  var initialResults = safelyRunOnBrowser(function () {
53
51
  return window[InstantSearchInitialResults];
54
52
  });
55
- 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;
53
+
54
+ // If we're not on the server and we don't need to hydrate, we don't need SSR context
55
+ if (!isServer && !initialResults) {
56
+ return children;
57
+ }
56
58
  return /*#__PURE__*/React.createElement(InstantSearchRSCContext.Provider, {
57
59
  value: promiseRef
58
60
  }, /*#__PURE__*/React.createElement(InstantSearchSSRProvider, {
59
61
  initialResults: initialResults
60
- }, /*#__PURE__*/React.createElement(InstantSearch, _extends({}, instantSearchProps, {
61
- routing: routing
62
- }), shouldTriggerSearch && /*#__PURE__*/React.createElement(InitializePromise, {
63
- nonce: nonce
64
- }), children, shouldTriggerSearch && _ref2)));
62
+ }, children));
65
63
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-instantsearch-nextjs",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
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.76.0",
52
+ "instantsearch.js": "4.77.1",
53
53
  "next": "15.1.4",
54
- "react-instantsearch-core": "7.14.0"
54
+ "react-instantsearch-core": "7.15.1"
55
55
  },
56
56
  "peerDependencies": {
57
57
  "next": ">= 13.4 < 16",
58
58
  "react-instantsearch": ">= 7.1.0 < 8"
59
59
  },
60
- "gitHead": "8e30cd5859416a1c29e2030a69d52b601fc91fab"
60
+ "gitHead": "3d0c6cbcb894a0b38a81485bc98de6244b70b97e"
61
61
  }