Skip to content

Commit a255c5a

Browse files
authored
perf(combobox): fix initialization performance regression (#11265)
**Related Issue:** #10731 ## Summary #10952 increased the frequency of `combobox`'s item-updating logic. This improves performance by: * reducing the number of initial item update calls * debouncing the item update function to the next tick
1 parent f2217a1 commit a255c5a

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

packages/calcite-components/src/components/combobox-item/combobox-item.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ export class ComboboxItem extends LitElement implements InteractiveComponent {
166166
Please refactor your code to reduce the need for this check.
167167
Docs: https://qawebgis.esri.com/arcgis-components/?path=/docs/lumina-transition-from-stencil--docs#watching-for-property-changes */
168168
if (
169-
(changes.has("disabled") && (this.hasUpdated || this.disabled !== false)) ||
170-
(changes.has("selected") && (this.hasUpdated || this.selected !== false)) ||
171-
changes.has("textLabel")
169+
(changes.has("disabled") && this.hasUpdated) ||
170+
(changes.has("selected") && this.hasUpdated) ||
171+
(changes.has("textLabel") && this.hasUpdated)
172172
) {
173173
this.calciteInternalComboboxItemChange.emit();
174174
}

packages/calcite-components/src/components/combobox/combobox.tsx

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ export class Combobox
134134
item && filteredData.some(({ el }) => item === el);
135135

136136
return debounce((text: string, setOpenToEmptyState = false, emit = true): void => {
137-
const filteredData = filter([...this.data, ...this.groupData], text, this.effectiveFilterProps);
137+
const filteredData = filter(
138+
[...this.data, ...this.groupData],
139+
text,
140+
this.effectiveFilterProps,
141+
);
138142
const itemsAndGroups = this.getItemsAndGroups();
139143

140144
const matchAll = text === "";
@@ -551,7 +555,6 @@ export class Combobox
551555
this.internalValueChangeFlag = false;
552556
this.mutationObserver?.observe(this.el, { childList: true, subtree: true });
553557

554-
this.updateItems();
555558
this.setFilteredPlacements();
556559

557560
if (this.open) {
@@ -564,7 +567,6 @@ export class Combobox
564567

565568
async load(): Promise<void> {
566569
setUpLoadableComponent(this);
567-
this.updateItems();
568570
this.filterItems(this.filterText, false, false);
569571
}
570572

@@ -592,10 +594,7 @@ export class Combobox
592594
this.reposition(true);
593595
}
594596

595-
if (
596-
(changes.has("selectionMode") && (this.hasUpdated || this.selectionMode !== "multiple")) ||
597-
(changes.has("scale") && (this.hasUpdated || this.scale !== "m"))
598-
) {
597+
if (changes.has("selectionMode") || changes.has("scale")) {
599598
this.updateItems();
600599
}
601600

@@ -1233,7 +1232,7 @@ export class Combobox
12331232
return this.filterText === "" ? this.items : this.items.filter((item) => !item.hidden);
12341233
}
12351234

1236-
private updateItems(): void {
1235+
private updateItems = debounce((): void => {
12371236
this.items = this.getItems();
12381237
this.groupItems = this.getGroupItems();
12391238
this.data = this.getData();
@@ -1264,7 +1263,7 @@ export class Combobox
12641263
nextGroupItem.afterEmptyGroup = groupItem.children.length === 0;
12651264
}
12661265
});
1267-
}
1266+
}, DEBOUNCE.nextTick);
12681267

12691268
private getData(): ItemData[] {
12701269
return this.items.map((item) => ({

0 commit comments

Comments
 (0)