fix(admin): prevent excessive polling in notifications (#12868)

Co-authored-by: Your Name <you@example.com>
This commit is contained in:
Jessy LANGEandYour Name authored and GitHub committed 2025-07-03 13:09:13 +02:00
1 parent 6aa89b62b9
commit eed72db502
1 file changed
+8 -2
@@ -77,6 +77,7 @@ export const InfiniteList = <
startObserver.current = new IntersectionObserver( startObserver.current = new IntersectionObserver(
(entries) => { (entries) => {
if (entries[0].isIntersecting && hasPreviousPage) { if (entries[0].isIntersecting && hasPreviousPage) {
startObserver.current?.disconnect()
fetchPreviousPage() fetchPreviousPage()
} }
}, },
@@ -88,6 +89,7 @@ export const InfiniteList = <
endObserver.current = new IntersectionObserver( endObserver.current = new IntersectionObserver(
(entries) => { (entries) => {
if (entries[0].isIntersecting && hasNextPage) { if (entries[0].isIntersecting && hasNextPage) {
endObserver.current?.disconnect()
fetchNextPage() fetchNextPage()
} }
}, },
@@ -97,8 +99,12 @@ export const InfiniteList = <
) )
// Register the new observers to observe the new first and last children // Register the new observers to observe the new first and last children
startObserver.current?.observe(parentRef.current!.firstChild as Element) if (parentRef.current?.firstChild) {
endObserver.current?.observe(parentRef.current!.lastChild as Element) startObserver.current?.observe(parentRef.current.firstChild as Element)
}
if (parentRef.current?.lastChild) {
endObserver.current?.observe(parentRef.current.lastChild as Element)
}
} }
// Clear the old observers // Clear the old observers