Skip to content
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

[Performance fix #21831] Don't re-render ReportScreen unnecessarily when switching #21832

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/pages/home/ReportScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ class ReportScreen extends React.Component {
isBannerVisible: true,
};
this.firstRenderRef = React.createRef();
this.firstRenderRef.current = reportActionsListViewHeight === 0;

this.flatListRef = React.createRef();
this.reactionListRef = React.createRef();
}
Expand Down Expand Up @@ -244,8 +246,8 @@ class ReportScreen extends React.Component {

const shouldHideReport = !ReportUtils.canAccessReport(this.props.report, this.props.policies, this.props.betas);

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

const parentReportAction = ReportActionsUtils.getParentReportAction(this.props.report);
const isSingleTransactionView = ReportActionsUtils.isTransactionThread(parentReportAction);
Expand Down Expand Up @@ -316,7 +318,11 @@ class ReportScreen extends React.Component {
nativeID={CONST.REPORT.DROP_NATIVE_ID + this.getNavigationKey()}
style={[styles.flex1, styles.justifyContentEnd, styles.overflowHidden]}
onLayout={(event) => {
const skeletonViewContainerHeight = event.nativeEvent.layout.height;
// Rounding this value for comparison because they can look like this: 411.9999694824219
const skeletonViewContainerHeight = Math.round(event.nativeEvent.layout.height);

// Only set state when the height changes to avoid unnecessary renders
if (reportActionsListViewHeight === skeletonViewContainerHeight) return;

// The height can be 0 if the component unmounts - we are not interested in this value and want to know how much space it
// takes up so we can set the skeleton view container height.
Expand Down