From 7d12b9fd36252d33d4d50cd5ed533ebfca847b9e Mon Sep 17 00:00:00 2001 From: cretadn22 Date: Mon, 12 Oct 2026 14:49:51 +0700 Subject: [PATCH 1/9] Thread report actions through clearAllRelatedReportActionErrors --- src/libs/actions/ClearReportActionErrors.ts | 21 ++- tests/unit/ClearReportActionErrorsTest.ts | 194 ++++++++++++++++++++ 2 files changed, 207 insertions(+), 8 deletions(-) diff --git a/src/libs/actions/ClearReportActionErrors.ts b/src/libs/actions/ClearReportActionErrors.ts index 7b2fc7746c1a..b1ddaa8b98d4 100644 --- a/src/libs/actions/ClearReportActionErrors.ts +++ b/src/libs/actions/ClearReportActionErrors.ts @@ -1,4 +1,4 @@ -import {getLinkedTransactionID, getReportAction, getReportActionMessage, isCreatedTaskReportAction, isRejectedAction} from '@libs/ReportActionsUtils'; +import {getLinkedTransactionID, getReportActionMessage, isCreatedTaskReportAction, isRejectedAction} from '@libs/ReportActionsUtils'; import {getOriginalReportID} from '@libs/ReportUtils'; import {buildOptimisticSnapshotData} from '@libs/SearchQueryUtils'; @@ -19,6 +19,7 @@ type IgnoreDirection = 'parent' | 'child'; /** The subset of report data needed to walk the parent hierarchy when clearing related errors */ type ReportHierarchyInfo = Pick; +// TODO: Remove this transitional fallback once all callers pass the `reportActions` param (https://github.com/Expensify/App/issues/96139) let allReportActions: OnyxCollection; Onyx.connectWithoutView({ key: ONYXKEYS.COLLECTION.REPORT_ACTIONS, @@ -33,7 +34,7 @@ Onyx.connectWithoutView({ }, }); -function clearReportActionErrors(reportAction: ReportAction, originalReportID: string | undefined, keys?: string[]) { +function clearReportActionErrors(reportAction: ReportAction, originalReportID: string | undefined, keys?: string[], reportActions?: OnyxCollection) { if (!reportAction?.reportActionID) { return; } @@ -52,7 +53,7 @@ function clearReportActionErrors(reportAction: ReportAction, originalReportID: s // Also clean up any orphaned optimistic reject actions (REJECTED/REJECTED_TO_SUBMITTER) // from the same report. When a rejection fails, the comment action gets the error but the // corresponding reject action remains with pendingAction ADD and no errors. - const siblingActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${originalReportID}`]; + const siblingActions = (reportActions ?? allReportActions)?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${originalReportID}`]; if (siblingActions) { for (const [actionID, siblingAction] of Object.entries(siblingActions)) { if ( @@ -125,21 +126,23 @@ type ClearAllRelatedReportActionErrorsParams = { ignore?: IgnoreDirection; keys?: string[]; reports?: OnyxCollection; + /** Report actions data used for the orphaned-reject-sibling cleanup and the parent/child walks, keyed by `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}` */ + reportActions?: OnyxCollection; }; -function clearAllRelatedReportActionErrors({reportID, reportAction, originalReportID, isOffline, ignore, keys, reports}: ClearAllRelatedReportActionErrorsParams) { +function clearAllRelatedReportActionErrors({reportID, reportAction, originalReportID, isOffline, ignore, keys, reports, reportActions}: ClearAllRelatedReportActionErrorsParams) { const errorKeys = keys ?? Object.keys(reportAction?.errors ?? {}); if (!reportAction || errorKeys.length === 0 || !reportID) { return; } - clearReportActionErrors(reportAction, originalReportID, keys); + clearReportActionErrors(reportAction, originalReportID, keys, reportActions); const report = (reports ?? allReports)?.[`${ONYXKEYS.COLLECTION.REPORT}${reportID}`]; if (report?.parentReportID && report?.parentReportActionID && ignore !== 'parent') { - const parentReportAction = getReportAction(report.parentReportID, report.parentReportActionID); + const parentReportActions = (reportActions ?? allReportActions)?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`] ?? {}; + const parentReportAction = parentReportActions[report.parentReportActionID]; const parentErrorKeys = Object.keys(parentReportAction?.errors ?? {}).filter((err) => errorKeys.includes(err)); - const parentReportActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${report.parentReportID}`] ?? {}; const parentOriginalReportID = getOriginalReportID(report.parentReportID, parentReportAction, parentReportActions, isOffline); clearAllRelatedReportActionErrors({ @@ -150,11 +153,12 @@ function clearAllRelatedReportActionErrors({reportID, reportAction, originalRepo ignore: 'child', keys: parentErrorKeys, reports, + reportActions, }); } if (reportAction.childReportID && ignore !== 'child') { - const childActions = allReportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportAction.childReportID}`] ?? {}; + const childActions = (reportActions ?? allReportActions)?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportAction.childReportID}`] ?? {}; for (const action of Object.values(childActions)) { const childErrorKeys = Object.keys(action.errors ?? {}).filter((err) => errorKeys.includes(err)); const childOriginalReportID = getOriginalReportID(reportAction.childReportID, action, childActions, isOffline); @@ -166,6 +170,7 @@ function clearAllRelatedReportActionErrors({reportID, reportAction, originalRepo ignore: 'parent', keys: childErrorKeys, reports, + reportActions, }); } } diff --git a/tests/unit/ClearReportActionErrorsTest.ts b/tests/unit/ClearReportActionErrorsTest.ts index 51def290c99f..3f7b3c564abe 100644 --- a/tests/unit/ClearReportActionErrorsTest.ts +++ b/tests/unit/ClearReportActionErrorsTest.ts @@ -15,6 +15,7 @@ const PARENT_REPORT_ID = '2'; const CHILD_REPORT_ID = '3'; const GRANDPARENT_REPORT_ID = '4'; const REPORT_ACTION_ID = '100'; +const SIBLING_REPORT_ACTION_ID = '101'; const PARENT_REPORT_ACTION_ID = '200'; const CHILD_REPORT_ACTION_ID = '300'; const GRANDPARENT_REPORT_ACTION_ID = '400'; @@ -560,5 +561,198 @@ describe('ClearReportActionErrors', () => { const parentReportActions = await getReportActionsFromOnyx(PARENT_REPORT_ID); expect(parentReportActions?.[PARENT_REPORT_ACTION_ID]?.errors).toEqual({sharedError: 'Parent error message'}); }); + + it('should clean up orphaned reject actions based on the reportActions parameter', async () => { + // Given an optimistic action in Onyx next to a sibling that Onyx knows as a plain submitted action, + // while the reportActions parameter presents that same sibling as an orphaned optimistic reject + // action (proving the sibling cleanup reads the caller-supplied data, not a hidden cache) + const reportAction = getFakeReportAction(Number(REPORT_ACTION_ID), { + errors: {error1: 'Error message'}, + isOptimisticAction: true, + }); + const seededSiblingAction = getFakeReportAction(Number(SIBLING_REPORT_ACTION_ID), { + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + errors: undefined, + }); + const rejectSiblingAction = getFakeReportAction(Number(SIBLING_REPORT_ACTION_ID), { + actionName: CONST.REPORT.ACTIONS.TYPE.REJECTED, + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + errors: undefined, + }); + + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`, { + [REPORT_ACTION_ID]: reportAction, + [SIBLING_REPORT_ACTION_ID]: seededSiblingAction, + }); + await waitForBatchedUpdates(); + + // When clearAllRelatedReportActionErrors is called with the sibling presented as a reject action in the parameter + clearAllRelatedReportActionErrors({ + reportID: REPORT_ID, + reportAction, + originalReportID: REPORT_ID, + isOffline: false, + reportActions: { + [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`]: { + [REPORT_ACTION_ID]: reportAction, + [SIBLING_REPORT_ACTION_ID]: rejectSiblingAction, + }, + }, + }); + await waitForBatchedUpdates(); + + // Then the sibling should be deleted because the parameter identified it as an orphaned reject action + const reportActions = await getReportActionsFromOnyx(REPORT_ID); + expect(reportActions?.[SIBLING_REPORT_ACTION_ID]).toBeUndefined(); + }); + + it('should thread the reportActions parameter into the parent walk recursion', async () => { + // Given a parent action that Onyx knows as a plain action next to a non-reject sibling, while the + // reportActions parameter presents the parent action as optimistic and its sibling as an orphaned + // reject action — the sibling can only be deleted if the recursive parent call forwards the parameter + const reportAction = getFakeReportAction(Number(REPORT_ACTION_ID), { + errors: {sharedError: 'Error message'}, + }); + const seededParentReportAction = getFakeReportAction(Number(PARENT_REPORT_ACTION_ID), { + errors: {sharedError: 'Parent error message'}, + }); + const optimisticParentReportAction = getFakeReportAction(Number(PARENT_REPORT_ACTION_ID), { + errors: {sharedError: 'Parent error message'}, + isOptimisticAction: true, + }); + const seededSiblingAction = getFakeReportAction(Number(SIBLING_REPORT_ACTION_ID), { + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + errors: undefined, + }); + const rejectSiblingAction = getFakeReportAction(Number(SIBLING_REPORT_ACTION_ID), { + actionName: CONST.REPORT.ACTIONS.TYPE.REJECTED, + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + errors: undefined, + }); + + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`, { + [REPORT_ACTION_ID]: reportAction, + }); + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${PARENT_REPORT_ID}`, { + [PARENT_REPORT_ACTION_ID]: seededParentReportAction, + [SIBLING_REPORT_ACTION_ID]: seededSiblingAction, + }); + await waitForBatchedUpdates(); + + // When clearAllRelatedReportActionErrors is called with the full hierarchy and actions supplied via parameters + clearAllRelatedReportActionErrors({ + reportID: REPORT_ID, + reportAction, + originalReportID: REPORT_ID, + isOffline: false, + reports: { + [`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`]: {parentReportID: PARENT_REPORT_ID, parentReportActionID: PARENT_REPORT_ACTION_ID}, + }, + reportActions: { + [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`]: { + [REPORT_ACTION_ID]: reportAction, + }, + [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${PARENT_REPORT_ID}`]: { + [PARENT_REPORT_ACTION_ID]: optimisticParentReportAction, + [SIBLING_REPORT_ACTION_ID]: rejectSiblingAction, + }, + }, + }); + await waitForBatchedUpdates(); + + // Then the parent frame should have deleted the reject sibling, proving it read the forwarded parameter + const parentReportActions = await getReportActionsFromOnyx(PARENT_REPORT_ID); + expect(parentReportActions?.[SIBLING_REPORT_ACTION_ID]).toBeUndefined(); + }); + + it('should not clean up reject actions when the supplied reportActions collection is missing the data', async () => { + // Given an optimistic action and an orphaned optimistic reject sibling both seeded in Onyx, but a + // caller-supplied reportActions collection that is empty (the function must trust the caller's data + // and not fall back to the module-level cache per key) + const reportAction = getFakeReportAction(Number(REPORT_ACTION_ID), { + errors: {error1: 'Error message'}, + isOptimisticAction: true, + }); + const rejectSiblingAction = getFakeReportAction(Number(SIBLING_REPORT_ACTION_ID), { + actionName: CONST.REPORT.ACTIONS.TYPE.REJECTED, + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + errors: undefined, + }); + + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`, { + [REPORT_ACTION_ID]: reportAction, + [SIBLING_REPORT_ACTION_ID]: rejectSiblingAction, + }); + await waitForBatchedUpdates(); + + // When clearAllRelatedReportActionErrors is called with an empty reportActions collection + clearAllRelatedReportActionErrors({reportID: REPORT_ID, reportAction, originalReportID: REPORT_ID, isOffline: false, reportActions: {}}); + await waitForBatchedUpdates(); + + // Then the reject sibling should remain because the supplied collection has no data for the report + const reportActions = await getReportActionsFromOnyx(REPORT_ID); + expect(reportActions?.[SIBLING_REPORT_ACTION_ID]).toBeDefined(); + }); + + it('should not clear child errors when the supplied reportActions collection is missing the data', async () => { + // Given a parent action with matching child errors seeded in Onyx, but a caller-supplied + // reportActions collection that is empty, so the child walk has nothing to iterate + const reportAction = getFakeReportAction(Number(REPORT_ACTION_ID), { + childReportID: CHILD_REPORT_ID, + errors: {sharedError: 'Error message'}, + }); + const childReportAction = getFakeReportAction(Number(CHILD_REPORT_ACTION_ID), { + errors: {sharedError: 'Child error message'}, + }); + + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, createMockReport()); + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`, { + [REPORT_ACTION_ID]: reportAction, + }); + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${CHILD_REPORT_ID}`, { + [CHILD_REPORT_ACTION_ID]: childReportAction, + }); + await waitForBatchedUpdates(); + + // When clearAllRelatedReportActionErrors is called with an empty reportActions collection + clearAllRelatedReportActionErrors({reportID: REPORT_ID, reportAction, originalReportID: REPORT_ID, isOffline: false, reportActions: {}}); + await waitForBatchedUpdates(); + + // Then the child action's error should remain because the supplied collection has no child actions + const childReportActions = await getReportActionsFromOnyx(CHILD_REPORT_ID); + expect(childReportActions?.[CHILD_REPORT_ACTION_ID]?.errors).toEqual({sharedError: 'Child error message'}); + }); + + it('should not clear parent errors when the supplied reportActions collection is missing the data', async () => { + // Given a report whose parent action with matching errors exists in Onyx, but a caller-supplied + // reportActions collection that is empty, so the parent action cannot be resolved from the input + const report = createMockReport({ + parentReportID: PARENT_REPORT_ID, + parentReportActionID: PARENT_REPORT_ACTION_ID, + }); + const reportAction = getFakeReportAction(Number(REPORT_ACTION_ID), { + errors: {sharedError: 'Error message'}, + }); + const parentReportAction = getFakeReportAction(Number(PARENT_REPORT_ACTION_ID), { + errors: {sharedError: 'Parent error message'}, + }); + + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`, { + [REPORT_ACTION_ID]: reportAction, + }); + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${PARENT_REPORT_ID}`, { + [PARENT_REPORT_ACTION_ID]: parentReportAction, + }); + await waitForBatchedUpdates(); + + // When clearAllRelatedReportActionErrors is called with an empty reportActions collection + clearAllRelatedReportActionErrors({reportID: REPORT_ID, reportAction, originalReportID: REPORT_ID, isOffline: false, reportActions: {}}); + await waitForBatchedUpdates(); + + // Then the parent action's error should remain because the parent action was not in the supplied collection + const parentReportActions = await getReportActionsFromOnyx(PARENT_REPORT_ID); + expect(parentReportActions?.[PARENT_REPORT_ACTION_ID]?.errors).toEqual({sharedError: 'Parent error message'}); + }); }); }); From 5fa22e10c0739fdf08fc7a67c5629b98c19ac4cc Mon Sep 17 00:00:00 2001 From: cretadn22 Date: Mon, 12 Oct 2026 15:01:48 +0700 Subject: [PATCH 2/9] Thread report actions through clearAllRelatedReportActionErrors --- .../MoneyRequestReceiptView.tsx | 19 +++++++++++++++++-- src/libs/actions/ClearReportActionErrors.ts | 2 -- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestReceiptView.tsx b/src/components/ReportActionItem/MoneyRequestReceiptView.tsx index dc16d8eb13b0..778f0fc0ac34 100644 --- a/src/components/ReportActionItem/MoneyRequestReceiptView.tsx +++ b/src/components/ReportActionItem/MoneyRequestReceiptView.tsx @@ -158,6 +158,7 @@ function MoneyRequestReceiptView({ const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(parentReportID)}`); const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(parentReport?.parentReportID)}`); const [parentReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`); + const [allReportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS); const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID); const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED); const [isSelfTourViewed] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector}); @@ -570,7 +571,14 @@ function MoneyRequestReceiptView({ return; } clearError(linkedTransactionID); - clearAllRelatedReportActionErrors({reportID: report.reportID, reportAction: parentReportAction, originalReportID, isOffline, reports: reportsParentHierarchy}); + clearAllRelatedReportActionErrors({ + reportID: report.reportID, + reportAction: parentReportAction, + originalReportID, + isOffline, + reports: reportsParentHierarchy, + reportActions: allReportActions, + }); return; } if (!isEmptyObject(transactionAndReportActionErrors)) { @@ -578,7 +586,14 @@ function MoneyRequestReceiptView({ } if (!isEmptyObject(errorsWithoutReportCreation)) { clearError(transaction.transactionID); - clearAllRelatedReportActionErrors({reportID: report.reportID, reportAction: parentReportAction, originalReportID, isOffline, reports: reportsParentHierarchy}); + clearAllRelatedReportActionErrors({ + reportID: report.reportID, + reportAction: parentReportAction, + originalReportID, + isOffline, + reports: reportsParentHierarchy, + reportActions: allReportActions, + }); } if (!isEmptyObject(reportCreationError)) { if (isInNarrowPaneModal) { diff --git a/src/libs/actions/ClearReportActionErrors.ts b/src/libs/actions/ClearReportActionErrors.ts index b1ddaa8b98d4..f83593ea85e9 100644 --- a/src/libs/actions/ClearReportActionErrors.ts +++ b/src/libs/actions/ClearReportActionErrors.ts @@ -19,7 +19,6 @@ type IgnoreDirection = 'parent' | 'child'; /** The subset of report data needed to walk the parent hierarchy when clearing related errors */ type ReportHierarchyInfo = Pick; -// TODO: Remove this transitional fallback once all callers pass the `reportActions` param (https://github.com/Expensify/App/issues/96139) let allReportActions: OnyxCollection; Onyx.connectWithoutView({ key: ONYXKEYS.COLLECTION.REPORT_ACTIONS, @@ -126,7 +125,6 @@ type ClearAllRelatedReportActionErrorsParams = { ignore?: IgnoreDirection; keys?: string[]; reports?: OnyxCollection; - /** Report actions data used for the orphaned-reject-sibling cleanup and the parent/child walks, keyed by `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}` */ reportActions?: OnyxCollection; }; From c65c7f527b7d196ad283c8a0464b10c88a0b5177 Mon Sep 17 00:00:00 2001 From: cretadn22 Date: Mon, 12 Oct 2026 16:38:50 +0700 Subject: [PATCH 3/9] Narrow report action fields passed to error clearing --- .../MoneyRequestReceiptView.tsx | 4 +- src/selectors/ReportAction.ts | 45 +++++++++++++- tests/unit/ClearReportActionErrorsTest.ts | 62 ++++++++++++++++++- 3 files changed, 107 insertions(+), 4 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestReceiptView.tsx b/src/components/ReportActionItem/MoneyRequestReceiptView.tsx index 778f0fc0ac34..200adcee33c2 100644 --- a/src/components/ReportActionItem/MoneyRequestReceiptView.tsx +++ b/src/components/ReportActionItem/MoneyRequestReceiptView.tsx @@ -97,7 +97,7 @@ import type {ValueOf} from 'type-fest'; import {useRoute} from '@react-navigation/native'; import {hasSeenTourSelector} from '@selectors/Onboarding'; -import {transactionThreadReportIDSelector} from '@selectors/ReportAction'; +import {reportActionsErrorFieldsSelector, transactionThreadReportIDSelector} from '@selectors/ReportAction'; import {Str} from 'expensify-common'; import mapValues from 'lodash/mapValues'; import React, {useEffect, useMemo, useRef, useState} from 'react'; @@ -158,7 +158,7 @@ function MoneyRequestReceiptView({ const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(parentReportID)}`); const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(parentReport?.parentReportID)}`); const [parentReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`); - const [allReportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS); + const [allReportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS, {selector: reportActionsErrorFieldsSelector}); const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID); const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED); const [isSelfTourViewed] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector}); diff --git a/src/selectors/ReportAction.ts b/src/selectors/ReportAction.ts index 468dd9bfd28c..97993758f000 100644 --- a/src/selectors/ReportAction.ts +++ b/src/selectors/ReportAction.ts @@ -3,8 +3,9 @@ import {filterOutDeprecatedReportActions, getIOUActionForTransactionID, getLinke import CONST from '@src/CONST'; import type {ReportAction, ReportActions} from '@src/types/onyx'; import type {VisibleReportActionsDerivedValue} from '@src/types/onyx/DerivedValues'; +import mapOnyxCollectionItems from '@src/utils/mapOnyxCollectionItems'; -import type {OnyxEntry} from 'react-native-onyx'; +import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; import lodashFindLast from 'lodash/findLast'; @@ -142,6 +143,47 @@ function getReceiptScanFailedIOUActionDataSelector( const transactionThreadReportIDSelector = (transactionID: string | undefined) => (reportActions: OnyxEntry) => transactionID ? getIOUActionForTransactionID(Object.values(reportActions ?? {}), transactionID)?.childReportID : undefined; +/** + * Keeps only the fields `clearAllRelatedReportActionErrors` reads when walking related report actions. + * Nested fields (`errors`, `message`, `originalMessage`) are copied by reference so equality checks on the + * projected result short-circuit and unrelated action updates (reactions, read receipts, person data, ...) + * neither re-render the subscriber nor pay a deep comparison. + */ +function reportActionErrorFieldsSelector(reportAction: OnyxEntry): OnyxEntry { + return ( + reportAction && { + reportActionID: reportAction.reportActionID, + actionName: reportAction.actionName, + created: reportAction.created, + pendingAction: reportAction.pendingAction, + isOptimisticAction: reportAction.isOptimisticAction, + childReportID: reportAction.childReportID, + errors: reportAction.errors, + message: reportAction.message, + // Copying the deprecated originalMessage field is intentional. The projection must preserve the raw + // data so downstream helpers can resolve it through getOriginalMessage. + // eslint-disable-next-line @typescript-eslint/no-deprecated + originalMessage: reportAction.originalMessage, + } + ); +} + +function reportActionsErrorFieldsSelector(reportActions: OnyxCollection): OnyxCollection { + return mapOnyxCollectionItems(reportActions, (actions) => { + if (!actions) { + return actions; + } + const projectedActions: ReportActions = {}; + for (const [reportActionID, reportAction] of Object.entries(actions)) { + const projectedAction = reportActionErrorFieldsSelector(reportAction); + if (projectedAction) { + projectedActions[reportActionID] = projectedAction; + } + } + return projectedActions; + }); +} + export { getParentReportActionSelector, getLastClosedReportAction, @@ -150,6 +192,7 @@ export { getReportActionByIDSelector, getReceiptScanFailedIOUActionDataSelector, reportVisibleActionsSelector, + reportActionsErrorFieldsSelector, transactionThreadReportIDSelector, }; export type {NewestReportAction}; diff --git a/tests/unit/ClearReportActionErrorsTest.ts b/tests/unit/ClearReportActionErrorsTest.ts index 3f7b3c564abe..dc70ad9c6988 100644 --- a/tests/unit/ClearReportActionErrorsTest.ts +++ b/tests/unit/ClearReportActionErrorsTest.ts @@ -4,6 +4,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {ReportActions} from '@src/types/onyx'; +import {reportActionsErrorFieldsSelector} from '@selectors/ReportAction'; import Onyx from 'react-native-onyx'; import {createMockReport, getFakeReportAction} from '../utils/ReportTestUtils'; @@ -609,7 +610,7 @@ describe('ClearReportActionErrors', () => { it('should thread the reportActions parameter into the parent walk recursion', async () => { // Given a parent action that Onyx knows as a plain action next to a non-reject sibling, while the // reportActions parameter presents the parent action as optimistic and its sibling as an orphaned - // reject action — the sibling can only be deleted if the recursive parent call forwards the parameter + // reject action. The sibling can only be deleted if the recursive parent call forwards the parameter. const reportAction = getFakeReportAction(Number(REPORT_ACTION_ID), { errors: {sharedError: 'Error message'}, }); @@ -665,6 +666,65 @@ describe('ClearReportActionErrors', () => { expect(parentReportActions?.[SIBLING_REPORT_ACTION_ID]).toBeUndefined(); }); + it('should clear errors when the reportActions data is narrowed by reportActionsErrorFieldsSelector', async () => { + // Given the same hierarchy as the recursion test, but with the reportActions parameter passed + // through the selector components use to narrow each action to the fields the error clearing + // reads. This fails if the selector ever drops a field the walk or its helpers start consuming. + const reportAction = getFakeReportAction(Number(REPORT_ACTION_ID), { + errors: {sharedError: 'Error message'}, + }); + const seededParentReportAction = getFakeReportAction(Number(PARENT_REPORT_ACTION_ID), { + errors: {sharedError: 'Parent error message'}, + }); + const optimisticParentReportAction = getFakeReportAction(Number(PARENT_REPORT_ACTION_ID), { + errors: {sharedError: 'Parent error message'}, + isOptimisticAction: true, + }); + const seededSiblingAction = getFakeReportAction(Number(SIBLING_REPORT_ACTION_ID), { + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + errors: undefined, + }); + const rejectSiblingAction = getFakeReportAction(Number(SIBLING_REPORT_ACTION_ID), { + actionName: CONST.REPORT.ACTIONS.TYPE.REJECTED, + pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, + errors: undefined, + }); + + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`, { + [REPORT_ACTION_ID]: reportAction, + }); + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${PARENT_REPORT_ID}`, { + [PARENT_REPORT_ACTION_ID]: seededParentReportAction, + [SIBLING_REPORT_ACTION_ID]: seededSiblingAction, + }); + await waitForBatchedUpdates(); + + // When clearAllRelatedReportActionErrors is called with selector-narrowed reportActions data + clearAllRelatedReportActionErrors({ + reportID: REPORT_ID, + reportAction, + originalReportID: REPORT_ID, + isOffline: false, + reports: { + [`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`]: {parentReportID: PARENT_REPORT_ID, parentReportActionID: PARENT_REPORT_ACTION_ID}, + }, + reportActions: reportActionsErrorFieldsSelector({ + [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`]: { + [REPORT_ACTION_ID]: reportAction, + }, + [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${PARENT_REPORT_ID}`]: { + [PARENT_REPORT_ACTION_ID]: optimisticParentReportAction, + [SIBLING_REPORT_ACTION_ID]: rejectSiblingAction, + }, + }), + }); + await waitForBatchedUpdates(); + + // Then the narrowed data should still drive the full walk and delete the reject sibling + const parentReportActions = await getReportActionsFromOnyx(PARENT_REPORT_ID); + expect(parentReportActions?.[SIBLING_REPORT_ACTION_ID]).toBeUndefined(); + }); + it('should not clean up reject actions when the supplied reportActions collection is missing the data', async () => { // Given an optimistic action and an orphaned optimistic reject sibling both seeded in Onyx, but a // caller-supplied reportActions collection that is empty (the function must trust the caller's data From a05bd367f5d5f5e257aa1826e13cd5e58aff7cb0 Mon Sep 17 00:00:00 2001 From: cretadn22 Date: Mon, 12 Oct 2026 16:49:11 +0700 Subject: [PATCH 4/9] Narrow report action fields passed to error clearing --- src/components/ReportActionItem/MoneyRequestReceiptView.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/components/ReportActionItem/MoneyRequestReceiptView.tsx b/src/components/ReportActionItem/MoneyRequestReceiptView.tsx index 200adcee33c2..ecb0a033105e 100644 --- a/src/components/ReportActionItem/MoneyRequestReceiptView.tsx +++ b/src/components/ReportActionItem/MoneyRequestReceiptView.tsx @@ -158,7 +158,7 @@ function MoneyRequestReceiptView({ const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(parentReportID)}`); const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(parentReport?.parentReportID)}`); const [parentReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`); - const [allReportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS, {selector: reportActionsErrorFieldsSelector}); + const [reportActionsErrorFields] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS, {selector: reportActionsErrorFieldsSelector}); const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID); const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED); const [isSelfTourViewed] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector}); @@ -577,7 +577,7 @@ function MoneyRequestReceiptView({ originalReportID, isOffline, reports: reportsParentHierarchy, - reportActions: allReportActions, + reportActions: reportActionsErrorFields, }); return; } @@ -592,7 +592,7 @@ function MoneyRequestReceiptView({ originalReportID, isOffline, reports: reportsParentHierarchy, - reportActions: allReportActions, + reportActions: reportActionsErrorFields, }); } if (!isEmptyObject(reportCreationError)) { From 57189f98ce73919693a8824dc799b7a048cbdd6e Mon Sep 17 00:00:00 2001 From: cretadn22 Date: Mon, 26 Oct 2026 15:31:04 +0700 Subject: [PATCH 5/9] Import CONST in ClearReportActionErrorsTest --- tests/unit/ClearReportActionErrorsTest.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/ClearReportActionErrorsTest.ts b/tests/unit/ClearReportActionErrorsTest.ts index a183fb994496..0bb9f46aa78e 100644 --- a/tests/unit/ClearReportActionErrorsTest.ts +++ b/tests/unit/ClearReportActionErrorsTest.ts @@ -1,5 +1,6 @@ import {clearAllRelatedReportActionErrors} from '@libs/actions/ClearReportActionErrors'; +import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {ReportActions} from '@src/types/onyx'; From fd4406d87705c67a58f823d62aa5a9f93f4233c5 Mon Sep 17 00:00:00 2001 From: cretadn22 Date: Thu, 29 Oct 2026 11:03:50 +0700 Subject: [PATCH 6/9] Introduced useRelatedReportActionsErrorFields --- .../MoneyRequestReceiptView.tsx | 9 +- .../useRelatedReportActionsErrorFields.ts | 30 +++++++ src/selectors/ReportAction.ts | 61 +++++++++++--- tests/unit/ClearReportActionErrorsTest.ts | 14 ++-- tests/unit/selectors/ReportActionTest.ts | 82 ++++++++++++++++++- 5 files changed, 173 insertions(+), 23 deletions(-) create mode 100644 src/hooks/useRelatedReportActionsErrorFields.ts diff --git a/src/components/ReportActionItem/MoneyRequestReceiptView.tsx b/src/components/ReportActionItem/MoneyRequestReceiptView.tsx index 92ce0696a252..3eed8e7d900a 100644 --- a/src/components/ReportActionItem/MoneyRequestReceiptView.tsx +++ b/src/components/ReportActionItem/MoneyRequestReceiptView.tsx @@ -28,6 +28,7 @@ import useOriginalReportID from '@hooks/useOriginalReportID'; import usePermissions from '@hooks/usePermissions'; import {usePersonalDetail} from '@hooks/usePersonalDetails'; import usePrevious from '@hooks/usePrevious'; +import useRelatedReportActionsErrorFields from '@hooks/useRelatedReportActionsErrorFields'; import useReportIsArchived from '@hooks/useReportIsArchived'; import useReportsParentHierarchy from '@hooks/useReportsParentHierarchy'; import useReportTransactionsCollection from '@hooks/useReportTransactionsCollection'; @@ -98,7 +99,7 @@ import type {ValueOf} from 'type-fest'; import {useRoute} from '@react-navigation/native'; import {hasSeenTourSelector} from '@selectors/Onboarding'; -import {reportActionsErrorFieldsSelector, transactionThreadReportIDSelector} from '@selectors/ReportAction'; +import {transactionThreadReportIDSelector} from '@selectors/ReportAction'; import {Str} from 'expensify-common'; import mapValues from 'lodash/mapValues'; import React, {useEffect, useMemo, useRef, useState} from 'react'; @@ -160,7 +161,6 @@ function MoneyRequestReceiptView({ const [parentReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(parentReportID)}`); const [chatReport] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT}${getNonEmptyStringOnyxID(parentReport?.parentReportID)}`); const [parentReportActions] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${parentReportID}`); - const [reportActionsErrorFields] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS, {selector: reportActionsErrorFieldsSelector}); const [conciergeReportID] = useOnyx(ONYXKEYS.CONCIERGE_REPORT_ID); const [introSelected] = useOnyx(ONYXKEYS.NVP_INTRO_SELECTED); const [isSelfTourViewed] = useOnyx(ONYXKEYS.NVP_ONBOARDING, {selector: hasSeenTourSelector}); @@ -175,6 +175,7 @@ function MoneyRequestReceiptView({ const originalReportID = useOriginalReportID(report?.reportID, parentReportAction); const reportsParentHierarchy = useReportsParentHierarchy(report?.reportID); + const relatedReportActions = useRelatedReportActionsErrorFields(reportsParentHierarchy, originalReportID, parentReportAction?.childReportID); const {iouReport, chatReport: chatIOUReport, isChatIOUReportArchived} = useGetIOUReportFromReportAction(parentReportAction); const iouReportTransactionsCollection = useReportTransactionsCollection(iouReport?.reportID); const iouReportTransactions = Object.values(iouReportTransactionsCollection); @@ -590,7 +591,7 @@ function MoneyRequestReceiptView({ originalReportID, isOffline, reports: reportsParentHierarchy, - reportActions: reportActionsErrorFields, + reportActions: relatedReportActions, }); return; } @@ -605,7 +606,7 @@ function MoneyRequestReceiptView({ originalReportID, isOffline, reports: reportsParentHierarchy, - reportActions: reportActionsErrorFields, + reportActions: relatedReportActions, }); } if (!isEmptyObject(reportCreationError)) { diff --git a/src/hooks/useRelatedReportActionsErrorFields.ts b/src/hooks/useRelatedReportActionsErrorFields.ts new file mode 100644 index 000000000000..6e3a5cbbf20c --- /dev/null +++ b/src/hooks/useRelatedReportActionsErrorFields.ts @@ -0,0 +1,30 @@ +import type {ReportHierarchyInfo} from '@userActions/ClearReportActionErrors'; + +import ONYXKEYS from '@src/ONYXKEYS'; +import {relatedReportActionsErrorFieldsSelector} from '@src/selectors/ReportAction'; +import type {ReportActions} from '@src/types/onyx'; + +import type {OnyxCollection} from 'react-native-onyx'; + +import useOnyx from './useOnyx'; + +/** + * Subscribes to the report actions `clearAllRelatedReportActionErrors` walks when an error is dismissed, narrowed to + * the fields it reads: the actions of every report in `reportsParentHierarchy` (see `useReportsParentHierarchy`), of + * the original report holding the dismissed action, and of the threads below `childRootReportID` that hang off + * errored actions. The selector only looks up those keys instead of mapping the whole collection, so a write to an + * unrelated report action costs a few lookups rather than a deep comparison over every action in the account. + */ +function useRelatedReportActionsErrorFields( + reportsParentHierarchy: OnyxCollection, + originalReportID: string | undefined, + childRootReportID: string | undefined, +): OnyxCollection { + const reportIDs = Object.keys(reportsParentHierarchy ?? {}).map((key) => key.slice(ONYXKEYS.COLLECTION.REPORT.length)); + const [relatedReportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS, { + selector: relatedReportActionsErrorFieldsSelector([...reportIDs, originalReportID], childRootReportID), + }); + return relatedReportActions; +} + +export default useRelatedReportActionsErrorFields; diff --git a/src/selectors/ReportAction.ts b/src/selectors/ReportAction.ts index e75e65b742e9..be202b00c3e9 100644 --- a/src/selectors/ReportAction.ts +++ b/src/selectors/ReportAction.ts @@ -13,7 +13,6 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {ReportAction, ReportActions} from '@src/types/onyx'; import type {VisibleReportActionsDerivedValue} from '@src/types/onyx/DerivedValues'; -import mapOnyxCollectionItems from '@src/utils/mapOnyxCollectionItems'; import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; @@ -178,20 +177,56 @@ function reportActionErrorFieldsSelector(reportAction: OnyxEntry): ); } -function reportActionsErrorFieldsSelector(reportActions: OnyxCollection): OnyxCollection { - return mapOnyxCollectionItems(reportActions, (actions) => { - if (!actions) { - return actions; +function projectReportActionsErrorFields(actions: ReportActions): ReportActions { + const projectedActions: ReportActions = {}; + for (const [reportActionID, reportAction] of Object.entries(actions)) { + const projectedAction = reportActionErrorFieldsSelector(reportAction); + if (projectedAction) { + projectedActions[reportActionID] = projectedAction; } - const projectedActions: ReportActions = {}; - for (const [reportActionID, reportAction] of Object.entries(actions)) { - const projectedAction = reportActionErrorFieldsSelector(reportAction); - if (projectedAction) { - projectedActions[reportActionID] = projectedAction; + } + return projectedActions; +} + +/** + * Creates a selector returning the report actions `clearAllRelatedReportActionErrors` walks, narrowed to the fields it + * reads: the actions of every report in `reportIDs` (the report whose error is dismissed, its ancestors and the original + * report holding the dismissed action), plus the threads below `childRootReportID` that hang off actions with errors. + * The walk returns early from an action without errors, so following only errored actions downward is exact. + * Only those keys are looked up, so a write to an unrelated report action neither maps the whole collection nor pays + * a deep comparison over it. + */ +function relatedReportActionsErrorFieldsSelector(reportIDs: Array, childRootReportID: string | undefined) { + return function selectRelatedReportActionsErrorFields(reportActions: OnyxCollection): OnyxCollection { + const result: OnyxCollection = {}; + const visitedReportIDs = new Set(); + const collect = (reportID: string | undefined, shouldFollowErroredThreads: boolean) => { + // The visited set also terminates the walk when thread links form a cycle + if (!reportID || visitedReportIDs.has(reportID)) { + return; } + visitedReportIDs.add(reportID); + const actions = reportActions?.[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`]; + if (!actions) { + return; + } + result[`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`] = projectReportActionsErrorFields(actions); + if (!shouldFollowErroredThreads) { + return; + } + for (const action of Object.values(actions)) { + if (action.childReportID && Object.keys(action.errors ?? {}).length > 0) { + collect(action.childReportID, true); + } + } + }; + // The child root is usually also one of `reportIDs`, so descend from it before the plain lookups mark it visited + collect(childRootReportID, true); + for (const reportID of reportIDs) { + collect(reportID, false); } - return projectedActions; - }); + return result; + }; } /** Returns the ID of the author's newest comment in the report that can show the feedback prompt. */ @@ -237,7 +272,7 @@ export { getReportActionByIDSelector, getReceiptScanFailedIOUActionDataSelector, reportVisibleActionsSelector, - reportActionsErrorFieldsSelector, + relatedReportActionsErrorFieldsSelector, forwardedSinceLastSubmitReportIDsSelector, transactionThreadReportIDSelector, getParentReportActionWithoutThreadRepliesSelector, diff --git a/tests/unit/ClearReportActionErrorsTest.ts b/tests/unit/ClearReportActionErrorsTest.ts index 0bb9f46aa78e..c9aefc656d3b 100644 --- a/tests/unit/ClearReportActionErrorsTest.ts +++ b/tests/unit/ClearReportActionErrorsTest.ts @@ -4,7 +4,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import type {ReportActions} from '@src/types/onyx'; -import {reportActionsErrorFieldsSelector} from '@selectors/ReportAction'; +import {relatedReportActionsErrorFieldsSelector} from '@selectors/ReportAction'; import Onyx from 'react-native-onyx'; import {createMockReport, getFakeReportAction} from '../utils/ReportTestUtils'; @@ -675,10 +675,11 @@ describe('ClearReportActionErrors', () => { expect(parentReportActions?.[SIBLING_REPORT_ACTION_ID]).toBeUndefined(); }); - it('should clear errors when the reportActions data is narrowed by reportActionsErrorFieldsSelector', async () => { + it('should clear errors when the reportActions data is narrowed by relatedReportActionsErrorFieldsSelector', async () => { // Given the same hierarchy as the recursion test, but with the reportActions parameter passed - // through the selector components use to narrow each action to the fields the error clearing - // reads. This fails if the selector ever drops a field the walk or its helpers start consuming. + // through the selector components use to scope the data to the hierarchy and narrow each action to + // the fields the error clearing reads. This fails if the selector ever drops a report the walk looks + // up or a field the walk or its helpers start consuming. const reportAction = getFakeReportAction(Number(REPORT_ACTION_ID), { errors: {sharedError: 'Error message'}, }); @@ -717,7 +718,10 @@ describe('ClearReportActionErrors', () => { reports: { [`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`]: {parentReportID: PARENT_REPORT_ID, parentReportActionID: PARENT_REPORT_ACTION_ID}, }, - reportActions: reportActionsErrorFieldsSelector({ + reportActions: relatedReportActionsErrorFieldsSelector( + [REPORT_ID, PARENT_REPORT_ID], + reportAction.childReportID, + )({ [`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`]: { [REPORT_ACTION_ID]: reportAction, }, diff --git a/tests/unit/selectors/ReportActionTest.ts b/tests/unit/selectors/ReportActionTest.ts index 916076705eed..c9db75a1d319 100644 --- a/tests/unit/selectors/ReportActionTest.ts +++ b/tests/unit/selectors/ReportActionTest.ts @@ -1,7 +1,10 @@ import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; import type {ReportAction, ReportActions} from '@src/types/onyx'; -import {getLatestFeedbackActionIDByAuthorSelector, getReceiptScanFailedIOUActionDataSelector} from '@selectors/ReportAction'; +import type {OnyxCollection} from 'react-native-onyx'; + +import {getLatestFeedbackActionIDByAuthorSelector, getReceiptScanFailedIOUActionDataSelector, relatedReportActionsErrorFieldsSelector} from '@selectors/ReportAction'; const CURRENT_USER_ACCOUNT_ID = 123456789; const OTHER_USER_ACCOUNT_ID = 987654321; @@ -179,3 +182,80 @@ describe('getLatestFeedbackActionIDByAuthorSelector', () => { expect(getLatestFeedbackActionIDByAuthorSelector(undefined)(reportActions)).toBeUndefined(); }); }); + +describe('relatedReportActionsErrorFieldsSelector', () => { + const THREAD_REPORT_ID = 'thread1'; + const PARENT_REPORT_ID = 'parent1'; + const CHAT_REPORT_ID = 'chat1'; + const UNRELATED_REPORT_ID = 'unrelated1'; + const ERRORED_THREAD_REPORT_ID = 'erroredThread1'; + const CLEAN_THREAD_REPORT_ID = 'cleanThread1'; + + const reportActionsKey = (reportID: string) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}` as const; + + it('should return the actions of the listed reports projected to the error fields, and nothing else', () => { + // Given actions for a thread, its parent and an unrelated report, where the parent action carries fields the error clearing never reads + const parentAction = createIOUAction('iou1', {childReportID: THREAD_REPORT_ID, errors: {error1: 'Error message'}, person: [{type: 'TEXT', text: 'Jane'}]}); + const reportActions: OnyxCollection = { + [reportActionsKey(THREAD_REPORT_ID)]: {comment1: createIOUAction('comment1')}, + [reportActionsKey(PARENT_REPORT_ID)]: {iou1: parentAction}, + [reportActionsKey(UNRELATED_REPORT_ID)]: {iou2: createIOUAction('iou2')}, + }; + + // When the selector is applied for the thread and its parent without a child root + const result = relatedReportActionsErrorFieldsSelector([THREAD_REPORT_ID, PARENT_REPORT_ID], undefined)(reportActions); + + // Then only the listed reports are returned, so unrelated report action writes cannot change the result + expect(Object.keys(result ?? {})).toEqual([reportActionsKey(THREAD_REPORT_ID), reportActionsKey(PARENT_REPORT_ID)]); + + // Then each action keeps the fields the walk and its helpers read, and drops the rest so unrelated action updates compare equal + const projectedParentAction = result?.[reportActionsKey(PARENT_REPORT_ID)]?.iou1; + expect(projectedParentAction).toEqual({ + reportActionID: 'iou1', + actionName: CONST.REPORT.ACTIONS.TYPE.IOU, + created: parentAction.created, + pendingAction: undefined, + isOptimisticAction: undefined, + childReportID: THREAD_REPORT_ID, + errors: parentAction.errors, + message: parentAction.message, + // The projection intentionally preserves the deprecated raw field so getOriginalMessage can resolve it downstream + // eslint-disable-next-line @typescript-eslint/no-deprecated + originalMessage: parentAction.originalMessage, + }); + expect(projectedParentAction).not.toHaveProperty('person'); + expect(projectedParentAction).not.toHaveProperty('actorAccountID'); + }); + + it('should follow threads below the child root only through actions that have errors', () => { + // Given a child root that is also one of the listed reports, holding an errored action with a thread and a clean action with a thread + const reportActions: OnyxCollection = { + [reportActionsKey(THREAD_REPORT_ID)]: { + errored1: createIOUAction('errored1', {childReportID: ERRORED_THREAD_REPORT_ID, errors: {error1: 'Error message'}}), + clean1: createIOUAction('clean1', {childReportID: CLEAN_THREAD_REPORT_ID}), + }, + [reportActionsKey(ERRORED_THREAD_REPORT_ID)]: {reply1: createIOUAction('reply1')}, + [reportActionsKey(CLEAN_THREAD_REPORT_ID)]: {reply2: createIOUAction('reply2')}, + }; + + // When the selector is applied with the thread both listed and used as the child root + const result = relatedReportActionsErrorFieldsSelector([THREAD_REPORT_ID], THREAD_REPORT_ID)(reportActions); + + // Then the thread hanging off the errored action is included, since the walk recurses into it, while the clean action's thread is not + expect(Object.keys(result ?? {}).sort()).toEqual([reportActionsKey(ERRORED_THREAD_REPORT_ID), reportActionsKey(THREAD_REPORT_ID)].sort()); + }); + + it('should skip missing and undefined report IDs and terminate when thread links form a cycle', () => { + // Given two errored actions whose threads point back at each other, a parent report that is not loaded and an undefined original report ID + const reportActions: OnyxCollection = { + [reportActionsKey(THREAD_REPORT_ID)]: {errored1: createIOUAction('errored1', {childReportID: CHAT_REPORT_ID, errors: {error1: 'Error message'}})}, + [reportActionsKey(CHAT_REPORT_ID)]: {errored2: createIOUAction('errored2', {childReportID: THREAD_REPORT_ID, errors: {error1: 'Error message'}})}, + }; + + // When the selector is applied with the cycle reachable from the child root + const result = relatedReportActionsErrorFieldsSelector([THREAD_REPORT_ID, PARENT_REPORT_ID, undefined], THREAD_REPORT_ID)(reportActions); + + // Then both reports in the cycle are returned once, the unloaded report is left out and the selector returns instead of hanging + expect(Object.keys(result ?? {}).sort()).toEqual([reportActionsKey(CHAT_REPORT_ID), reportActionsKey(THREAD_REPORT_ID)].sort()); + }); +}); From 6861b7c6f7f1ee4535d5d8270473dac997231f7b Mon Sep 17 00:00:00 2001 From: cretadn22 Date: Tue, 3 Nov 2026 22:55:15 +0700 Subject: [PATCH 7/9] replacing useRelatedReportActionsErrorFields with useRelatedReportActions --- .../MoneyRequestReceiptView.tsx | 4 +- src/hooks/useRelatedReportActions.ts | 30 +++++++++++ .../useRelatedReportActionsErrorFields.ts | 30 ----------- src/selectors/ReportAction.ts | 54 ++++--------------- tests/unit/ClearReportActionErrorsTest.ts | 15 +++--- tests/unit/selectors/ReportActionTest.ts | 37 +++++-------- 6 files changed, 60 insertions(+), 110 deletions(-) create mode 100644 src/hooks/useRelatedReportActions.ts delete mode 100644 src/hooks/useRelatedReportActionsErrorFields.ts diff --git a/src/components/ReportActionItem/MoneyRequestReceiptView.tsx b/src/components/ReportActionItem/MoneyRequestReceiptView.tsx index 3eed8e7d900a..1dd5c27ef78b 100644 --- a/src/components/ReportActionItem/MoneyRequestReceiptView.tsx +++ b/src/components/ReportActionItem/MoneyRequestReceiptView.tsx @@ -28,7 +28,7 @@ import useOriginalReportID from '@hooks/useOriginalReportID'; import usePermissions from '@hooks/usePermissions'; import {usePersonalDetail} from '@hooks/usePersonalDetails'; import usePrevious from '@hooks/usePrevious'; -import useRelatedReportActionsErrorFields from '@hooks/useRelatedReportActionsErrorFields'; +import useRelatedReportActions from '@hooks/useRelatedReportActions'; import useReportIsArchived from '@hooks/useReportIsArchived'; import useReportsParentHierarchy from '@hooks/useReportsParentHierarchy'; import useReportTransactionsCollection from '@hooks/useReportTransactionsCollection'; @@ -175,7 +175,7 @@ function MoneyRequestReceiptView({ const originalReportID = useOriginalReportID(report?.reportID, parentReportAction); const reportsParentHierarchy = useReportsParentHierarchy(report?.reportID); - const relatedReportActions = useRelatedReportActionsErrorFields(reportsParentHierarchy, originalReportID, parentReportAction?.childReportID); + const relatedReportActions = useRelatedReportActions(reportsParentHierarchy, originalReportID, parentReportAction?.childReportID); const {iouReport, chatReport: chatIOUReport, isChatIOUReportArchived} = useGetIOUReportFromReportAction(parentReportAction); const iouReportTransactionsCollection = useReportTransactionsCollection(iouReport?.reportID); const iouReportTransactions = Object.values(iouReportTransactionsCollection); diff --git a/src/hooks/useRelatedReportActions.ts b/src/hooks/useRelatedReportActions.ts new file mode 100644 index 000000000000..43bdf90bda97 --- /dev/null +++ b/src/hooks/useRelatedReportActions.ts @@ -0,0 +1,30 @@ +import type {ReportHierarchyInfo} from '@userActions/ClearReportActionErrors'; + +import ONYXKEYS from '@src/ONYXKEYS'; +import {relatedReportActionsSelector} from '@src/selectors/ReportAction'; +import type {ReportActions} from '@src/types/onyx'; + +import type {OnyxCollection} from 'react-native-onyx'; + +import useOnyx from './useOnyx'; + +/** + * Subscribes to the report actions `clearAllRelatedReportActionErrors` walks when an error is dismissed: the actions + * of every report in `reportsParentHierarchy` (see `useReportsParentHierarchy`), of the original report holding the + * dismissed action, and of the threads below `childRootReportID` that hang off errored actions. The selector only + * looks up those keys and returns each report's actions by reference, so a write to an unrelated report action costs + * a few lookups rather than a deep comparison over every action in the account. + */ +function useRelatedReportActions( + reportsParentHierarchy: OnyxCollection, + originalReportID: string | undefined, + childRootReportID: string | undefined, +): OnyxCollection { + const reportIDs = Object.keys(reportsParentHierarchy ?? {}).map((key) => key.slice(ONYXKEYS.COLLECTION.REPORT.length)); + const [relatedReportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS, { + selector: relatedReportActionsSelector([...reportIDs, originalReportID], childRootReportID), + }); + return relatedReportActions; +} + +export default useRelatedReportActions; diff --git a/src/hooks/useRelatedReportActionsErrorFields.ts b/src/hooks/useRelatedReportActionsErrorFields.ts deleted file mode 100644 index 6e3a5cbbf20c..000000000000 --- a/src/hooks/useRelatedReportActionsErrorFields.ts +++ /dev/null @@ -1,30 +0,0 @@ -import type {ReportHierarchyInfo} from '@userActions/ClearReportActionErrors'; - -import ONYXKEYS from '@src/ONYXKEYS'; -import {relatedReportActionsErrorFieldsSelector} from '@src/selectors/ReportAction'; -import type {ReportActions} from '@src/types/onyx'; - -import type {OnyxCollection} from 'react-native-onyx'; - -import useOnyx from './useOnyx'; - -/** - * Subscribes to the report actions `clearAllRelatedReportActionErrors` walks when an error is dismissed, narrowed to - * the fields it reads: the actions of every report in `reportsParentHierarchy` (see `useReportsParentHierarchy`), of - * the original report holding the dismissed action, and of the threads below `childRootReportID` that hang off - * errored actions. The selector only looks up those keys instead of mapping the whole collection, so a write to an - * unrelated report action costs a few lookups rather than a deep comparison over every action in the account. - */ -function useRelatedReportActionsErrorFields( - reportsParentHierarchy: OnyxCollection, - originalReportID: string | undefined, - childRootReportID: string | undefined, -): OnyxCollection { - const reportIDs = Object.keys(reportsParentHierarchy ?? {}).map((key) => key.slice(ONYXKEYS.COLLECTION.REPORT.length)); - const [relatedReportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS, { - selector: relatedReportActionsErrorFieldsSelector([...reportIDs, originalReportID], childRootReportID), - }); - return relatedReportActions; -} - -export default useRelatedReportActionsErrorFields; diff --git a/src/selectors/ReportAction.ts b/src/selectors/ReportAction.ts index be202b00c3e9..bb313beb297f 100644 --- a/src/selectors/ReportAction.ts +++ b/src/selectors/ReportAction.ts @@ -153,51 +153,15 @@ const transactionThreadReportIDSelector = (transactionID: string | undefined) => transactionID ? getIOUActionForTransactionID(Object.values(reportActions ?? {}), transactionID)?.childReportID : undefined; /** - * Keeps only the fields `clearAllRelatedReportActionErrors` reads when walking related report actions. - * Nested fields (`errors`, `message`, `originalMessage`) are copied by reference so equality checks on the - * projected result short-circuit and unrelated action updates (reactions, read receipts, person data, ...) - * neither re-render the subscriber nor pay a deep comparison. - */ -function reportActionErrorFieldsSelector(reportAction: OnyxEntry): OnyxEntry { - return ( - reportAction && { - reportActionID: reportAction.reportActionID, - actionName: reportAction.actionName, - created: reportAction.created, - pendingAction: reportAction.pendingAction, - isOptimisticAction: reportAction.isOptimisticAction, - childReportID: reportAction.childReportID, - errors: reportAction.errors, - message: reportAction.message, - // Copying the deprecated originalMessage field is intentional. The projection must preserve the raw - // data so downstream helpers can resolve it through getOriginalMessage. - // eslint-disable-next-line @typescript-eslint/no-deprecated - originalMessage: reportAction.originalMessage, - } - ); -} - -function projectReportActionsErrorFields(actions: ReportActions): ReportActions { - const projectedActions: ReportActions = {}; - for (const [reportActionID, reportAction] of Object.entries(actions)) { - const projectedAction = reportActionErrorFieldsSelector(reportAction); - if (projectedAction) { - projectedActions[reportActionID] = projectedAction; - } - } - return projectedActions; -} - -/** - * Creates a selector returning the report actions `clearAllRelatedReportActionErrors` walks, narrowed to the fields it - * reads: the actions of every report in `reportIDs` (the report whose error is dismissed, its ancestors and the original - * report holding the dismissed action), plus the threads below `childRootReportID` that hang off actions with errors. + * Creates a selector returning the report actions `clearAllRelatedReportActionErrors` walks: the actions of every + * report in `reportIDs` (the report whose error is dismissed, its ancestors and the original report holding the + * dismissed action), plus the threads below `childRootReportID` that hang off actions with errors. * The walk returns early from an action without errors, so following only errored actions downward is exact. - * Only those keys are looked up, so a write to an unrelated report action neither maps the whole collection nor pays - * a deep comparison over it. + * Only those keys are looked up and each report's actions are returned by reference, so a write to an unrelated + * report action costs a few lookups, and a report whose actions are unchanged compares by reference. */ -function relatedReportActionsErrorFieldsSelector(reportIDs: Array, childRootReportID: string | undefined) { - return function selectRelatedReportActionsErrorFields(reportActions: OnyxCollection): OnyxCollection { +function relatedReportActionsSelector(reportIDs: Array, childRootReportID: string | undefined) { + return function selectRelatedReportActions(reportActions: OnyxCollection): OnyxCollection { const result: OnyxCollection = {}; const visitedReportIDs = new Set(); const collect = (reportID: string | undefined, shouldFollowErroredThreads: boolean) => { @@ -210,7 +174,7 @@ function relatedReportActionsErrorFieldsSelector(reportIDs: Array { expect(parentReportActions?.[SIBLING_REPORT_ACTION_ID]).toBeUndefined(); }); - it('should clear errors when the reportActions data is narrowed by relatedReportActionsErrorFieldsSelector', async () => { + it('should clear errors when the reportActions data comes from relatedReportActionsSelector', async () => { // Given the same hierarchy as the recursion test, but with the reportActions parameter passed - // through the selector components use to scope the data to the hierarchy and narrow each action to - // the fields the error clearing reads. This fails if the selector ever drops a report the walk looks - // up or a field the walk or its helpers start consuming. + // through the selector components use to scope the data to the dismissal hierarchy. This fails if + // the selector ever drops a report the walk looks up. const reportAction = getFakeReportAction(Number(REPORT_ACTION_ID), { errors: {sharedError: 'Error message'}, }); @@ -709,7 +708,7 @@ describe('ClearReportActionErrors', () => { }); await waitForBatchedUpdates(); - // When clearAllRelatedReportActionErrors is called with selector-narrowed reportActions data + // When clearAllRelatedReportActionErrors is called with selector-scoped reportActions data clearAllRelatedReportActionErrors({ reportID: REPORT_ID, reportAction, @@ -718,7 +717,7 @@ describe('ClearReportActionErrors', () => { reports: { [`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`]: {parentReportID: PARENT_REPORT_ID, parentReportActionID: PARENT_REPORT_ACTION_ID}, }, - reportActions: relatedReportActionsErrorFieldsSelector( + reportActions: relatedReportActionsSelector( [REPORT_ID, PARENT_REPORT_ID], reportAction.childReportID, )({ @@ -733,7 +732,7 @@ describe('ClearReportActionErrors', () => { }); await waitForBatchedUpdates(); - // Then the narrowed data should still drive the full walk and delete the reject sibling + // Then the scoped data should still drive the full walk and delete the reject sibling const parentReportActions = await getReportActionsFromOnyx(PARENT_REPORT_ID); expect(parentReportActions?.[SIBLING_REPORT_ACTION_ID]).toBeUndefined(); }); diff --git a/tests/unit/selectors/ReportActionTest.ts b/tests/unit/selectors/ReportActionTest.ts index c9db75a1d319..5a4943ada055 100644 --- a/tests/unit/selectors/ReportActionTest.ts +++ b/tests/unit/selectors/ReportActionTest.ts @@ -4,7 +4,7 @@ import type {ReportAction, ReportActions} from '@src/types/onyx'; import type {OnyxCollection} from 'react-native-onyx'; -import {getLatestFeedbackActionIDByAuthorSelector, getReceiptScanFailedIOUActionDataSelector, relatedReportActionsErrorFieldsSelector} from '@selectors/ReportAction'; +import {getLatestFeedbackActionIDByAuthorSelector, getReceiptScanFailedIOUActionDataSelector, relatedReportActionsSelector} from '@selectors/ReportAction'; const CURRENT_USER_ACCOUNT_ID = 123456789; const OTHER_USER_ACCOUNT_ID = 987654321; @@ -183,7 +183,7 @@ describe('getLatestFeedbackActionIDByAuthorSelector', () => { }); }); -describe('relatedReportActionsErrorFieldsSelector', () => { +describe('relatedReportActionsSelector', () => { const THREAD_REPORT_ID = 'thread1'; const PARENT_REPORT_ID = 'parent1'; const CHAT_REPORT_ID = 'chat1'; @@ -193,9 +193,9 @@ describe('relatedReportActionsErrorFieldsSelector', () => { const reportActionsKey = (reportID: string) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}` as const; - it('should return the actions of the listed reports projected to the error fields, and nothing else', () => { - // Given actions for a thread, its parent and an unrelated report, where the parent action carries fields the error clearing never reads - const parentAction = createIOUAction('iou1', {childReportID: THREAD_REPORT_ID, errors: {error1: 'Error message'}, person: [{type: 'TEXT', text: 'Jane'}]}); + it('should return the actions of the listed reports by reference, and nothing else', () => { + // Given actions for a thread, its parent and an unrelated report + const parentAction = createIOUAction('iou1', {childReportID: THREAD_REPORT_ID, errors: {error1: 'Error message'}}); const reportActions: OnyxCollection = { [reportActionsKey(THREAD_REPORT_ID)]: {comment1: createIOUAction('comment1')}, [reportActionsKey(PARENT_REPORT_ID)]: {iou1: parentAction}, @@ -203,28 +203,15 @@ describe('relatedReportActionsErrorFieldsSelector', () => { }; // When the selector is applied for the thread and its parent without a child root - const result = relatedReportActionsErrorFieldsSelector([THREAD_REPORT_ID, PARENT_REPORT_ID], undefined)(reportActions); + const result = relatedReportActionsSelector([THREAD_REPORT_ID, PARENT_REPORT_ID], undefined)(reportActions); // Then only the listed reports are returned, so unrelated report action writes cannot change the result expect(Object.keys(result ?? {})).toEqual([reportActionsKey(THREAD_REPORT_ID), reportActionsKey(PARENT_REPORT_ID)]); - // Then each action keeps the fields the walk and its helpers read, and drops the rest so unrelated action updates compare equal - const projectedParentAction = result?.[reportActionsKey(PARENT_REPORT_ID)]?.iou1; - expect(projectedParentAction).toEqual({ - reportActionID: 'iou1', - actionName: CONST.REPORT.ACTIONS.TYPE.IOU, - created: parentAction.created, - pendingAction: undefined, - isOptimisticAction: undefined, - childReportID: THREAD_REPORT_ID, - errors: parentAction.errors, - message: parentAction.message, - // The projection intentionally preserves the deprecated raw field so getOriginalMessage can resolve it downstream - // eslint-disable-next-line @typescript-eslint/no-deprecated - originalMessage: parentAction.originalMessage, - }); - expect(projectedParentAction).not.toHaveProperty('person'); - expect(projectedParentAction).not.toHaveProperty('actorAccountID'); + // Then each report's actions are the input objects by reference, so a report whose actions are unchanged compares cheaply + expect(result?.[reportActionsKey(THREAD_REPORT_ID)]).toBe(reportActions[reportActionsKey(THREAD_REPORT_ID)]); + expect(result?.[reportActionsKey(PARENT_REPORT_ID)]).toBe(reportActions[reportActionsKey(PARENT_REPORT_ID)]); + expect(result?.[reportActionsKey(PARENT_REPORT_ID)]?.iou1).toBe(parentAction); }); it('should follow threads below the child root only through actions that have errors', () => { @@ -239,7 +226,7 @@ describe('relatedReportActionsErrorFieldsSelector', () => { }; // When the selector is applied with the thread both listed and used as the child root - const result = relatedReportActionsErrorFieldsSelector([THREAD_REPORT_ID], THREAD_REPORT_ID)(reportActions); + const result = relatedReportActionsSelector([THREAD_REPORT_ID], THREAD_REPORT_ID)(reportActions); // Then the thread hanging off the errored action is included, since the walk recurses into it, while the clean action's thread is not expect(Object.keys(result ?? {}).sort()).toEqual([reportActionsKey(ERRORED_THREAD_REPORT_ID), reportActionsKey(THREAD_REPORT_ID)].sort()); @@ -253,7 +240,7 @@ describe('relatedReportActionsErrorFieldsSelector', () => { }; // When the selector is applied with the cycle reachable from the child root - const result = relatedReportActionsErrorFieldsSelector([THREAD_REPORT_ID, PARENT_REPORT_ID, undefined], THREAD_REPORT_ID)(reportActions); + const result = relatedReportActionsSelector([THREAD_REPORT_ID, PARENT_REPORT_ID, undefined], THREAD_REPORT_ID)(reportActions); // Then both reports in the cycle are returned once, the unloaded report is left out and the selector returns instead of hanging expect(Object.keys(result ?? {}).sort()).toEqual([reportActionsKey(CHAT_REPORT_ID), reportActionsKey(THREAD_REPORT_ID)].sort()); From ffd8f54de8754b751fee30436af5d4839d76df3a Mon Sep 17 00:00:00 2001 From: cretadn22 Date: Sat, 7 Nov 2026 18:54:21 +0700 Subject: [PATCH 8/9] Merge branch 'main' into 96139-remove-report-actions-onyx-connect --- .../isDeployChecklistLocked/index.js | 357 +++++++++++++----- .../javascript/proposalPoliceComment/index.js | 357 +++++++++++++----- 2 files changed, 514 insertions(+), 200 deletions(-) diff --git a/.github/actions/javascript/isDeployChecklistLocked/index.js b/.github/actions/javascript/isDeployChecklistLocked/index.js index 81a08e417d8a..9cac857a61a8 100644 --- a/.github/actions/javascript/isDeployChecklistLocked/index.js +++ b/.github/actions/javascript/isDeployChecklistLocked/index.js @@ -2016,32 +2016,6 @@ var require_API = __commonJS({ requireParameters(["email"], parameters, commandName); return performPOSTRequest(commandName, parameters); }, - /** - * Resets the password for an account - * @param {Object} parameters - * @param {String} parameters.email - * @returns {ExpensifyAPIDeferred} - */ - resetPassword(parameters) { - const commandName = "ResetPassword"; - requireParameters(["email"], parameters, commandName); - const newParameters = Object.assign(Object.assign({}, parameters), { api_setCookie: false }); - return performPOSTRequest(commandName, newParameters); - }, - /** - * Sets the password for an account - * - * @param {Object} parameters - * @param {String} parameters.email - * @param {String} parameters.password - * @param {String} parameters.validateCode - * @returns {ExpensifyAPIDeferred} - */ - setPassword(parameters) { - const commandName = "SetPassword"; - requireParameters(["email", "password", "validateCode"], parameters, commandName); - return performPOSTRequest(commandName, parameters); - }, /** * Validate a user * @@ -2591,8 +2565,12 @@ var require_CONST = __commonJS({ "node_modules/expensify-common/dist/CONST.js"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); - exports.PUBLIC_DOMAINS_SET = exports.UI = exports.CONST = exports.g_cloudFrontImg = exports.g_cloudFront = void 0; + exports.MAX_URL_HOSTNAME_LENGTH = exports.MAX_URL_HOSTNAME_LABEL_LENGTH = exports.PUBLIC_DOMAINS_SET = exports.UI = exports.CONST = exports.g_cloudFrontImg = exports.g_cloudFront = void 0; var EMAIL_BASE_REGEX = "(?=((?=[\\w'#%+-]+(?:\\.[\\w'#%+-]+)*@)[\\w\\.'#%+-]{1,64}@(?:(?=[a-z\\d]+(?:-+[a-z\\d]+)*\\.)(?:[a-z\\d-]{1,63}\\.)+[a-z]{2,63})(?= |_|\\b))(?.*))\\S{3,254}(?=\\k$)"; + var MAX_URL_HOSTNAME_LABEL_LENGTH = 63; + exports.MAX_URL_HOSTNAME_LABEL_LENGTH = MAX_URL_HOSTNAME_LABEL_LENGTH; + var MAX_URL_HOSTNAME_LENGTH = 253; + exports.MAX_URL_HOSTNAME_LENGTH = MAX_URL_HOSTNAME_LENGTH; var MOMENT_FORMAT_STRING = "YYYY-MM-DD"; var g_cloudFront = "https://d2k5nsl2zxldvw.cloudfront.net"; exports.g_cloudFront = g_cloudFront; @@ -21596,12 +21574,22 @@ var require_Url = __commonJS({ return mod && mod.__esModule ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); - exports.MARKDOWN_URL_REGEX = exports.LOOSE_URL_WEBSITE_REGEX = exports.LOOSE_URL_REGEX = exports.URL_PROTOCOL_REGEX = exports.URL_REGEX_WITH_REQUIRED_PROTOCOL = exports.URL_REGEX = exports.URL_FRAGMENT_REGEX = exports.URL_PARAM_REGEX = exports.URL_PATH_REGEX = exports.URL_WEBSITE_REGEX = void 0; + exports.MARKDOWN_URL_REGEX = exports.LOOSE_URL_WEBSITE_REGEX = exports.LOOSE_URL_REGEX = exports.URL_PORT_REGEX = exports.URL_PROTOCOL_REGEX = exports.URL_REGEX_WITH_REQUIRED_PROTOCOL = exports.URL_REGEX = exports.URL_FRAGMENT_REGEX = exports.URL_PARAM_REGEX = exports.URL_PATH_REGEX = exports.URL_WEBSITE_REGEX = exports.URL_HOSTNAME_LABEL_REGEX = exports.URL_HOSTNAME_BOUNDARY_REGEX = void 0; var tlds_1 = __importDefault(require_tlds()); - var ALLOWED_PORTS = "([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])"; + var CONST_1 = require_CONST(); + var URL_PORT_REGEX = "([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])"; + exports.URL_PORT_REGEX = URL_PORT_REGEX; var URL_PROTOCOL_REGEX = "((ht|f)tps?:\\/\\/)"; exports.URL_PROTOCOL_REGEX = URL_PROTOCOL_REGEX; - var URL_WEBSITE_REGEX = `${URL_PROTOCOL_REGEX}?((?:www\\.)?[a-z0-9](?=(?