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 3afc1e3 commit 7b35f0f
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 @@ -287,13 +287,6 @@ function ReportScreen({
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 @@ -733,6 +726,16 @@ function ReportScreen({
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;
}

if (
(!isLinkedActionInaccessibleWhisper && isLinkedActionDeleted) ||
(shouldShowSkeleton &&
Expand Down

0 comments on commit 7b35f0f

Please sign in to comment.