feat(react-virtualizer): Add improved scrollTo with iterative corrections for dynamic lists #573
+1,072
−64
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.
Description
This PR introduces an improved
scrollToimplementation forVirtualizerScrollViewDynamicthat handles dynamically sized items more accurately. The new behavior is opt-in via theenableScrollToCorrectionsprop to ensure backward compatibility.Problem
When using
scrollTowith dynamically sized items in virtualized lists, the target element could end up misaligned or outside the viewport because:Current behavior: The scrollTo function does not navigate to the correct position.
https://microsoft.github.io/fluentui-contrib/react-virtualizer/?path=/story/packages-react-virtualizer-virtualizerscrollviewdynamic--scroll-to
Screen.Recording.2025-12-03.at.16.13.00.mov
Solution
Added a new
useScrollToItemDynamichook that provides:Screen.Recording.2025-12-03.at.16.14.41.mov
Changes
New Files
packages/react-virtualizer/src/hooks/useScrollToItemDynamic.ts- New hook for managing scroll-to operations with correctionsModified Files
packages/react-virtualizer/src/hooks/useMeasureList.ts- AddedonItemMeasuredcallback parameterpackages/react-virtualizer/src/components/VirtualizerScrollViewDynamic/useVirtualizerScrollViewDynamic.tsx- Integrated new hook with opt-in behaviorpackages/react-virtualizer/src/components/VirtualizerScrollViewDynamic/VirtualizerScrollViewDynamic.types.ts- AddedenableScrollToCorrectionsproppackages/react-virtualizer/stories/VirtualizerScrollViewDynamic/ScrollTo.stories.tsx- Updated story to demonstrate new behaviorUsage
API
New Prop:
enableScrollToCorrectionsenableScrollToCorrectionsbooleanfalseWhen disabled (default): Uses legacy
scrollToItemDynamic- existing behavior unchanged.When enabled: Uses
useScrollToItemDynamichook which provides:useMeasureListscroll compensation during operationsTesting
enableScrollToCorrectionsis not setOpen questions
Should we mark the existing
scrollToDynamicItemutil asdeprecated(as we can't fix it or just remove)?