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: Refactor ComboBoxBase to memo more #964

Merged
merged 1 commit into from
Oct 12, 2023
Merged

Conversation

stephenh
Copy link
Contributor

@stephenh stephenh commented Oct 11, 2023

Marking this as a "fix" to get it released, but it's really a chore/no change refactoring.

After working on the "current/load/options" refactoring, I pulled the thread a little bit on useMemo-ing things like getOptionLabel, getOptionValue.

And then also noticed that, AFAICT, ~3-4 keys in the FieldState that were manually set in multiple places could, again AFAICT, be derived with useMemos.

So that's what this does.

@stephenh stephenh force-pushed the refactor-combo-state branch 2 times, most recently from e82ca05 to 26f37c1 Compare October 11, 2023 05:07
@stephenh stephenh changed the title wip fix: Refactor ComboBoxBase to memo more Oct 11, 2023
const r = await render(
<SelectField
label="label"
value={true}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before this refactoring, this value could stay hard-coded and ComboBoxBase had its own internal version of values that could drift from the value prop.

But now, kinda on accident but I think it makes sense, the internal value is always derived from the value prop, so it behaves more like a controlled component.

Which is fine, afaict not a breaking change, but meant these tests that were hard-coding value=true needed to change.

),
filteredOptions: options,
allOptions: options,
selectedOptions,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

filteredOptiosn, allOptions, and selectedOptions, and selectedKeys are now all derived from the useMemo-d options / values or what not.

// eslint-disable-next-line react-hooks/exhaustive-deps
[options],
);
// Reset inputValue when closed or selected changes
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Kinda surprised, this useEffect ends up being a pretty cute place to handle resetting inputValue as various conditions change.

@stephenh stephenh force-pushed the refactor-combo-state branch from 26f37c1 to 35ef286 Compare October 11, 2023 16:40
@stephenh stephenh marked this pull request as ready for review October 11, 2023 16:40
Comment on lines +374 to +376
// We need separate `searchValue` vs. `inputValue` b/c we might be showing the
// currently-loaded option in the input, without the user having typed a filter yet.
searchValue: string | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

praise: Nice, that does help keep this a bit cleaner

@stephenh stephenh merged commit f1329f6 into main Oct 12, 2023
1 check passed
@stephenh stephenh deleted the refactor-combo-state branch October 12, 2023 17:58
homebound-team-bot pushed a commit that referenced this pull request Oct 12, 2023
## [2.321.1](v2.321.0...v2.321.1) (2023-10-12)

### Bug Fixes

* Refactor ComboBoxBase to memo more ([#964](#964)) ([f1329f6](f1329f6))
@homebound-team-bot
Copy link

🎉 This PR is included in version 2.321.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants