diff --git a/src/components/OptionListContextProvider.tsx b/src/components/OptionListContextProvider.tsx index fe7942f30024..21f8bb3de097 100644 --- a/src/components/OptionListContextProvider.tsx +++ b/src/components/OptionListContextProvider.tsx @@ -53,49 +53,24 @@ function OptionsListContextProvider({reports, children}: OptionsListProviderProp const personalDetails = usePersonalDetails() || CONST.EMPTY_OBJECT; const prevPersonalDetails = usePrevious(personalDetails); - const prevReports = usePrevious(reports); /** - * This effect is used to update the options list when a report is updated. + * This effect is used to update the options list when reports change. */ useEffect(() => { // there is no need to update the options if the options are not initialized - if (!areOptionsInitialized.current) { - return; - } - - const newReports = OptionsListUtils.createOptionList(personalDetails, reports).reports; - - setOptions((prevOptions) => { - const newOptions = {...prevOptions}; - newOptions.reports = newReports; - return newOptions; - }); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [reports]); - - /** - * This effect is used to add a new report option or remove a report option from the list of options when a new report is added to/removed from the collection. - */ - useEffect(() => { if (!areOptionsInitialized.current || !reports) { return; } - const missingReportIds = Object.keys(reports).filter((key) => prevReports && !(key in prevReports)); + // Since reports updates can happen in bulk, and some reports depend on other reports, we need to recreate the whole list from scratch. + const newReports = OptionsListUtils.createOptionList(personalDetails, reports).reports; setOptions((prevOptions) => { const newOptions = { ...prevOptions, - reports: prevOptions.reports.filter((report) => reports[`${ONYXKEYS.COLLECTION.REPORT}${report.reportID}`] !== null), + reports: newReports, }; - missingReportIds.forEach((missingReportId) => { - const report = missingReportId ? reports[missingReportId] : null; - if (!missingReportId || !report) { - return; - } - const reportOption = OptionsListUtils.createOptionFromReport(report, personalDetails); - newOptions.reports.push(reportOption); - }); + return newOptions; }); // eslint-disable-next-line react-hooks/exhaustive-deps diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index d11e8a612bc1..192c6f720b5f 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -780,9 +780,7 @@ function openReport( onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, value: { - errorFields: { - notFound: null, - }, + errorFields: null, }, }, {