Skip to content

Commit

Permalink
[ButtonBase] Fix potential memory leak for multi-touch devices
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Jan 21, 2020
1 parent a0f6255 commit 7a350fd
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions packages/material-ui/src/ButtonBase/TouchRipple.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,22 @@ const TouchRipple = React.forwardRef(function TouchRipple(props, ref) {

// Touche devices
if (event.touches) {
// Prepare the ripple effect.
startTimerCommit.current = () => {
startCommit({ pulsate, rippleX, rippleY, rippleSize, cb });
};
// Delay the execution of the ripple effect.
startTimer.current = setTimeout(() => {
if (startTimerCommit.current) {
startTimerCommit.current();
startTimerCommit.current = null;
}
}, DELAY_RIPPLE); // We have to make a tradeoff with this value.
// check that this isn't another touchstart due to multitouch
// otherwise we will only clear a single timer when unmounting while two
// are running
if (startTimerCommit.current === null) {
// Prepare the ripple effect.
startTimerCommit.current = () => {
startCommit({ pulsate, rippleX, rippleY, rippleSize, cb });
};
// Delay the execution of the ripple effect.
startTimer.current = setTimeout(() => {
if (startTimerCommit.current) {
startTimerCommit.current();
startTimerCommit.current = null;
}
}, DELAY_RIPPLE); // We have to make a tradeoff with this value.
}
} else {
startCommit({ pulsate, rippleX, rippleY, rippleSize, cb });
}
Expand Down

0 comments on commit 7a350fd

Please sign in to comment.