Skip to content

Commit

Permalink
fix prevReportRef.current being undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
SosenWiosen committed Aug 3, 2023
1 parent faa1e27 commit 5715e91
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/pages/home/ReportScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ function ReportScreen({
const shouldHideReport = !ReportUtils.canAccessReport(report, policies, betas);

const isLoading = !reportID || !isSidebarLoaded || _.isEmpty(personalDetails) || firstRenderRef.current;
firstRenderRef.current = false;

const parentReportAction = ReportActionsUtils.getParentReportAction(report);
const isDeletedParentAction = ReportActionsUtils.isDeletedParentAction(parentReportAction);
Expand Down Expand Up @@ -241,6 +240,7 @@ function ReportScreen({
},
[route],
);

useEffect(() => {
const unsubscribeVisibilityListener = Visibility.onVisibilityChange(() => {
// If the report is not fully visible (AKA on small screen devices and LHR is open) or the report is optimistic (AKA not yet created)
Expand All @@ -254,20 +254,27 @@ function ReportScreen({

fetchReportIfNeeded();
ComposerActions.setShouldShowComposeInput(true);
prevReportRef.current = report;

return () => {
if (!unsubscribeVisibilityListener) {
return;
}
unsubscribeVisibilityListener();
};
// disabling the warning, as it expects to use exhaustive deps, even though we want this useEffect to run only on the first render.
// I'm disabling the warning, as it expects to use exhaustive deps, even though we want this useEffect to run only on the first render.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(() => {
// If composer should be hidden, hide emoji picker as well
// We don't want this effect to run on the first render.
if (firstRenderRef.current) {
firstRenderRef.current = false;
return;
}

if (ReportUtils.shouldHideComposer(report, errors)) {
// If composer should be hidden, hide emoji picker as well
EmojiPickerAction.hideEmojiPicker(true);
}
const onyxReportID = report.reportID;
Expand Down

0 comments on commit 5715e91

Please sign in to comment.