react-instantsearch-nextjs 1.2.10 → 1.2.12

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.
@@ -21,11 +21,11 @@ var _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcar
21
21
  var _object_spread = require("@swc/helpers/_/_object_spread");
22
22
  var _object_spread_props = require("@swc/helpers/_/_object_spread_props");
23
23
  var _object_without_properties = require("@swc/helpers/_/_object_without_properties");
24
+ var _sliced_to_array = require("@swc/helpers/_/_sliced_to_array");
24
25
  var _utils = require("instantsearch.js/cjs/lib/utils");
25
26
  var _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
26
27
  var _reactinstantsearchcore = require("react-instantsearch-core");
27
28
  var _InitializePromise = require("./InitializePromise");
28
- var _RefreshOnClientNavigation = require("./RefreshOnClientNavigation");
29
29
  var _TriggerSearch = require("./TriggerSearch");
30
30
  var _useDynamicRouteWarning = require("./useDynamicRouteWarning");
31
31
  var _useInstantSearchRouting = require("./useInstantSearchRouting");
@@ -72,18 +72,39 @@ function InstantSearchNext(_0) {
72
72
  nonce: nonce
73
73
  }), children, isServer && /*#__PURE__*/ _react.default.createElement(_TriggerSearch.TriggerSearch, {
74
74
  nonce: nonce
75
- }), !isServer && /*#__PURE__*/ _react.default.createElement(_RefreshOnClientNavigation.RefreshOnClientNavigation, null)));
75
+ })));
76
76
  }
77
77
  function ServerOrHydrationProvider(param) {
78
78
  var isServer = param.isServer, children = param.children, instance = param.instance, ignoreMultipleHooksWarning = param.ignoreMultipleHooksWarning;
79
79
  var promiseRef = (0, _react.useRef)(null);
80
80
  var countRef = (0, _react.useRef)(0);
81
- var initialResults = (0, _utils.safelyRunOnBrowser)(function() {
82
- return window[InstantSearchInitialResults];
83
- });
81
+ // Capture once on first render. Side-effect-free read keeps hydration
82
+ // deterministic across StrictMode double-invocation and React 19 / Next.js
83
+ // metadata streaming re-renders.
84
+ var _useState = _sliced_to_array._((0, _react.useState)(function() {
85
+ return (0, _utils.safelyRunOnBrowser)(function(param) {
86
+ var window1 = param.window;
87
+ return window1[InstantSearchInitialResults];
88
+ });
89
+ }), 1), initialResults = _useState[0];
90
+ // After commit, clear the global so a later <InstantSearchNext> mount —
91
+ // typically the destination of an App Router <Link> click — does not
92
+ // recycle this mount's serialized state.
93
+ (0, _react.useEffect)(function() {
94
+ (0, _utils.safelyRunOnBrowser)(function(param) {
95
+ var window1 = param.window;
96
+ if (window1[InstantSearchInitialResults] !== undefined) {
97
+ window1[InstantSearchInitialResults] = undefined;
98
+ }
99
+ });
100
+ }, []);
101
+ // `useInstantSearchApi` reads a truthy `waitForResultsRef` as "SSR results
102
+ // are arriving" and skips the initial search. On client mounts without
103
+ // results (typical for SPA navigation) we must let it fall through.
104
+ var rscWaitRef = !isServer && !initialResults ? null : promiseRef;
84
105
  return /*#__PURE__*/ _react.default.createElement(_reactinstantsearchcore.InstantSearchRSCContext.Provider, {
85
106
  value: {
86
- waitForResultsRef: promiseRef,
107
+ waitForResultsRef: rscWaitRef,
87
108
  countRef: countRef,
88
109
  ignoreMultipleHooksWarning: ignoreMultipleHooksWarning
89
110
  }
@@ -1,11 +1,11 @@
1
1
  import { _ as _$2 } from '@swc/helpers/esm/_object_spread.js';
2
2
  import { _ as _$1 } from '@swc/helpers/esm/_object_spread_props.js';
3
3
  import { _ } from '@swc/helpers/esm/_object_without_properties.js';
4
+ import { _ as _$3 } from '@swc/helpers/esm/_sliced_to_array.js';
4
5
  import { safelyRunOnBrowser } from 'instantsearch.js/es/lib/utils/index.js';
5
- import React, { useRef, useEffect } from 'react';
6
+ import React, { useRef, useEffect, useState } from 'react';
6
7
  import { InstantSearch, InstantSearchRSCContext, InstantSearchSSRContext } from 'react-instantsearch-core';
7
8
  import { InitializePromise } from './InitializePromise.js';
8
- import { RefreshOnClientNavigation } from './RefreshOnClientNavigation.js';
9
9
  import { TriggerSearch } from './TriggerSearch.js';
10
10
  import { useDynamicRouteWarning } from './useDynamicRouteWarning.js';
11
11
  import { useInstantSearchRouting } from './useInstantSearchRouting.js';
@@ -53,18 +53,39 @@ function InstantSearchNext(_0) {
53
53
  nonce: nonce
54
54
  }), children, isServer && /*#__PURE__*/ React.createElement(TriggerSearch, {
55
55
  nonce: nonce
56
- }), !isServer && /*#__PURE__*/ React.createElement(RefreshOnClientNavigation, null)));
56
+ })));
57
57
  }
58
58
  function ServerOrHydrationProvider(param) {
59
59
  var isServer = param.isServer, children = param.children, instance = param.instance, ignoreMultipleHooksWarning = param.ignoreMultipleHooksWarning;
60
60
  var promiseRef = useRef(null);
61
61
  var countRef = useRef(0);
62
- var initialResults = safelyRunOnBrowser(function() {
63
- return window[InstantSearchInitialResults];
64
- });
62
+ // Capture once on first render. Side-effect-free read keeps hydration
63
+ // deterministic across StrictMode double-invocation and React 19 / Next.js
64
+ // metadata streaming re-renders.
65
+ var _useState = _$3(useState(function() {
66
+ return safelyRunOnBrowser(function(param) {
67
+ var window1 = param.window;
68
+ return window1[InstantSearchInitialResults];
69
+ });
70
+ }), 1), initialResults = _useState[0];
71
+ // After commit, clear the global so a later <InstantSearchNext> mount —
72
+ // typically the destination of an App Router <Link> click — does not
73
+ // recycle this mount's serialized state.
74
+ useEffect(function() {
75
+ safelyRunOnBrowser(function(param) {
76
+ var window1 = param.window;
77
+ if (window1[InstantSearchInitialResults] !== undefined) {
78
+ window1[InstantSearchInitialResults] = undefined;
79
+ }
80
+ });
81
+ }, []);
82
+ // `useInstantSearchApi` reads a truthy `waitForResultsRef` as "SSR results
83
+ // are arriving" and skips the initial search. On client mounts without
84
+ // results (typical for SPA navigation) we must let it fall through.
85
+ var rscWaitRef = !isServer && !initialResults ? null : promiseRef;
65
86
  return /*#__PURE__*/ React.createElement(InstantSearchRSCContext.Provider, {
66
87
  value: {
67
- waitForResultsRef: promiseRef,
88
+ waitForResultsRef: rscWaitRef,
68
89
  countRef: countRef,
69
90
  ignoreMultipleHooksWarning: ignoreMultipleHooksWarning
70
91
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-instantsearch-nextjs",
3
- "version": "1.2.10",
3
+ "version": "1.2.12",
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",
@@ -52,9 +52,9 @@
52
52
  },
53
53
  "devDependencies": {
54
54
  "@playwright/test": "1.49.1",
55
- "instantsearch.js": "4.103.0",
55
+ "instantsearch.js": "4.105.0",
56
56
  "next": "16.0.7",
57
- "react-instantsearch-core": "7.37.0",
57
+ "react-instantsearch-core": "7.39.0",
58
58
  "start-server-and-test": "1.15.3",
59
59
  "ts-node": "8.4.1"
60
60
  },
@@ -62,5 +62,5 @@
62
62
  "next": ">= 13.4 < 17",
63
63
  "react-instantsearch": ">= 7.1.0 < 8"
64
64
  },
65
- "gitHead": "60cd8cde80998cc3df26ece7583f1f7c0b658113"
65
+ "gitHead": "934a48eaf77e7c6b3e7c2e018daa1f95b9f246e7"
66
66
  }
@@ -1,69 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- function _export(target, all) {
7
- for(var name in all)Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: Object.getOwnPropertyDescriptor(all, name).get
10
- });
11
- }
12
- _export(exports, {
13
- get RefreshOnClientNavigation () {
14
- return RefreshOnClientNavigation;
15
- },
16
- get isClientNavigation () {
17
- return isClientNavigation;
18
- }
19
- });
20
- var _sliced_to_array = require("@swc/helpers/_/_sliced_to_array");
21
- var _react = require("react");
22
- var _reactinstantsearchcore = require("react-instantsearch-core");
23
- // Fallback store for the first location an `InstantSearchNext` instance
24
- // rendered with, used only in environments without the Navigation Timing API
25
- // (e.g. jsdom in tests). See `getInitialLocation` below.
26
- var InstantSearchDocumentLocation = Symbol.for('InstantSearchDocumentLocation');
27
- /**
28
- * The `pathname` + `search` the document was initially loaded with.
29
- *
30
- * It comes from the Navigation Timing API, which reflects the hard page load
31
- * and is *not* affected by client-side (SPA) navigations. The hash is ignored
32
- * as it isn't part of the routing state. Falls back to the first location any
33
- * instance rendered with (stored on `window`) when Navigation Timing is
34
- * unavailable.
35
- */ function getInitialLocation(currentLocation) {
36
- try {
37
- var _performance_getEntriesByType = _sliced_to_array._(performance.getEntriesByType('navigation'), 1), entry = _performance_getEntriesByType[0];
38
- if (entry && entry.name) {
39
- var url = new URL(entry.name);
40
- return url.pathname + url.search;
41
- }
42
- } catch (e) {
43
- // Navigation Timing not available; fall through to the `window` fallback.
44
- }
45
- if (window[InstantSearchDocumentLocation] === undefined) {
46
- window[InstantSearchDocumentLocation] = currentLocation;
47
- }
48
- return window[InstantSearchDocumentLocation];
49
- }
50
- function isClientNavigation() {
51
- var currentLocation = window.location.pathname + window.location.search;
52
- return getInitialLocation(currentLocation) !== currentLocation;
53
- }
54
- function RefreshOnClientNavigation() {
55
- var search = (0, _reactinstantsearchcore.useInstantSearchContext)();
56
- var hasRefreshed = (0, _react.useRef)(false);
57
- (0, _react.useEffect)(function() {
58
- if (hasRefreshed.current) {
59
- return;
60
- }
61
- hasRefreshed.current = true;
62
- if (search.started && isClientNavigation()) {
63
- search.refresh();
64
- }
65
- }, [
66
- search
67
- ]);
68
- return null;
69
- }
@@ -1,28 +0,0 @@
1
- declare const InstantSearchDocumentLocation: unique symbol;
2
- declare global {
3
- interface Window {
4
- [InstantSearchDocumentLocation]?: string;
5
- }
6
- }
7
- /**
8
- * Whether the current location differs from the one the document was initially
9
- * loaded with — i.e. whether we reached this render through a client-side (SPA)
10
- * navigation rather than the initial hydration.
11
- */
12
- export declare function isClientNavigation(): boolean;
13
- /**
14
- * Refreshes the search after a client-side navigation.
15
- *
16
- * On a client-side navigation the App Router remounts `InstantSearchNext` with
17
- * the server-streamed `initialResults`, which can be empty (e.g. coming from a
18
- * page without InstantSearch) or stale, and the instance doesn't search again
19
- * on its own — leaving the new page with no or outdated hits until a full
20
- * reload (#7060). When we detect such a navigation we refresh the search so it
21
- * re-fetches with the (already correct) current UI state.
22
- *
23
- * Unlike re-running the router's `onUpdate`, `refresh()` doesn't touch the URL,
24
- * so it can't wipe the URL of a nested `<Index>` whose children only register
25
- * on a second render pass (#6980).
26
- */
27
- export declare function RefreshOnClientNavigation(): null;
28
- export {};
@@ -1,70 +0,0 @@
1
- import { _ } from '@swc/helpers/esm/_sliced_to_array.js';
2
- import { useRef, useEffect } from 'react';
3
- import { useInstantSearchContext } from 'react-instantsearch-core';
4
-
5
- // Fallback store for the first location an `InstantSearchNext` instance
6
- // rendered with, used only in environments without the Navigation Timing API
7
- // (e.g. jsdom in tests). See `getInitialLocation` below.
8
- var InstantSearchDocumentLocation = Symbol.for('InstantSearchDocumentLocation');
9
- /**
10
- * The `pathname` + `search` the document was initially loaded with.
11
- *
12
- * It comes from the Navigation Timing API, which reflects the hard page load
13
- * and is *not* affected by client-side (SPA) navigations. The hash is ignored
14
- * as it isn't part of the routing state. Falls back to the first location any
15
- * instance rendered with (stored on `window`) when Navigation Timing is
16
- * unavailable.
17
- */ function getInitialLocation(currentLocation) {
18
- try {
19
- var _performance_getEntriesByType = _(performance.getEntriesByType('navigation'), 1), entry = _performance_getEntriesByType[0];
20
- if (entry && entry.name) {
21
- var url = new URL(entry.name);
22
- return url.pathname + url.search;
23
- }
24
- } catch (e) {
25
- // Navigation Timing not available; fall through to the `window` fallback.
26
- }
27
- if (window[InstantSearchDocumentLocation] === undefined) {
28
- window[InstantSearchDocumentLocation] = currentLocation;
29
- }
30
- return window[InstantSearchDocumentLocation];
31
- }
32
- /**
33
- * Whether the current location differs from the one the document was initially
34
- * loaded with — i.e. whether we reached this render through a client-side (SPA)
35
- * navigation rather than the initial hydration.
36
- */ function isClientNavigation() {
37
- var currentLocation = window.location.pathname + window.location.search;
38
- return getInitialLocation(currentLocation) !== currentLocation;
39
- }
40
- /**
41
- * Refreshes the search after a client-side navigation.
42
- *
43
- * On a client-side navigation the App Router remounts `InstantSearchNext` with
44
- * the server-streamed `initialResults`, which can be empty (e.g. coming from a
45
- * page without InstantSearch) or stale, and the instance doesn't search again
46
- * on its own — leaving the new page with no or outdated hits until a full
47
- * reload (#7060). When we detect such a navigation we refresh the search so it
48
- * re-fetches with the (already correct) current UI state.
49
- *
50
- * Unlike re-running the router's `onUpdate`, `refresh()` doesn't touch the URL,
51
- * so it can't wipe the URL of a nested `<Index>` whose children only register
52
- * on a second render pass (#6980).
53
- */ function RefreshOnClientNavigation() {
54
- var search = useInstantSearchContext();
55
- var hasRefreshed = useRef(false);
56
- useEffect(function() {
57
- if (hasRefreshed.current) {
58
- return;
59
- }
60
- hasRefreshed.current = true;
61
- if (search.started && isClientNavigation()) {
62
- search.refresh();
63
- }
64
- }, [
65
- search
66
- ]);
67
- return null;
68
- }
69
-
70
- export { RefreshOnClientNavigation, isClientNavigation };