@homebound/beam 2.343.1 → 2.343.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.
@@ -1,4 +1,7 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.disabledOptionToKeyedTuple = exports.unsetOption = exports.initializeOptions = exports.ComboBoxBase = void 0;
4
7
  const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
@@ -14,6 +17,7 @@ const ListBox_1 = require("./ListBox");
14
17
  const Value_1 = require("../Value");
15
18
  const utils_1 = require("../utils");
16
19
  const use_debounce_1 = require("use-debounce");
20
+ const fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
17
21
  /**
18
22
  * Provides a non-native select/dropdown widget that allows the user to type to filter the options.
19
23
  *
@@ -48,8 +52,17 @@ function ComboBoxBase(props) {
48
52
  // eslint-disable-next-line react-hooks/exhaustive-deps
49
53
  Array.isArray(propOptions) ? [propOptions, unsetLabel] : [propOptions.current, propOptions.options, unsetLabel]);
50
54
  const values = (0, react_1.useMemo)(() => propValues !== null && propValues !== void 0 ? propValues : [], [propValues]);
55
+ const selectedOptionsRef = (0, react_1.useRef)(options.filter((o) => values.includes(getOptionValue(o))));
51
56
  const selectedOptions = (0, react_1.useMemo)(() => {
52
- return options.filter((o) => values.includes(getOptionValue(o)));
57
+ // `selectedOptions` should only ever update if the `values` prop actually change.
58
+ // Assuming `values` is a state variable, then it should hold its identity until it _really_ changes.
59
+ // Though, it is possible that the `options` prop has changed, which is a dependency on this `useMemo`.
60
+ // That could trigger an unnecessary new reference for `selectedOptions`, and cause additional renders or unexpected state changes.
61
+ // We should avoid updating `selectedOptions` unless `values` has actually changed.
62
+ if (!(0, fast_deep_equal_1.default)(values.sort(), selectedOptionsRef.current.map(getOptionValue).sort())) {
63
+ selectedOptionsRef.current = options.filter((o) => values.includes(getOptionValue(o)));
64
+ }
65
+ return selectedOptionsRef.current;
53
66
  }, [options, values, getOptionValue]);
54
67
  const { contains } = (0, react_aria_1.useFilter)({ sensitivity: "base" });
55
68
  const isDisabled = !!disabled;
@@ -170,8 +183,6 @@ function ComboBoxBase(props) {
170
183
  const [debouncedSearch] = (0, use_debounce_1.useDebounce)(searchValue, 300);
171
184
  // Reset inputValue when closed or selected changes
172
185
  (0, react_1.useEffect)(() => {
173
- if (debouncedSearch)
174
- return;
175
186
  if (state.isOpen && multiselect) {
176
187
  // While the multiselect is open, let the user keep typing
177
188
  setFieldState((prevState) => ({
@@ -187,7 +198,7 @@ function ComboBoxBase(props) {
187
198
  inputValue: getInputValue(selectedOptions, getOptionLabel, multiselect, nothingSelectedText, isReadOnly),
188
199
  }));
189
200
  }
190
- }, [state.isOpen, selectedOptions, getOptionLabel, multiselect, nothingSelectedText, isReadOnly, debouncedSearch]);
201
+ }, [state.isOpen, selectedOptions, getOptionLabel, multiselect, nothingSelectedText, isReadOnly]);
191
202
  // Call on search callback when the user types in the input field
192
203
  (0, react_1.useEffect)(() => {
193
204
  onSearch === null || onSearch === void 0 ? void 0 : onSearch(debouncedSearch !== null && debouncedSearch !== void 0 ? debouncedSearch : "");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebound/beam",
3
- "version": "2.343.1",
3
+ "version": "2.343.2",
4
4
  "author": "Homebound",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",