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

CustomSelectControl: Refactor to use Ariakit store state for current value #67815

Merged
merged 5 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

- `ResizableBox`: Make drag handles focusable ([#67305](https://github.com/WordPress/gutenberg/pull/67305)).
- `CustomSelectControl`: Update correctly when `showSelectedHint` is enabled ([#67733](https://github.com/WordPress/gutenberg/pull/67733)).
- `CustomSelectControl`: use `useStoreState` to get `currentValue` for optimistic updates ([#67815](https://github.com/WordPress/gutenberg/pull/67815))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
- `CustomSelectControl`: use `useStoreState` to get `currentValue` for optimistic updates ([#67815](https://github.com/WordPress/gutenberg/pull/67815))
- `CustomSelectControl`: Use `useStoreState` to get `currentValue` and avoid stale values ([#67815](https://github.com/WordPress/gutenberg/pull/67815)).

A minor suggestion. The optimistic updates refer to a different pattern, especially after the React 19 release.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion @Mamaduka. Fixed in the latest commit 🚀.


## 28.13.0 (2024-11-27)

Expand Down
6 changes: 3 additions & 3 deletions packages/components/src/custom-select-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,16 @@ function CustomSelectControl< T extends CustomSelectOption >(
);
} );

const { value: currentValue } = store.getState();
const currentValue = Ariakit.useStoreState( store, 'value' );

const renderSelectedValueHint = () => {
const selectedOptionHint = options
?.map( applyOptionDeprecations )
?.find( ( { name } ) => store.getState().value === name )?.hint;
?.find( ( { name } ) => currentValue === name )?.hint;

return (
<Styled.SelectedExperimentalHintWrapper>
{ store.getState().value }
{ currentValue }
{ selectedOptionHint && (
<Styled.SelectedExperimentalHintItem
// Keeping the classname for legacy reasons
Expand Down
Loading