Skip to content
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
20 changes: 14 additions & 6 deletions src/pages/ScheduleCall/ScheduleCallPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {getLatestError} from '@libs/ErrorUtils';
import Navigation from '@libs/Navigation/Navigation';
import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types';
import type {ScheduleCallParamList} from '@libs/Navigation/types';
import {isAdminRoom, isTaskReport} from '@libs/ReportUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
Expand Down Expand Up @@ -55,17 +56,24 @@ function ScheduleCallPage() {
const [scheduleCallDraft] = useOnyx(`${ONYXKEYS.SCHEDULE_CALL_DRAFT}`);
const reportID = route.params?.reportID;

const [adminReportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`, {
const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ PERF-11 (docs)

The two new useOnyx subscriptions for report and parentReport subscribe to entire Report objects without selectors. Report objects can be large with many fields, but this component only needs type and parentReportID from report, and chatType and reportID from parentReport. Any change to unrelated fields on these reports (e.g., lastVisibleActionCreated, stateNum, etc.) will trigger unnecessary re-renders of this component.

Add selectors to narrow the subscriptions to only the fields needed:

const [report] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {
    selector: (data) => ({
        type: data?.type,
        parentReportID: data?.parentReportID,
    }),
});
const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`, {
    selector: (data) => ({
        chatType: data?.chatType,
        reportID: data?.reportID,
    }),
});

This ensures deepEqual runs on a tiny object (2 fields) rather than the full Report, and the component only re-renders when the fields it actually uses change.


Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah this violates functions call for TS error, so going to leave it as it is

const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${report?.parentReportID}`);

// Task reports in #admins room have chatType as policyAdmins,
// So for a task report, we need to send the real #admins room i.e., the parent report.
const adminsRoomReportID = isTaskReport(report) && parentReport?.reportID && isAdminRoom(parentReport) ? parentReport.reportID : reportID;

const [adminReportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${adminsRoomReportID}`, {
selector: adminReportNameValuePairsSelector,
});
const calendlySchedule = adminReportNameValuePairs?.calendlySchedule;

useEffect(() => {
if (!reportID) {
if (!adminsRoomReportID) {
return;
}
getGuideCallAvailabilitySchedule(reportID);
}, [reportID]);
getGuideCallAvailabilitySchedule(adminsRoomReportID);
}, [adminsRoomReportID]);

// Clear selected time when user comes back to the selection screen
useFocusEffect(
Expand All @@ -76,7 +84,7 @@ function ScheduleCallPage() {

useEffect(() => {
return () => {
sendScheduleCallNudge(session?.accountID ?? CONST.DEFAULT_NUMBER_ID, reportID);
sendScheduleCallNudge(session?.accountID ?? CONST.DEFAULT_NUMBER_ID, adminsRoomReportID);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Comment on lines 86 to 90

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Track admins room ID in unmount nudge effect

The cleanup effect is intentionally frozen with [], so it captures the initial adminsRoomReportID only. In task-report flows, that value can start as the task ID and later switch to the parent #admins report after Onyx data arrives; when the page unmounts, sendScheduleCallNudge may still be sent to the stale task report. This means the new parent-report routing logic is skipped in cold-start/deep-link cases and the nudge can target the wrong conversation.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MonilBhavsar is this still relevant?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's an edge case. I would like to leave it as its unless we see real issue.

Expand Down Expand Up @@ -224,7 +232,7 @@ function ScheduleCallPage() {
accountID: timeSlot.guideAccountID,
email: timeSlot.guideEmail,
},
reportID,
reportID: adminsRoomReportID,
});
Navigation.navigate(ROUTES.SCHEDULE_CALL_CONFIRMATION.getRoute(reportID));
}}
Expand Down
Loading