Skip to content

Commit

Permalink
Fix not found view flicker when comment linking
Browse files Browse the repository at this point in the history
  • Loading branch information
janicduplessis committed Aug 1, 2024
1 parent b010315 commit 85ac515
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,6 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro
const [currentUserAccountID = -1] = useOnyx(ONYXKEYS.SESSION, {selector: (value) => value?.accountID});
const {reportActions, linkedAction, sortedAllReportActions} = usePaginatedReportActions(report.reportID, reportActionIDFromRoute);

// Define here because reportActions are recalculated before mount, allowing data to display faster than useEffect can trigger.
// If we have cached reportActions, they will be shown immediately.
// We aim to display a loader first, then fetch relevant reportActions, and finally show them.
useLayoutEffect(() => {
setIsLinkingToMessage(!!reportActionIDFromRoute);
}, [route, reportActionIDFromRoute]);

const [isBannerVisible, setIsBannerVisible] = useState(true);
const [scrollPosition, setScrollPosition] = useState<ScrollPosition>({});

Expand Down Expand Up @@ -728,6 +721,16 @@ function ReportScreen({route, currentReportID = '', navigation}: ReportScreenPro
Report.readNewestAction(report.reportID);
}, [report]);

const lastRoute = usePrevious(route);
const lastReportActionIDFromRoute = usePrevious(reportActionIDFromRoute);
// Define here because reportActions are recalculated before mount, allowing data to display faster than useEffect can trigger.
// If we have cached reportActions, they will be shown immediately.
// We aim to display a loader first, then fetch relevant reportActions, and finally show them.
if ((lastRoute !== route || lastReportActionIDFromRoute !== reportActionIDFromRoute) && isLinkingToMessage !== !!reportActionIDFromRoute) {
setIsLinkingToMessage(!!reportActionIDFromRoute);
return null;
}

return (
<ActionListContext.Provider value={actionListValue}>
<ReactionListContext.Provider value={reactionListRef}>
Expand Down

0 comments on commit 85ac515

Please sign in to comment.