prevent datatable from spamming loadMore on scroll to end (#5973)

This commit is contained in:
Diego Imbert
2025-06-18 14:25:55 +02:00
committed by GitHub
parent 959280bf5a
commit be0c8ddae0
@@ -73,7 +73,7 @@
const hasScrollbar = tableContainer.scrollHeight > tableContainer.clientHeight
if (!hasScrollbar && hasMore) {
dispatch('loadMore')
triggerLoadMore()
}
}
@@ -92,11 +92,20 @@
if (!tableContainer) return
const { scrollTop, scrollHeight, clientHeight } = tableContainer
if (scrollHeight - (scrollTop + clientHeight) < 50) {
dispatch('loadMore')
if (scrollHeight - (scrollTop + clientHeight) === 0) {
triggerLoadMore()
}
}
let lastLoadMoreDispatch: number | undefined = $state(undefined)
function triggerLoadMore() {
if (lastLoadMoreDispatch && Date.now() - lastLoadMoreDispatch < 1000) {
return
}
dispatch('loadMore')
lastLoadMoreDispatch = Date.now()
}
$effect(() => {
if (tableContainer && hasMore && !loading) {
untrack(() => checkScrollStatus())
@@ -170,7 +179,7 @@
<Button
color="light"
size="xs2"
on:click={() => dispatch('loadMore')}
on:click={() => triggerLoadMore()}
endIcon={{ icon: ArrowDownIcon }}
>
Load {loadMore} more