Skip to content

Conversation

RobinMalfait
Copy link
Member

This PR fixes an issue where the changing the immediate prop value on the Combobox component didn't always reflect in the expected behavior, but only after other state changed.

This was a useMemo dependency issue. I also added a new useSlot internal hook that ensures the value and dependency array is always up to date since we don't really care about optimizing the slot values but we just want a stable reference back instead.

Fixes: #3659

This is just a small wrapper around `useMemo` with the only goal of
getting a stable object out unless an value in the object changes.

We are not using the `useMemo` hook to optimize expensive calculations
at all.

This hook has 2 benefits:

1. Type safe — you will get a type error if you are missing some property (or add one that shouldn't exist)
2. The dependencies array is always properly up to date based on the values of the object. We rely on `Object.values` returning the values in the same order.
We were using separate variables to make the object key and dependency
value of `useMemo` a bit easier but that's not necessary anymore.
Copy link

vercel bot commented Sep 12, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
headlessui-react Ready Ready Preview Comment Sep 12, 2025 2:25pm
headlessui-vue Ready Ready Preview Comment Sep 12, 2025 2:25pm

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

Successfully merging this pull request may close these issues.

immediate prop does not work well in React 18.2
1 participant