react-instantsearch-core 7.41.0 → 7.42.0

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.
@@ -10,8 +10,34 @@ Object.defineProperty(exports, "useChat", {
10
10
  }
11
11
  });
12
12
  var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
13
+ var _object_spread = require("@swc/helpers/_/_object_spread");
14
+ var _object_spread_props = require("@swc/helpers/_/_object_spread_props");
13
15
  var _connectChat = /*#__PURE__*/ _interop_require_default._(require("instantsearch.js/cjs/connectors/chat/connectChat"));
14
16
  var _useConnector = require("../hooks/useConnector");
17
+ var _useIsHydrated = require("../lib/useIsHydrated");
15
18
  function useChat(props, additionalWidgetProperties) {
16
- return (0, _useConnector.useConnector)(_connectChat.default, props, additionalWidgetProperties);
19
+ var isHydrated = (0, _useIsHydrated.useIsHydrated)();
20
+ var chatState = (0, _useConnector.useConnector)(_connectChat.default, props, additionalWidgetProperties);
21
+ if (isHydrated) {
22
+ return chatState;
23
+ }
24
+ // Server rendering only promises the closed Chat shell, so a render that has
25
+ // to reproduce that markup shows no conversation either. `status` is pinned
26
+ // with `messages` because it diverges two ways: a server render suppresses
27
+ // `resumeStream()`, which the browser runs synchronously while initialising,
28
+ // and a caller-owned chat can already be streaming. `error` is pinned because
29
+ // a caller-owned chat can already have failed, which a connector-built one
30
+ // cannot, since its failures arrive in a microtask. `suggestions` is pinned
31
+ // because the connector derives them from those messages. Only an `id` given
32
+ // as a connector option passes through, because that value is the same on
33
+ // both sides. Anything else is withheld: the default is random per Chat, and
34
+ // an `id` carried by a caller-owned instance is no safer, since the server and
35
+ // the browser each construct their own.
36
+ return _object_spread_props._(_object_spread._({}, chatState), {
37
+ error: undefined,
38
+ id: 'id' in props && props.id || '',
39
+ messages: [],
40
+ status: 'ready',
41
+ suggestions: undefined
42
+ });
17
43
  }
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "usePromptSuggestions", {
7
+ enumerable: true,
8
+ get: function() {
9
+ return usePromptSuggestions;
10
+ }
11
+ });
12
+ var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
13
+ var _connectPromptSuggestions = /*#__PURE__*/ _interop_require_default._(require("instantsearch.js/cjs/connectors/prompt-suggestions/connectPromptSuggestions"));
14
+ var _useConnector = require("../hooks/useConnector");
15
+ function usePromptSuggestions(props, additionalWidgetProperties) {
16
+ return (0, _useConnector.useConnector)(_connectPromptSuggestions.default, props, additionalWidgetProperties);
17
+ }
package/dist/cjs/index.js CHANGED
@@ -22,6 +22,7 @@ _export_star._(require("./components/InstantSearchSSRProvider"), exports);
22
22
  _export_star._(require("./connectors/useAutocomplete"), exports);
23
23
  _export_star._(require("./connectors/useBreadcrumb"), exports);
24
24
  _export_star._(require("./connectors/useChat"), exports);
25
+ _export_star._(require("./connectors/usePromptSuggestions"), exports);
25
26
  _export_star._(require("./connectors/useChatTrigger"), exports);
26
27
  _export_star._(require("./connectors/useClearRefinements"), exports);
27
28
  _export_star._(require("./connectors/useConfigure"), exports);
@@ -0,0 +1,51 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "useIsHydrated", {
7
+ enumerable: true,
8
+ get: function() {
9
+ return useIsHydrated;
10
+ }
11
+ });
12
+ var _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
13
+ var _sliced_to_array = require("@swc/helpers/_/_sliced_to_array");
14
+ var _react = /*#__PURE__*/ _interop_require_wildcard._(require("react"));
15
+ var _useInstantSearchServerContext = require("./useInstantSearchServerContext");
16
+ var _useInstantSearchSSRContext = require("./useInstantSearchSSRContext");
17
+ var subscribe = function subscribe() {
18
+ return function() {};
19
+ };
20
+ var getClientSnapshot = function getClientSnapshot() {
21
+ return true;
22
+ };
23
+ var getServerSnapshot = function getServerSnapshot() {
24
+ return false;
25
+ };
26
+ function useNativeIsHydrated() {
27
+ return _react.useSyncExternalStore(subscribe, getClientSnapshot, getServerSnapshot);
28
+ }
29
+ // React 16 and 17 have no `useSyncExternalStore`, so the flip waits for an
30
+ // effect and the render itself cannot tell hydration from a plain mount. These
31
+ // contexts provide that signal for the supported `getServerState` and
32
+ // `InstantSearchSSRProvider` flow: the server context covers state collection,
33
+ // and the SSR context covers HTML rendering and hydration.
34
+ //
35
+ // This can cost an extra render: a mount inside a provider that carries server
36
+ // state is withheld once even when there is no server markup to reproduce. A
37
+ // mount outside both contexts is never withheld.
38
+ //
39
+ // The shim's React 16 and 17 fallback ignores the server snapshot, so using it
40
+ // here would not change this limitation.
41
+ function useLegacyIsHydrated() {
42
+ var serverContext = (0, _useInstantSearchServerContext.useInstantSearchServerContext)();
43
+ var ssrContext = (0, _useInstantSearchSSRContext.useInstantSearchSSRContext)();
44
+ var isServerRendered = serverContext !== null || ssrContext !== null;
45
+ var _React_useState = _sliced_to_array._(_react.useState(!isServerRendered), 2), isHydrated = _React_useState[0], setIsHydrated = _React_useState[1];
46
+ _react.useEffect(function() {
47
+ setIsHydrated(true);
48
+ }, []);
49
+ return isHydrated;
50
+ }
51
+ var useIsHydrated = typeof _react.useSyncExternalStore === 'function' ? useNativeIsHydrated : useLegacyIsHydrated;
@@ -9,4 +9,4 @@ Object.defineProperty(exports, "default", {
9
9
  return _default;
10
10
  }
11
11
  });
12
- var _default = '7.41.0';
12
+ var _default = '7.42.0';
@@ -1,5 +1,5 @@
1
1
  import type { AdditionalWidgetProperties } from '../hooks/useConnector';
2
- import type { ChatConnectorParams } from 'instantsearch.js/es/connectors/chat/connectChat';
2
+ import type { ChatConnectorParams, ChatWidgetDescription } from 'instantsearch.js/es/connectors/chat/connectChat';
3
3
  import type { UIMessage } from 'instantsearch.js/es/lib/chat';
4
4
  export type UseChatProps<TUiMessage extends UIMessage = UIMessage> = ChatConnectorParams<TUiMessage>;
5
- export declare function useChat<TUiMessage extends UIMessage = UIMessage>(props: UseChatProps<TUiMessage>, additionalWidgetProperties?: AdditionalWidgetProperties): import("instantsearch.js/es/connectors/chat/connectChat").ChatRenderState<TUiMessage>;
5
+ export declare function useChat<TUiMessage extends UIMessage = UIMessage>(props: UseChatProps<TUiMessage>, additionalWidgetProperties?: AdditionalWidgetProperties): ChatWidgetDescription<TUiMessage>['renderState'];
@@ -1,8 +1,34 @@
1
+ import { _ as _$1 } from '@swc/helpers/esm/_object_spread.js';
2
+ import { _ } from '@swc/helpers/esm/_object_spread_props.js';
1
3
  import connectChat from 'instantsearch.js/es/connectors/chat/connectChat.js';
2
4
  import { useConnector } from '../hooks/useConnector.js';
5
+ import { useIsHydrated } from '../lib/useIsHydrated.js';
3
6
 
4
7
  function useChat(props, additionalWidgetProperties) {
5
- return useConnector(connectChat, props, additionalWidgetProperties);
8
+ var isHydrated = useIsHydrated();
9
+ var chatState = useConnector(connectChat, props, additionalWidgetProperties);
10
+ if (isHydrated) {
11
+ return chatState;
12
+ }
13
+ // Server rendering only promises the closed Chat shell, so a render that has
14
+ // to reproduce that markup shows no conversation either. `status` is pinned
15
+ // with `messages` because it diverges two ways: a server render suppresses
16
+ // `resumeStream()`, which the browser runs synchronously while initialising,
17
+ // and a caller-owned chat can already be streaming. `error` is pinned because
18
+ // a caller-owned chat can already have failed, which a connector-built one
19
+ // cannot, since its failures arrive in a microtask. `suggestions` is pinned
20
+ // because the connector derives them from those messages. Only an `id` given
21
+ // as a connector option passes through, because that value is the same on
22
+ // both sides. Anything else is withheld: the default is random per Chat, and
23
+ // an `id` carried by a caller-owned instance is no safer, since the server and
24
+ // the browser each construct their own.
25
+ return _(_$1({}, chatState), {
26
+ error: undefined,
27
+ id: 'id' in props && props.id || '',
28
+ messages: [],
29
+ status: 'ready',
30
+ suggestions: undefined
31
+ });
6
32
  }
7
33
 
8
34
  export { useChat };
@@ -0,0 +1,4 @@
1
+ import type { AdditionalWidgetProperties } from '../hooks/useConnector';
2
+ import type { PromptSuggestionsConnectorParams } from 'instantsearch.js/es/connectors/prompt-suggestions/connectPromptSuggestions';
3
+ export type UsePromptSuggestionsProps = PromptSuggestionsConnectorParams;
4
+ export declare function usePromptSuggestions(props: UsePromptSuggestionsProps, additionalWidgetProperties?: AdditionalWidgetProperties): import("instantsearch.js/es/connectors/prompt-suggestions/connectPromptSuggestions").PromptSuggestionsRenderState;
@@ -0,0 +1,8 @@
1
+ import connectPromptSuggestions from 'instantsearch.js/es/connectors/prompt-suggestions/connectPromptSuggestions.js';
2
+ import { useConnector } from '../hooks/useConnector.js';
3
+
4
+ function usePromptSuggestions(props, additionalWidgetProperties) {
5
+ return useConnector(connectPromptSuggestions, props, additionalWidgetProperties);
6
+ }
7
+
8
+ export { usePromptSuggestions };
@@ -9,6 +9,7 @@ export * from './components/InstantSearchSSRProvider';
9
9
  export * from './connectors/useAutocomplete';
10
10
  export * from './connectors/useBreadcrumb';
11
11
  export * from './connectors/useChat';
12
+ export * from './connectors/usePromptSuggestions';
12
13
  export * from './connectors/useChatTrigger';
13
14
  export * from './connectors/useClearRefinements';
14
15
  export * from './connectors/useConfigure';
package/dist/es/index.js CHANGED
@@ -9,6 +9,7 @@ export { InstantSearchSSRProvider } from './components/InstantSearchSSRProvider.
9
9
  export { useAutocomplete } from './connectors/useAutocomplete.js';
10
10
  export { useBreadcrumb } from './connectors/useBreadcrumb.js';
11
11
  export { useChat } from './connectors/useChat.js';
12
+ export { usePromptSuggestions } from './connectors/usePromptSuggestions.js';
12
13
  export { useChatTrigger } from './connectors/useChatTrigger.js';
13
14
  export { useClearRefinements } from './connectors/useClearRefinements.js';
14
15
  export { useConfigure } from './connectors/useConfigure.js';
@@ -1,5 +1,5 @@
1
- import type { InstantSearchServerState } from '../components/InstantSearchSSRProvider';
2
1
  import type { InternalInstantSearch } from './useInstantSearchApi';
2
+ import type { InstantSearchServerState } from '../components/InstantSearchSSRProvider';
3
3
  import type { UiState } from 'instantsearch.js';
4
4
  import type { MutableRefObject } from 'react';
5
5
  export type InstantSearchSSRContextApi<TUiState extends UiState, TRouteState = TUiState> = InstantSearchServerState & {
@@ -0,0 +1,9 @@
1
+ declare function useNativeIsHydrated(): boolean;
2
+ /**
3
+ * Whether this render can use browser state, or has to reproduce the markup a
4
+ * server produced without it.
5
+ *
6
+ * @internal
7
+ */
8
+ export declare const useIsHydrated: typeof useNativeIsHydrated;
9
+ export {};
@@ -0,0 +1,47 @@
1
+ import { _ } from '@swc/helpers/esm/_sliced_to_array.js';
2
+ import * as React from 'react';
3
+ import { useInstantSearchServerContext } from './useInstantSearchServerContext.js';
4
+ import { useInstantSearchSSRContext } from './useInstantSearchSSRContext.js';
5
+
6
+ var subscribe = function subscribe() {
7
+ return function() {};
8
+ };
9
+ var getClientSnapshot = function getClientSnapshot() {
10
+ return true;
11
+ };
12
+ var getServerSnapshot = function getServerSnapshot() {
13
+ return false;
14
+ };
15
+ function useNativeIsHydrated() {
16
+ return React.useSyncExternalStore(subscribe, getClientSnapshot, getServerSnapshot);
17
+ }
18
+ // React 16 and 17 have no `useSyncExternalStore`, so the flip waits for an
19
+ // effect and the render itself cannot tell hydration from a plain mount. These
20
+ // contexts provide that signal for the supported `getServerState` and
21
+ // `InstantSearchSSRProvider` flow: the server context covers state collection,
22
+ // and the SSR context covers HTML rendering and hydration.
23
+ //
24
+ // This can cost an extra render: a mount inside a provider that carries server
25
+ // state is withheld once even when there is no server markup to reproduce. A
26
+ // mount outside both contexts is never withheld.
27
+ //
28
+ // The shim's React 16 and 17 fallback ignores the server snapshot, so using it
29
+ // here would not change this limitation.
30
+ function useLegacyIsHydrated() {
31
+ var serverContext = useInstantSearchServerContext();
32
+ var ssrContext = useInstantSearchSSRContext();
33
+ var isServerRendered = serverContext !== null || ssrContext !== null;
34
+ var _React_useState = _(React.useState(!isServerRendered), 2), isHydrated = _React_useState[0], setIsHydrated = _React_useState[1];
35
+ React.useEffect(function() {
36
+ setIsHydrated(true);
37
+ }, []);
38
+ return isHydrated;
39
+ }
40
+ /**
41
+ * Whether this render can use browser state, or has to reproduce the markup a
42
+ * server produced without it.
43
+ *
44
+ * @internal
45
+ */ var useIsHydrated = typeof React.useSyncExternalStore === 'function' ? useNativeIsHydrated : useLegacyIsHydrated;
46
+
47
+ export { useIsHydrated };
@@ -1,2 +1,2 @@
1
- declare const _default: "7.41.0";
1
+ declare const _default: "7.42.0";
2
2
  export default _default;
@@ -1,3 +1,3 @@
1
- var version = '7.41.0';
1
+ var version = '7.42.0';
2
2
 
3
3
  export { version as default };