Skip to content

[scroll area] Fix overflow edge rounding - #3888

Merged
atomiks merged 4 commits into
mui:masterfrom
atomiks:fix/scrollarea-rounding
Feb 10, 2026
Merged

atomiks merged 4 commits into
mui:masterfrom
atomiks:fix/scrollarea-rounding

Conversation

@atomiks

@atomiks atomiks commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

Fixes #3795 (comment)

@atomiks atomiks added type: bug It doesn't behave as expected. component: scroll area Changes related to the scroll area component. labels Jan 29, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jan 29, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@3888
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@3888
    

commit: 319f107

@mui-bot

mui-bot commented Jan 29, 2026 •

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 🔺+108B(+0.03%) 🔺+60B(+0.04%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Jan 29, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 319f107
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/698b153655fe9d0008e03ff6
😎 Deploy Preview https://deploy-preview-3888--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@atomiks
atomiks marked this pull request as ready for review January 30, 2026 00:44
@greptile-apps

greptile-apps Bot commented Jan 30, 2026

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

This PR fixes floating-point rounding issues in scroll edge detection by introducing a 1px tolerance when determining if the viewport is scrolled to an edge. The change prevents scenarios where scroll positions like maxScroll - 0.5px incorrectly show as not fully scrolled.

  • Created normalizeScrollOffset utility that snaps scroll values within 1px of edges to the actual edge value
  • Applied normalization to both horizontal and vertical scroll calculations in ScrollAreaViewport
  • Removed redundant clamping operations that were duplicating the work done by normalizeScrollOffset
  • Added comprehensive test coverage for the edge-rounding behavior

Confidence Score: 5/5

  • This PR is safe to merge with no identified issues
  • The implementation is clean, well-tested, and addresses a specific floating-point precision bug. The 1px tolerance is reasonable for browser rendering, the logic is straightforward, and the change is properly covered by new tests
  • No files require special attention

Important Files Changed

Filename Overview
packages/react/src/scroll-area/utils/scrollEdges.ts Added new utility to normalize scroll offsets near edges (within 1px tolerance) to handle floating-point rounding issues
packages/react/src/scroll-area/viewport/ScrollAreaViewport.tsx Integrated normalizeScrollOffset for both X and Y scroll positions to prevent off-by-one edge detection errors
packages/react/src/scroll-area/root/ScrollAreaRoot.test.tsx Added test case verifying scroll positions within 0.5px of edges are treated as fully scrolled

@michaldudak

Copy link
Copy Markdown
Member

Review by Codex (looks minor):

Normalize end offsets for tiny scroll ranges — packages/react/src/scroll-area/utils/scrollEdges.ts:12-17 When the scroll range is ≤ 1px (e.g., content is only 1px larger than the viewport), normalizeScrollOffset always returns 0 because the start-edge check runs before the end-edge check. That means even at scrollLeft === max, the normalized value stays 0 and scrollLeftFromEnd stays max, so data-overflow-*-end never clears. This shows up whenever the scrollable range is 1px or less. Consider handling overlapping tolerances (e.g., compare distance to each edge or special-case max <= tolerance) so the end state can be reached.

@michaldudak
michaldudak force-pushed the fix/scrollarea-rounding branch from 48eb4bc to 4ae3ec2 Compare January 30, 2026 11:21
@atomiks
atomiks merged commit 16f34b1 into mui:master Feb 10, 2026
7 checks passed
@atomiks
atomiks deleted the fix/scrollarea-rounding branch February 10, 2026 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: scroll area Changes related to the scroll area component. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants