Skip to content

[drawer] Deduplicate swipe math to reduce bundle size - #5181

Merged
atomiks merged 1 commit into
mui:masterfrom
atomiks:claude/relaxed-swartz-9601e0
Jul 10, 2026
Merged

atomiks merged 1 commit into
mui:masterfrom
atomiks:claude/relaxed-swartz-9601e0

Conversation

@atomiks

@atomiks atomiks commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Part of the bundle-size minimization effort. The drawer's swipe substrate re-derived the same directional math in many places: DrawerViewport hand-rolled the left/up ? -x : x sign flip seven times even though useSwipeDismiss already exports getDisplacement, ran three nearly identical closest-offset scan loops in the snap-point release path, and paired setAttribute/removeAttribute where toggleAttribute suffices. useSwipeDismiss had the same shape in its per-direction threshold switch and its mirrored vertical/horizontal scroll-edge branches.

This deduplicates all of it: one shared closestSnapPointIndex helper (also reused by useDrawerSnapPoints), getDisplacement for every sign flip, positional args for private callbacks, and removal of guards that are provably dead after clamping but that terser can't eliminate. @base-ui/react/drawer goes from 106,034 B parsed / 34,492 B gzipped to 104,152 B / 34,135 B (−1,882 B / −357 B), with each refactor batch measured to confirm it shrank the output.

Behavior is identical: no release-path control flow in useSwipeDismiss was touched (every path still reaches handleEnd), and the drawer, toast, and swipe-area suites pass in both jsdom and Chromium.

@atomiks atomiks added type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. component: drawer Changes related to the drawer component. labels Jul 7, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jul 7, 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@5181
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@5181
    

commit: 89298a8

@code-infra-dashboard

code-infra-dashboard Bot commented Jul 7, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react ▼-1.88KB(-0.40%) ▼-361B(-0.24%)

Details of bundle changes

Performance

Total duration: 1,327.18 ms -105.18 ms(-7.3%) | Renders: 78 (+0)

Test Duration Renders
Select open (500 options) 56.43 ms 🔺+11.13 ms(+24.6%) 14 (+0)
Checkbox mount (500 instances) 65.67 ms ▼-18.86 ms(-22.3%) 1 (+0)
Menu open (500 items) 65.63 ms ▼-18.33 ms(-21.8%) 12 (+0)

11 tests within noise — details


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

@netlify

netlify Bot commented Jul 7, 2026

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 89298a8
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a4ca5846018520008413b9c
😎 Deploy Preview https://deploy-preview-5181--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

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

@atomiks
atomiks marked this pull request as ready for review July 7, 2026 08:27
@atomiks
atomiks merged commit 136d38d into mui:master Jul 10, 2026
7 checks passed
@atomiks
atomiks deleted the claude/relaxed-swartz-9601e0 branch July 10, 2026 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: drawer Changes related to the drawer component. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant