Skip to content

Commit

Permalink
fix: avoid eager channel pagination on channel open (#2425)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinCupela authored Jun 21, 2024
1 parent 2ca3188 commit c1e8b93
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/components/InfiniteScrollPaginator/InfiniteScroll.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { PropsWithChildren, useEffect, useLayoutEffect, useRef } from 'react';
import React, { PropsWithChildren, useEffect, useRef } from 'react';
import type { PaginatorProps } from '../../types/types';
import { deprecationAndReplacementWarning } from '../../utils/deprecationWarning';
import { DEFAULT_LOAD_PAGE_SCROLL_THRESHOLD } from '../../constants/limits';
Expand Down Expand Up @@ -73,6 +73,8 @@ export const InfiniteScroll = (props: PropsWithChildren<InfiniteScrollProps>) =>
const hasPreviousPageFlag = hasPreviousPage || hasMore;

const scrollComponent = useRef<HTMLElement>();
const previousOffset = useRef<number | undefined>();
const previousReverseOffset = useRef<number | undefined>();

const scrollListenerRef = useRef<() => void>();
scrollListenerRef.current = () => {
Expand All @@ -93,7 +95,12 @@ export const InfiniteScroll = (props: PropsWithChildren<InfiniteScrollProps>) =>
}

if (isLoading) return;
// FIXME: this triggers loadMore call when a user types messages in thread and the scroll container container expands
if (previousOffset.current === offset && previousReverseOffset.current === reverseOffset)
return;
previousOffset.current = offset;
previousReverseOffset.current = reverseOffset;

// FIXME: this triggers loadMore call when a user types messages in thread and the scroll container expands
if (
reverseOffset < Number(threshold) &&
typeof loadPreviousPageFn === 'function' &&
Expand All @@ -120,7 +127,7 @@ export const InfiniteScroll = (props: PropsWithChildren<InfiniteScrollProps>) =>
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useLayoutEffect(() => {
useEffect(() => {
const scrollElement = scrollComponent.current?.parentNode;
if (!scrollElement) return;

Expand Down

0 comments on commit c1e8b93

Please sign in to comment.