Skip to content

Commit

Permalink
Merge pull request #54881 from callstack-internal/remove-forcing-re-l…
Browse files Browse the repository at this point in the history
…ayout-on-useViewportOffsetTop
  • Loading branch information
mountiny authored Jan 12, 2025
2 parents 0349d96 + a68a091 commit f6774ca
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/hooks/useViewportOffsetTop/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export default function useViewportOffsetTop(shouldAdjustScrollView = false): nu
useEffect(() => addViewportResizeListener(updateOffsetTop), [updateOffsetTop]);

useEffect(() => {
if (!shouldAdjustScrollView) {
// We don't want to trigger window.scrollTo when we are already at the target position. It causes unnecessary style recalculations.
if (!shouldAdjustScrollView || viewportOffsetTop === window.scrollY) {
return;
}
window.scrollTo({top: viewportOffsetTop, behavior: 'smooth'});
Expand Down

0 comments on commit f6774ca

Please sign in to comment.