Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork1.2k
Ensure--button-width
and--input-width
are always up to date#3786
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Ideally we can listen to some sort of event (via ResizeObserver), but aResizeObserver doesn't see visual changes in width when using the`scale` property.As far as I can tell there doesn't exist any event or observer we canuse to watch for changes in the bounding client rect of an element.This fixes that by introducing a requestAnimationFrame loop. To make itsomewhat efficient, we will make sure to:1. Only run them when the hook is enabled (see previous commit). This allows us to only run this code when a Listbox or Menu is open for example.2. As long as the size doesn't change, we won't trigger a re-render.
vercelbot commentedSep 8, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
The latest updates on your projects. Learn more aboutVercel for GitHub.
|
c9bf352
intomain 8 checks passed
Uh oh!
There was an error while loading.Please reload this page.
This was referencedSep 8, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes an issue where the
--button-width
and--input-width
CSS variables weren't always up to date.We compute these values initially when the component mounts based on the
getBoundingClientRect
of the button and input elements.To ensure we catch changes in size, we setup a
ResizeObserver
that watches for changes to the button and input elements.Unfortunately,
ResizeObserver
doesn't fire when the size changes due to CSS properties such astransform
orscale
. As far as I can tell, there isn't a single event or Observer we can use to catch all possible changes.One solution to this problem would be to delay the computation of the sizes until after all transitions have completed and then we could even introduce a small delay to ensure everything is in its final state.
However, you could literally use
hover:scale-110
on the Listbox button which would mean that the size changes whenever you hover over the button.To fix this in a more generic way, we setup a
requestAnimationFrame
loop that checks the size of the button and input elements on each frame. If the size has changed, we update the CSS variables.Note: we will only re-render if the size has actually changed, so this shouldn't cause unnecessary re-renders.
The internal hook we use (
useElementSize
) also now receives anenabled
option such that we only run thisrequestAnimationFrame
loop when the component is enabled.For components such as the
Combobox
,Listbox
andMenu
that means that we only start measuring when the corresponding dropdown is in an open state.Hopefully we can fix this kind of issue with an Observer in the future (e.g.:
PerformanceObserver
withLayoutShift
(https://developer.mozilla.org/en-US/docs/Web/API/LayoutShift)) but this is still experimental today.Fixes:#3612
Fixes:#3598