From dedee37c64bd9cf14992e4df94d834cfa69bcd77 Mon Sep 17 00:00:00 2001 From: Neeraj Bachani Date: Thu, 9 Apr 2026 17:26:00 +0000 Subject: [PATCH] fix: prevent Concierge redirect and LHN disappearance when vacation delegate splits expense MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add useIsOwnWorkspaceChatRef shared hook (ref persists through temporary Onyx SET wipe) - Guard isRemovalExpectedForReportType in ReportNavigateAwayHandler to exclude own workspace chats so the delegate-split Onyx wipe does not trigger a Concierge redirect (Effect 1) - Skip Effect 2 navigation entirely for own workspace chats — the re-fetch in ReportFetchHandler restores the data causing wasDeleted to reset; genuine deletions always go through Effect 1 via userLeavingStatus/didReportClose and never rely on Effect 2 alone - Add re-fetch useEffect in ReportFetchHandler to restore report after Onyx wipe (fixes skeleton) Fixes #84248 --- src/hooks/useIsOwnWorkspaceChatRef.ts | 30 +++++++++++++++++++ src/pages/inbox/ReportFetchHandler.tsx | 19 ++++++++++++ src/pages/inbox/ReportNavigateAwayHandler.tsx | 22 +++++++++++++- 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 src/hooks/useIsOwnWorkspaceChatRef.ts diff --git a/src/hooks/useIsOwnWorkspaceChatRef.ts b/src/hooks/useIsOwnWorkspaceChatRef.ts new file mode 100644 index 000000000000..edc2eaafb9ef --- /dev/null +++ b/src/hooks/useIsOwnWorkspaceChatRef.ts @@ -0,0 +1,30 @@ +import {useRef} from 'react'; +import type {OnyxEntry} from 'react-native-onyx'; +import type * as OnyxTypes from '@src/types/onyx'; + +/** + * Returns a ref that tracks whether the currently-open report is an own workspace chat. + * + * Must be updated synchronously during render — after a vacation delegate splits an expense + * the server sends an Onyx SET that wipes the report object. By the time any useEffect fires, + * `report` is already undefined, so live state and usePrevious both fail. The ref persists + * the last known value through that wipe window so navigation guards and re-fetch effects + * can still make the correct decision. See issue #84248. + */ +function useIsOwnWorkspaceChatRef(report: OnyxEntry | undefined, reportIDFromRoute: string | undefined) { + const isOwnWorkspaceChatRef = useRef(false); + + if (report?.reportID && report.reportID === reportIDFromRoute) { + // Valid, matching report — update the ref. + isOwnWorkspaceChatRef.current = !!report.isOwnPolicyExpenseChat; + } else if (!report?.reportID) { + // Report wiped by Onyx SET — intentionally keep the last known value. + } else { + // Different report loaded — reset. + isOwnWorkspaceChatRef.current = false; + } + + return isOwnWorkspaceChatRef; +} + +export default useIsOwnWorkspaceChatRef; diff --git a/src/pages/inbox/ReportFetchHandler.tsx b/src/pages/inbox/ReportFetchHandler.tsx index 7503d1bcdcbf..9438a55ae197 100644 --- a/src/pages/inbox/ReportFetchHandler.tsx +++ b/src/pages/inbox/ReportFetchHandler.tsx @@ -4,6 +4,7 @@ import {InteractionManager} from 'react-native'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; import useIsAnonymousUser from '@hooks/useIsAnonymousUser'; import useIsInSidePanel from '@hooks/useIsInSidePanel'; +import useIsOwnWorkspaceChatRef from '@hooks/useIsOwnWorkspaceChatRef'; import useNetwork from '@hooks/useNetwork'; import useOnyx from '@hooks/useOnyx'; import usePaginatedReportActions from '@hooks/usePaginatedReportActions'; @@ -91,6 +92,9 @@ function ReportFetchHandler() { const isTransactionThreadView = isReportTransactionThread(report); + // Track whether the current route is an own workspace chat. See issue #84248. + const isCurrentRouteOwnWorkspaceChatRef = useIsOwnWorkspaceChatRef(report, reportIDFromRoute); + const indexOfLinkedMessage = reportActionIDFromRoute ? reportActions.findIndex((obj) => String(obj.reportActionID) === String(reportActionIDFromRoute)) : -1; const doesCreatedActionExists = !!reportActions?.findLast((action) => isCreatedAction(action)); const isLinkedMessageAvailable = indexOfLinkedMessage > -1; @@ -151,6 +155,21 @@ function ReportFetchHandler() { // Effect order below matches the original declaration order in ReportScreen.tsx. + // When a delegate splits an expense the server sends a temporary Onyx SET that wipes the + // workspace chat. The navigation guards in ReportScreen block any redirect, but the report + // stays blank until something re-fetches it. This effect detects the wipe and re-fetches. + // See issue #84248. + const prevReportID = usePrevious(report?.reportID); + useEffect(() => { + const wasJustWiped = !!prevReportID && prevReportID === reportIDFromRoute && !report?.reportID; + if (!wasJustWiped || !isCurrentRouteOwnWorkspaceChatRef.current) { + return; + } + fetchReport(); + // fetchReport is a stable useEffectEvent callback and does not need to be listed as a dependency. + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [report?.reportID, prevReportID, reportIDFromRoute]); + useEffect(() => { if (!transactionThreadReportID || !route?.params?.reportActionID || !isOneTransactionThread(childReport, report, linkedAction)) { return; diff --git a/src/pages/inbox/ReportNavigateAwayHandler.tsx b/src/pages/inbox/ReportNavigateAwayHandler.tsx index 1022dcab9fe9..a3d5e2a60f6c 100644 --- a/src/pages/inbox/ReportNavigateAwayHandler.tsx +++ b/src/pages/inbox/ReportNavigateAwayHandler.tsx @@ -3,6 +3,7 @@ import {useEffect, useEffectEvent, useRef} from 'react'; import type {OnyxEntry} from 'react-native-onyx'; import {useCurrentReportIDState} from '@hooks/useCurrentReportID'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; +import useIsOwnWorkspaceChatRef from '@hooks/useIsOwnWorkspaceChatRef'; import useOnyx from '@hooks/useOnyx'; import useParentReportAction from '@hooks/useParentReportAction'; import usePrevious from '@hooks/usePrevious'; @@ -81,6 +82,11 @@ function ReportNavigateAwayHandler() { const isOptimisticDelete = report?.statusNum === CONST.REPORT.STATUS_NUM.CLOSED; const {wasDeleted: reportWasDeleted, parentReportID: deletedReportParentID} = useReportWasDeleted(reportIDFromRoute, report, isOptimisticDelete, userLeavingStatus); + // Track whether the current route is an own workspace chat. A vacation delegate split sends + // a temporary Onyx SET that wipes the report; by the time effects fire, report is undefined + // so we must persist the value in a ref updated synchronously during render. See issue #84248. + const isCurrentRouteOwnWorkspaceChatRef = useIsOwnWorkspaceChatRef(report, reportIDFromRoute); + const firstRender = useRef(true); // Navigation action that reads non-reactive context (concierge params, modal state, etc.) @@ -138,7 +144,10 @@ function ReportNavigateAwayHandler() { isEmpty(report) && (isMoneyRequest(prevReport) || isMoneyRequestReport(prevReport) || - isPolicyExpenseChat(prevReport) || + // Own workspace chats are excluded: a vacation delegate split sends a temporary + // Onyx SET that wipes the report — the chat was never intentionally removed. + // See issue #84248. + (isPolicyExpenseChat(prevReport) && !prevReport?.isOwnPolicyExpenseChat) || isGroupChat(prevReport) || isAdminRoom(prevReport) || isAnnounceRoom(prevReport)); @@ -194,6 +203,17 @@ function ReportNavigateAwayHandler() { return; } + // For own workspace chats, a vacation delegate split sends a temporary Onyx SET that + // silently wipes the report from Onyx — triggering this effect. We skip navigation here + // entirely: the re-fetch effect in ReportFetchHandler restores the data, which causes + // useReportWasDeleted to reset wasDeleted → false, and this effect exits early on the + // next run. Genuine workspace deletions (e.g. user removed, workspace closed) always + // trigger the "navigate on removal" effect above via userLeavingStatus / didReportClose, + // never via this path alone. See issue #84248. + if (isCurrentRouteOwnWorkspaceChatRef.current) { + return; + } + // Try to navigate to parent report if available if (deletedReportParentID && !isMoneyRequestReportPendingDeletion(deletedReportParentID)) { Navigation.isNavigationReady().then(() => {