-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
SuggestionList: use requestAnimationFrame instead of setTimeout when scrolling selected item into view #44573
Conversation
if ( id !== undefined ) { | ||
window.clearTimeout( id ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure there's a point in running cancelAnimationFrame
in the effect's return function, and so for now I've avoided it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't get a chance to review properly today, unfortunately, but hopefully should get a bit more time next week once some things for 6.1 Beta 3 are ready.
From a quick skim of the failing unit test, though, it's reporting:
["Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in %s.%s", "a useEffect cleanup function", "
Is that warning showing up because the requestAnimationFrame
is still firing? If so, I wonder if we might need to grab the id returned from requestAnimationFrame
and call cancelAnimationFrame
so that it doesn't attempt to update state after unmounting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense! Done in 566b233
1b615ec
to
566b233
Compare
Hey @andrewserong , would you mind giving this another round of review? Thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your patience, and for the reminder ping @ciampo! This is all testing nicely for me in Chrome, FF, Safari, and Edge on Mac. I tested in Storybook, and using the parent page selector in a test site with a large number of pages.
✅ Suggestions are now highlighted in a responsive manner
✅ Hovering over an item, and then blurring the field, and then selecting the drop-down again correctly returns the scroll position to the previously hovered item
✅ Hovering over a partially visible item at the bottom of the list scrolls it into view
✅ Double-checked that the scrollView
function from dom-scroll-into-view
appears to attempt to scroll immediately (i.e. doesn't use smooth scroll) here, so using requestAnimationFrame
seems safe to me 👍
Before | After |
---|---|
This LGTM! ✨
I believe this PR will need a rebase in order to land. I kicked off the failing e2e, but it looks like it needs this commit (3983fee) in order to pass, now that the 6.1 RC 1 has been released.
Thanks again for the follow-up!
…scrolling selected item into view
566b233
to
8f71327
Compare
Thank you Andrew for the thorough review! I've just rebased, will merge once CI is ✅ |
What?
As originally flagged by @andrewserong in #44526 (review), currently
SuggestionList
(used in theComboboxControl
andFormTokenField
components) uses a 100ms timeout when scrolling selected list items into view. This timeout causes the UI to be very unresponsive when hovering over the list of suggestions.This PR swaps the
setTimeout
call with arequestAnimationFrame
call, in order to minimize the delay while keeping the "scroll into view" logic unchanged.Why?
Make out UI smoother and more pleasant to interact with
How?
Swap the
setTimeout
call with arequestAnimationFrame
call, in order to minimize the delay while keeping the "scroll into view" logic unchanged.Testing Instructions
On
ComboboxControl
:trunk
)trunk
as wellScreenshots or screencast
trunk
:combobox-control-timeout-trunk.mp4
This PR:
combobox-control-timeout-PR.mp4