Skip to content

Commit 7a350fd

Browse files
committed
[ButtonBase] Fix potential memory leak for multi-touch devices
1 parent a0f6255 commit 7a350fd

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

packages/material-ui/src/ButtonBase/TouchRipple.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -207,17 +207,22 @@ const TouchRipple = React.forwardRef(function TouchRipple(props, ref) {
207207

208208
// Touche devices
209209
if (event.touches) {
210-
// Prepare the ripple effect.
211-
startTimerCommit.current = () => {
212-
startCommit({ pulsate, rippleX, rippleY, rippleSize, cb });
213-
};
214-
// Delay the execution of the ripple effect.
215-
startTimer.current = setTimeout(() => {
216-
if (startTimerCommit.current) {
217-
startTimerCommit.current();
218-
startTimerCommit.current = null;
219-
}
220-
}, DELAY_RIPPLE); // We have to make a tradeoff with this value.
210+
// check that this isn't another touchstart due to multitouch
211+
// otherwise we will only clear a single timer when unmounting while two
212+
// are running
213+
if (startTimerCommit.current === null) {
214+
// Prepare the ripple effect.
215+
startTimerCommit.current = () => {
216+
startCommit({ pulsate, rippleX, rippleY, rippleSize, cb });
217+
};
218+
// Delay the execution of the ripple effect.
219+
startTimer.current = setTimeout(() => {
220+
if (startTimerCommit.current) {
221+
startTimerCommit.current();
222+
startTimerCommit.current = null;
223+
}
224+
}, DELAY_RIPPLE); // We have to make a tradeoff with this value.
225+
}
221226
} else {
222227
startCommit({ pulsate, rippleX, rippleY, rippleSize, cb });
223228
}

0 commit comments

Comments
 (0)