Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(combobox, input-time-zone): fix initial item selection delay #11326

Open
wants to merge 12 commits into
base: dev
Choose a base branch
from

Conversation

jcfranco
Copy link
Member

@jcfranco jcfranco commented Jan 17, 2025

Related Issue: #10731

Summary

Fixes a combobox regression introduced by #11265 without impacting performance.

Notable changes

  • drops debouncing of
    • item update (initial update delay was the main cause of regression)
    • change event emitting
  • adds more test coverage for change event emitting
  • ignores item-initiated updates until combobox is loaded
  • splits up item update logic into the following sections to minimize re-renders:
    • item/data
    • item props
    • selection/filter
    • minor tidy up

@github-actions github-actions bot added the bug Bug reports for broken functionality. Issues should include a reproduction of the bug. label Jan 17, 2025
@jcfranco jcfranco requested review from driskull and benelan January 17, 2025 08:48
@jcfranco jcfranco added the pr ready for visual snapshots Adding this label will run visual snapshot testing. label Jan 17, 2025
Copy link
Member

@driskull driskull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -119,7 +115,9 @@ export class Combobox

defaultValue: Combobox["value"];

private emitComboboxChange = debounce(this.internalComboboxChangeEvent, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@@ -1229,15 +1229,19 @@ export class Combobox
return this.filterText === "" ? this.items : this.items.filter((item) => !item.hidden);
}

private updateItems = debounce((): void => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we still debounce this in some cases? Like the mutation observer case?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could keep an eye out for this. The MO callback kicks in once per batch of mutations, so I don't expect a significant increase in updateItem calls.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. We may want to have some internal doc/guidelines on when we should debounce a function and under what circumstances.

Comment on lines 659 to 665
this.getItems().forEach((item) => {
item.selected = Array.isArray(value)
? value.includes(item.value)
: value
? value === item.value
: false;
});

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.getItems().forEach((item) => {
item.selected = Array.isArray(value)
? value.includes(item.value)
: value
? value === item.value
: false;
});
for (const item of this.getItems()) {
item.selected = (Array.isArray(value) && value.includes(item.value)) ||
(!Array.isArray(value) && value === item.value);
}

@jcfranco
Copy link
Member Author

I noticed some diffs on the initial render. Looking into this.

@jcfranco jcfranco added pr ready for visual snapshots Adding this label will run visual snapshot testing. and removed pr ready for visual snapshots Adding this label will run visual snapshot testing. labels Jan 17, 2025
@jcfranco jcfranco added pr ready for visual snapshots Adding this label will run visual snapshot testing. and removed pr ready for visual snapshots Adding this label will run visual snapshot testing. labels Jan 18, 2025
@jcfranco jcfranco added pr ready for visual snapshots Adding this label will run visual snapshot testing. and removed pr ready for visual snapshots Adding this label will run visual snapshot testing. labels Jan 18, 2025
@jcfranco jcfranco added pr ready for visual snapshots Adding this label will run visual snapshot testing. and removed pr ready for visual snapshots Adding this label will run visual snapshot testing. labels Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug reports for broken functionality. Issues should include a reproduction of the bug. pr ready for visual snapshots Adding this label will run visual snapshot testing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants