react-instantsearch-core 7.46.0 → 7.48.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.
@@ -12,12 +12,23 @@ Object.defineProperty(exports, "useChat", {
12
12
  var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
13
13
  var _object_spread = require("@swc/helpers/_/_object_spread");
14
14
  var _object_spread_props = require("@swc/helpers/_/_object_spread_props");
15
+ require("@swc/helpers/_/_type_of");
15
16
  var _connectChat = /*#__PURE__*/ _interop_require_default._(require("instantsearch.js/cjs/connectors/chat/connectChat"));
17
+ var _react = require("react");
16
18
  var _useConnector = require("../hooks/useConnector");
19
+ require("../lib/dequal");
17
20
  var _useIsHydrated = require("../lib/useIsHydrated");
21
+ var _useIsomorphicLayoutEffect = require("../lib/useIsomorphicLayoutEffect");
22
+ require("../lib/warn");
18
23
  function useChat(props, additionalWidgetProperties) {
19
24
  var isHydrated = (0, _useIsHydrated.useIsHydrated)();
25
+ (0, _react.useRef)(props);
26
+ (0, _react.useRef)(null);
27
+ (0, _useIsomorphicLayoutEffect.useIsomorphicLayoutEffect)(function() {
28
+ });
20
29
  var chatState = (0, _useConnector.useConnector)(_connectChat.default, props, additionalWidgetProperties);
30
+ (0, _useIsomorphicLayoutEffect.useIsomorphicLayoutEffect)(function() {
31
+ });
21
32
  if (isHydrated) {
22
33
  return chatState;
23
34
  }
@@ -55,22 +55,18 @@ function useWidget(param) {
55
55
  clearTimeout(cleanupTimerRef.current);
56
56
  // Warning: if an unstable function prop is provided, `dequal` is not able
57
57
  // to keep its reference and therefore will consider that props did change.
58
- // This could unsollicitely remove/add the widget, therefore forget its state,
59
- // and could be a source of confusion.
58
+ // This unintentionally replaces the widget, which is wasteful (it causes
59
+ // a search), even though `updateWidget` below keeps its state.
60
60
  // If users face this issue, we should advise them to provide stable function
61
61
  // references.
62
62
  var arePropsEqual = (0, _dequal.dequal)(props, prevPropsRef.current);
63
- // If props did change, then we execute the cleanup function instantly
64
- // and then add the widget back. This lets us add the widget without
63
+ // If props did change, then we replace the widget instantly instead of
65
64
  // waiting for the scheduled cleanup function to finish (that we canceled
66
- // above).
65
+ // above). `updateWidget` hands the previous widget's `uiState` over to the
66
+ // new one, so that a parameter change doesn't reset the state the widget
67
+ // still owns — which would otherwise break routing.
67
68
  if (!arePropsEqual) {
68
- parentIndex.removeWidgets([
69
- previousWidget
70
- ]);
71
- parentIndex.addWidgets([
72
- widget
73
- ]);
69
+ parentIndex.updateWidget(previousWidget, widget);
74
70
  }
75
71
  }
76
72
  return function() {
@@ -9,4 +9,4 @@ Object.defineProperty(exports, "default", {
9
9
  return _default;
10
10
  }
11
11
  });
12
- var _default = '7.46.0';
12
+ var _default = '7.48.0';
@@ -1,12 +1,21 @@
1
1
  import { _ as _$1 } from '@swc/helpers/esm/_object_spread.js';
2
2
  import { _ } from '@swc/helpers/esm/_object_spread_props.js';
3
+ import '@swc/helpers/esm/_type_of.js';
3
4
  import connectChat from 'instantsearch.js/es/connectors/chat/connectChat.js';
5
+ import { useRef } from 'react';
4
6
  import { useConnector } from '../hooks/useConnector.js';
5
7
  import { useIsHydrated } from '../lib/useIsHydrated.js';
8
+ import { useIsomorphicLayoutEffect } from '../lib/useIsomorphicLayoutEffect.js';
6
9
 
7
10
  function useChat(props, additionalWidgetProperties) {
8
11
  var isHydrated = useIsHydrated();
12
+ useRef(props);
13
+ useRef(null);
14
+ useIsomorphicLayoutEffect(function() {
15
+ });
9
16
  var chatState = useConnector(connectChat, props, additionalWidgetProperties);
17
+ useIsomorphicLayoutEffect(function() {
18
+ });
10
19
  if (isHydrated) {
11
20
  return chatState;
12
21
  }
@@ -44,22 +44,18 @@ function useWidget(param) {
44
44
  clearTimeout(cleanupTimerRef.current);
45
45
  // Warning: if an unstable function prop is provided, `dequal` is not able
46
46
  // to keep its reference and therefore will consider that props did change.
47
- // This could unsollicitely remove/add the widget, therefore forget its state,
48
- // and could be a source of confusion.
47
+ // This unintentionally replaces the widget, which is wasteful (it causes
48
+ // a search), even though `updateWidget` below keeps its state.
49
49
  // If users face this issue, we should advise them to provide stable function
50
50
  // references.
51
51
  var arePropsEqual = dequal(props, prevPropsRef.current);
52
- // If props did change, then we execute the cleanup function instantly
53
- // and then add the widget back. This lets us add the widget without
52
+ // If props did change, then we replace the widget instantly instead of
54
53
  // waiting for the scheduled cleanup function to finish (that we canceled
55
- // above).
54
+ // above). `updateWidget` hands the previous widget's `uiState` over to the
55
+ // new one, so that a parameter change doesn't reset the state the widget
56
+ // still owns — which would otherwise break routing.
56
57
  if (!arePropsEqual) {
57
- parentIndex.removeWidgets([
58
- previousWidget
59
- ]);
60
- parentIndex.addWidgets([
61
- widget
62
- ]);
58
+ parentIndex.updateWidget(previousWidget, widget);
63
59
  }
64
60
  }
65
61
  return function() {
@@ -1,2 +1,2 @@
1
- declare const _default: "7.46.0";
1
+ declare const _default: "7.48.0";
2
2
  export default _default;
@@ -1,3 +1,3 @@
1
- var version = '7.46.0';
1
+ var version = '7.48.0';
2
2
 
3
3
  export { version as default };