Repository navigation
fix: Opening a room at its oldest unread message never loads newer messages #107793
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4e2bee7
f1d0caa
56470c7
5c4d639
bbeb022
72d90ed
2cae1e2
99d4ec9
43bcd58
a456961
8e42597
bd7d1e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import type {ViewableItemsChangedHandler} from '@components/FlashList/types'; | ||
|
|
||
| import useOnyx from '@hooks/useOnyx'; | ||
| import useReportActionsScroll from '@hooks/useReportActionsScroll'; | ||
| import useReportScrollManager from '@hooks/useReportScrollManager'; | ||
| import useWindowDimensions from '@hooks/useWindowDimensions'; | ||
|
|
@@ -13,14 +14,21 @@ import useFollowActionBadgeTarget from '@pages/inbox/report/useFollowActionBadge | |
| import useScrollToEditingReportAction from '@pages/inbox/report/useScrollToEditingReportAction'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import {canLoadNewerReportActionsSelector} from '@src/selectors/ReportMetaData'; | ||
| import type * as OnyxTypes from '@src/types/onyx'; | ||
|
|
||
| import type {LayoutChangeEvent, NativeScrollEvent, NativeSyntheticEvent} from 'react-native'; | ||
| import type {OnyxEntry} from 'react-native-onyx'; | ||
|
|
||
| import {useEffect, useRef} from 'react'; | ||
| import {useEffect, useEffectEvent, useRef} from 'react'; | ||
|
|
||
| import type {UseReportActionsListScrollParams} from './types'; | ||
|
|
||
| const START_REACHED_THRESHOLD = 0.75; | ||
|
|
||
| const newestFetchedReportActionIDSelector = (paginationState: OnyxEntry<OnyxTypes.ReportPaginationState>) => paginationState?.newestFetchedReportActionID; | ||
|
|
||
| /** | ||
| * Create a unique key for each action in the FlatList. | ||
| * We use the reportActionID that is a string representation of a random 64-bit int, which should be | ||
|
|
@@ -163,7 +171,16 @@ function useReportActionsListScroll({ | |
| loadOlderChats(false); | ||
| }; | ||
|
|
||
| const [newestFetchedReportActionID] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_PAGINATION_STATE}${reportID}`, {selector: newestFetchedReportActionIDSelector}); | ||
| const [canLoadNewerReportActions = false] = useOnyx(`${ONYXKEYS.COLLECTION.RAM_ONLY_REPORT_LOADING_STATE}${reportID}`, {selector: canLoadNewerReportActionsSelector}); | ||
| const requestedNewerCursorRef = useRef(newestFetchedReportActionID); | ||
| const listHeightRef = useRef(0); | ||
|
|
||
| const loadNewerChatsAfterTransitions = () => { | ||
| if (!canLoadNewerReportActions) { | ||
| return; | ||
| } | ||
| requestedNewerCursorRef.current = newestFetchedReportActionID; | ||
| if (!isSearchTopmostFullScreenRoute()) { | ||
| loadNewerChats(false); | ||
| return; | ||
|
|
@@ -176,6 +193,22 @@ function useReportActionsListScroll({ | |
| }); | ||
| }; | ||
|
|
||
| // FlashList won't call onStartReached again while the user stays at the bottom, so ask for the next page when the cursor moves. | ||
| const loadNewerChatsIfAtBottom = useEffectEvent(() => { | ||
| if (!hasNewerActions || !newestFetchedReportActionID || requestedNewerCursorRef.current === newestFetchedReportActionID || listHeightRef.current <= 0) { | ||
| return; | ||
|
Comment on lines
+198
to
+199
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a partially cached chat already has a cursor and the user reaches its loaded bottom while Useful? React with 👍 / 👎.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure about this one. I've tested this on native app, desktop and mobile web, but couldn't reproduce it, even when forcing the conditions (failing the first On the first visit in a session, the list remounts after |
||
| } | ||
| const scrollOffset = listRef.current?.getAbsoluteLastScrollOffset?.(); | ||
| if (scrollOffset === undefined || scrollOffset > listHeightRef.current * START_REACHED_THRESHOLD) { | ||
| return; | ||
| } | ||
| loadNewerChatsAfterTransitions(); | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| loadNewerChatsIfAtBottom(); | ||
| }, [hasNewerActions, newestFetchedReportActionID, canLoadNewerReportActions]); | ||
|
|
||
| useFollowActionBadgeTarget({ | ||
| reportID, | ||
| actionTargetReportActionID: actionBadgeTargetID, | ||
|
|
@@ -199,9 +232,11 @@ function useReportActionsListScroll({ | |
| getItemType: (item: OnyxTypes.ReportAction) => item.actionName, | ||
| onEndReached: loadOlderChatsOnEndReached, | ||
| onEndReachedThreshold: 0.75, | ||
| onStartReached: loadNewerChatsAfterTransitions, | ||
| onStartReachedThreshold: 0.75, | ||
| // FlashList calls this once per entry into the start zone, so don't use that call up before there are newer messages. | ||
| onStartReached: hasNewerActions ? loadNewerChatsAfterTransitions : undefined, | ||
| onStartReachedThreshold: START_REACHED_THRESHOLD, | ||
| onLayout: (event: LayoutChangeEvent) => { | ||
| listHeightRef.current = event.nativeEvent.layout.height; | ||
| onLayout?.(event); | ||
| flushPendingScrollToBottom(); | ||
| }, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.