-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Handle pagination errors in chats #40610
Changes from 1 commit
c95398c
ff7c706
47be44a
350c7e2
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 |
---|---|---|
|
@@ -696,7 +696,9 @@ function openReport( | |
value: { | ||
isLoadingInitialReportActions: true, | ||
isLoadingOlderReportActions: false, | ||
hasLoadingOlderReportActionsError: false, | ||
isLoadingNewerReportActions: false, | ||
hasLoadingNewerReportActionsError: false, | ||
lastVisitTime: DateUtils.getDBTime(), | ||
}, | ||
}, | ||
|
@@ -988,6 +990,7 @@ function getOlderActions(reportID: string, reportActionID: string) { | |
key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`, | ||
value: { | ||
isLoadingOlderReportActions: true, | ||
hasLoadingOlderReportActionsError: false, | ||
}, | ||
}, | ||
]; | ||
|
@@ -1008,6 +1011,7 @@ function getOlderActions(reportID: string, reportActionID: string) { | |
key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`, | ||
value: { | ||
isLoadingOlderReportActions: false, | ||
hasLoadingOlderReportActionsError: true, | ||
}, | ||
}, | ||
]; | ||
|
@@ -1031,6 +1035,7 @@ function getNewerActions(reportID: string, reportActionID: string) { | |
key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`, | ||
value: { | ||
isLoadingNewerReportActions: true, | ||
hasLoadingNewerReportActionsError: false, | ||
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. We can prevent setting |
||
}, | ||
}, | ||
]; | ||
|
@@ -1051,6 +1056,7 @@ function getNewerActions(reportID: string, reportActionID: string) { | |
key: `${ONYXKEYS.COLLECTION.REPORT_METADATA}${reportID}`, | ||
value: { | ||
isLoadingNewerReportActions: false, | ||
hasLoadingNewerReportActionsError: true, | ||
}, | ||
}, | ||
]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,20 +65,26 @@ type ReportActionsListProps = WithCurrentUserPersonalDetailsProps & { | |
/** Are we loading more report actions? */ | ||
isLoadingOlderReportActions?: boolean; | ||
|
||
/** Was there an error when loading older report actions? */ | ||
hasLoadingOlderReportActionsError?: boolean; | ||
|
||
/** Are we loading newer report actions? */ | ||
isLoadingNewerReportActions?: boolean; | ||
|
||
/** Was there an error when loading newer report actions? */ | ||
hasLoadingNewerReportActionsError?: boolean; | ||
|
||
/** Callback executed on list layout */ | ||
onLayout: (event: LayoutChangeEvent) => void; | ||
|
||
/** Callback executed on scroll */ | ||
onScroll?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void; | ||
|
||
/** Function to load more chats */ | ||
loadOlderChats: () => void; | ||
loadOlderChats: (force?: boolean) => void; | ||
|
||
/** Function to load newer chats */ | ||
loadNewerChats: () => void; | ||
loadNewerChats: (force?: boolean) => void; | ||
|
||
/** Whether the composer is in full size */ | ||
isComposerFullSize?: boolean; | ||
|
@@ -139,7 +145,9 @@ function ReportActionsList({ | |
parentReportAction, | ||
isLoadingInitialReportActions = false, | ||
isLoadingOlderReportActions = false, | ||
hasLoadingOlderReportActionsError = false, | ||
isLoadingNewerReportActions = false, | ||
hasLoadingNewerReportActionsError = false, | ||
sortedReportActions, | ||
onScroll, | ||
mostRecentIOUReportActionID = '', | ||
|
@@ -569,7 +577,11 @@ function ReportActionsList({ | |
|
||
const lastReportAction: OnyxTypes.ReportAction | EmptyObject = useMemo(() => sortedReportActions.at(-1) ?? {}, [sortedReportActions]); | ||
|
||
const listFooterComponent = useCallback(() => { | ||
const retryLoadOlderChatsError = useCallback(() => { | ||
loadOlderChats(true); | ||
}, [loadOlderChats]); | ||
|
||
const listFooterComponent = useMemo(() => { | ||
// Skip this hook on the first render (when online), as we are not sure if more actions are going to be loaded, | ||
// Therefore showing the skeleton on footer might be misleading. | ||
// When offline, there should be no second render, so we should show the skeleton if the corresponding loading prop is present | ||
|
@@ -584,9 +596,11 @@ function ReportActionsList({ | |
isLoadingOlderReportActions={isLoadingOlderReportActions} | ||
isLoadingInitialReportActions={isLoadingInitialReportActions} | ||
lastReportActionName={lastReportAction.actionName} | ||
hasError={hasLoadingOlderReportActionsError} | ||
onRetry={retryLoadOlderChatsError} | ||
/> | ||
); | ||
}, [isLoadingInitialReportActions, isLoadingOlderReportActions, lastReportAction.actionName, isOffline]); | ||
}, [isLoadingInitialReportActions, isLoadingOlderReportActions, lastReportAction.actionName, isOffline, hasLoadingOlderReportActionsError, retryLoadOlderChatsError]); | ||
|
||
const onLayoutInner = useCallback( | ||
(event: LayoutChangeEvent) => { | ||
|
@@ -601,7 +615,11 @@ function ReportActionsList({ | |
[onContentSizeChange], | ||
); | ||
|
||
const listHeaderComponent = useCallback(() => { | ||
const retryLoadNewerChatsError = useCallback(() => { | ||
loadNewerChats(true); | ||
}, [loadNewerChats]); | ||
|
||
const listHeaderComponent = useMemo(() => { | ||
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. I changed this so we pass a react element instead of a function. When passing a function it causes the component to be unmounted and remounted every time one of the dependencies of useCallback changes. This caused flickers in the loading component as well as resetting any internal state so this fixes it. |
||
if (!canShowHeader) { | ||
hasHeaderRendered.current = true; | ||
return null; | ||
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 40610-newer-actions-issue.mp4There 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. I am curious about what this canShowHeader is for, meant to raise this in the review but probably forgot. Maybe I should just ignore canShowHeader if there’s an error? 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.
I think the same reasoning for
Hmm. Interesting. If there is an error then we may as well show the error UI even during first render. 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 if there is a bug with that logic but when testing comment linking I never see the loading indicator for newer messages, maybe I should make an issue for that?. Anyway I think it makes sense to always render the header / footer state if there's an error. |
||
|
@@ -611,9 +629,19 @@ function ReportActionsList({ | |
<ListBoundaryLoader | ||
type={CONST.LIST_COMPONENTS.HEADER} | ||
isLoadingNewerReportActions={isLoadingNewerReportActions} | ||
hasError={hasLoadingNewerReportActionsError} | ||
onRetry={retryLoadNewerChatsError} | ||
/> | ||
); | ||
}, [isLoadingNewerReportActions, canShowHeader]); | ||
}, [isLoadingNewerReportActions, canShowHeader, hasLoadingNewerReportActionsError, retryLoadNewerChatsError]); | ||
|
||
const onStartReached = useCallback(() => { | ||
loadNewerChats(false); | ||
}, [loadNewerChats]); | ||
|
||
const onEndReached = useCallback(() => { | ||
loadOlderChats(false); | ||
}, [loadOlderChats]); | ||
|
||
// When performing comment linking, initially 25 items are added to the list. Subsequent fetches add 15 items from the cache or 50 items from the server. | ||
// This is to ensure that the user is able to see the 'scroll to newer comments' button when they do comment linking and have not reached the end of the list yet. | ||
|
@@ -635,9 +663,9 @@ function ReportActionsList({ | |
contentContainerStyle={contentContainerStyle} | ||
keyExtractor={keyExtractor} | ||
initialNumToRender={initialNumToRender} | ||
onEndReached={loadOlderChats} | ||
onEndReached={onEndReached} | ||
onEndReachedThreshold={0.75} | ||
onStartReached={loadNewerChats} | ||
onStartReached={onStartReached} | ||
onStartReachedThreshold={0.75} | ||
ListFooterComponent={listFooterComponent} | ||
ListHeaderComponent={listHeaderComponent} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And we may want to do the same for
getOlderActions
here