Skip to content

[slider] Fix touchend listener accumulation leak - #5070

Merged
atomiks merged 2 commits into
mui:masterfrom
atomiks:claude/hardcore-bohr-84caa3
Jun 18, 2026
Merged

atomiks merged 2 commits into
mui:masterfrom
atomiks:claude/hardcore-bohr-84caa3

Conversation

@atomiks

@atomiks atomiks commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Fixes #5068

Problem

After a touch interaction on the slider (tap or drag), tapping anywhere else on the page fired onValueCommitted. This was originally reported for desktop in #3311 and fixed for the pointer path in #3312 ({ once: true } on pointerup), but it persisted on touch devices (Safari iOS, Chrome with emulated touch).

Root cause

handleTouchEnd was a plain function recreated on every render, unlike its siblings (handleTouchMove, handleTouchStart, stopListening), which use useStableCallback. The slider re-renders during an interaction (via setValue/setDragging), so:

  • handleTouchStart registers document.addEventListener('touchend', handleTouchEnd) with one function instance, and
  • stopListening later calls removeEventListener('touchend', handleTouchEnd) with a different (later-render) instance.

The references don't match, so the touchend listener is never removed and leaks onto the document, re-firing on every subsequent tap. On v1.5.0 (where handleTouchEnd committed unconditionally) this surfaced as the reported spurious onValueCommitted. On master, #4937's currentInteractionValueRef gate masks the commit, but the underlying listener leak remains.

Fix

Wrap handleTouchEnd in useStableCallback so addEventListener/removeEventListener use the same stable reference and the listener is reliably removed. This also matches the repo convention of using useStableCallback for functions invoked from event handlers.

Tests

Added two Chromium regression tests:

  • does not call onValueCommitted on outside taps after a touch interaction — the user-facing contract.

  • removes the document touchend listener after a touch interaction — targets the root cause (red before this change, green after).

  • I have followed (at least) the PR section of the contributing guide.

@atomiks atomiks added component: slider Changes related to the slider component. type: bug It doesn't behave as expected. labels Jun 18, 2026
`handleTouchEnd` was a plain function recreated on every render, so the
`touchend` listener added on `touchstart` was registered with one
instance and removed with a different one after the interaction's
re-renders. The listener was never removed, so a new one accumulated on
the document per touch interaction and re-fired on every subsequent tap.

Wrap `handleTouchEnd` in `useStableCallback` so add/removeEventListener
use the same reference and the listener is reliably removed.
@atomiks
atomiks force-pushed the claude/hardcore-bohr-84caa3 branch from e574ba7 to 1009e54 Compare June 18, 2026 04:56
@atomiks atomiks changed the title [slider] Fix onValueCommitted firing on outside taps after touch [slider] Fix touchend listener accumulation leak Jun 18, 2026
@pkg-pr-new

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

commit: 240a7d4

@netlify

netlify Bot commented Jun 18, 2026

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit e574ba7
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a337a46dd701e00084a8e98
😎 Deploy Preview https://deploy-preview-5070--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.

@code-infra-dashboard

code-infra-dashboard Bot commented Jun 18, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react ▼-8B(0.00%) ▼-3B(0.00%)

Details of bundle changes


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

@atomiks
atomiks marked this pull request as ready for review June 18, 2026 05:02
@netlify

netlify Bot commented Jun 18, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 240a7d4
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a339811f378f600080b8008
😎 Deploy Preview https://deploy-preview-5070--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 merged commit 4c33d74 into mui:master Jun 18, 2026
6 checks passed
@atomiks
atomiks deleted the claude/hardcore-bohr-84caa3 branch June 18, 2026 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[slider] onValueCommitted called on "outside taps" after drag ends

2 participants