From da706d41850eb213fe713c57f4bf7982e72d98e0 Mon Sep 17 00:00:00 2001 From: Verghese Koshy Date: Fri, 10 Sep 2021 18:07:14 +0900 Subject: [PATCH] Issue where index is -1 or more than total When the user does a crazy amount of swapping the component get diff as negative or positive and sometimes result in an overflow 'or' underflow of the index results in the component sort of not responding. This only reset the value to 0 or total if the loop is false --- src/index.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/index.js b/src/index.js index f52cc707..9d881b5a 100644 --- a/src/index.js +++ b/src/index.js @@ -489,6 +489,14 @@ export default class extends Component { offset[dir] = step loopJump = true } + } else { + // Note: this is a hack to solve the overflow or underflow of index + // when user navigates to quickly + if (index <= -1) { + index = 0 + } else if (index >= state.total) { + index = state.total - 1 + } } const newState = {}