Repository navigation
[slider] Fix touchend listener accumulation leak - #5070
Merged
Merged
Conversation
`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
force-pushed
the
claude/hardcore-bohr-84caa3
branch
from
June 18, 2026 04:56
e574ba7 to
1009e54
Compare
commit: |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Bundle size
Check out the code infra dashboard for more information about this PR. |
atomiks
marked this pull request as ready for review
June 18, 2026 05:02
atomiks
requested review from
colmtuite,
flaviendelangle,
jjenzz and
michaldudak
as code owners
June 18, 2026 05:02
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
michaldudak
approved these changes
Jun 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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 }onpointerup), but it persisted on touch devices (Safari iOS, Chrome with emulated touch).Root cause
handleTouchEndwas a plain function recreated on every render, unlike its siblings (handleTouchMove,handleTouchStart,stopListening), which useuseStableCallback. The slider re-renders during an interaction (viasetValue/setDragging), so:handleTouchStartregistersdocument.addEventListener('touchend', handleTouchEnd)with one function instance, andstopListeninglater callsremoveEventListener('touchend', handleTouchEnd)with a different (later-render) instance.The references don't match, so the
touchendlistener is never removed and leaks onto the document, re-firing on every subsequent tap. On v1.5.0 (wherehandleTouchEndcommitted unconditionally) this surfaced as the reported spuriousonValueCommitted. Onmaster, #4937'scurrentInteractionValueRefgate masks the commit, but the underlying listener leak remains.Fix
Wrap
handleTouchEndinuseStableCallbacksoaddEventListener/removeEventListeneruse the same stable reference and the listener is reliably removed. This also matches the repo convention of usinguseStableCallbackfor 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.