@@ -2162,27 +2162,30 @@ function navigateToAndOpenReport(
21622162 }
21632163
21642164 let hasAttemptedFallback = false ;
2165- const reportConnection = Onyx . connectWithoutView ( {
2166- key : `${ ONYXKEYS . COLLECTION . REPORT } ${ chat . reportID } ` ,
2167- callback : ( updatedReport ) => {
2168- // If OpenReport confirms access, stop listening.
2169- if ( ! updatedReport ?. errorFields ?. notFound ) {
2165+ let hasSeenLoadingStart = false ;
2166+ const loadingStateConnection = Onyx . connectWithoutView ( {
2167+ key : `${ ONYXKEYS . COLLECTION . RAM_ONLY_REPORT_LOADING_STATE } ${ chat . reportID } ` ,
2168+ callback : ( loadingState ) => {
2169+ if ( loadingState ?. isLoadingInitialReportActions ) {
2170+ hasSeenLoadingStart = true ;
21702171 return ;
21712172 }
21722173
2173- if ( hasAttemptedFallback ) {
2174+ if ( ! hasSeenLoadingStart ) {
21742175 return ;
21752176 }
2177+
2178+ Onyx . disconnect ( loadingStateConnection ) ;
2179+ const latestReport = allReports ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ chat . reportID } ` ] ;
2180+ if ( ! latestReport ?. errorFields ?. notFound || hasAttemptedFallback ) {
2181+ return ;
2182+ }
2183+
21762184 hasAttemptedFallback = true ;
2177- Onyx . disconnect ( reportConnection ) ;
21782185 createAndOpenNewOptimisticChat ( chat . reportID ) ;
21792186 } ,
21802187 } ) ;
21812188
2182- setTimeout ( ( ) => {
2183- Onyx . disconnect ( reportConnection ) ;
2184- } , 10000 ) ;
2185-
21862189 // Re-open existing chats to re-validate server-side access and refresh stale local state.
21872190 openReport ( { reportID : chat . reportID , introSelected, isSelfTourViewed, betas} ) ;
21882191 navigateToReport ( chat . reportID , shouldDismissModal ) ;
@@ -2267,27 +2270,30 @@ function navigateToAndOpenReportWithAccountIDs(
22672270 }
22682271
22692272 let hasAttemptedFallback = false ;
2270- const reportConnection = Onyx . connectWithoutView ( {
2271- key : `${ ONYXKEYS . COLLECTION . REPORT } ${ chat . reportID } ` ,
2272- callback : ( updatedReport ) => {
2273- // If OpenReport confirms access, stop listening.
2274- if ( ! updatedReport ?. errorFields ?. notFound ) {
2273+ let hasSeenLoadingStart = false ;
2274+ const loadingStateConnection = Onyx . connectWithoutView ( {
2275+ key : `${ ONYXKEYS . COLLECTION . RAM_ONLY_REPORT_LOADING_STATE } ${ chat . reportID } ` ,
2276+ callback : ( loadingState ) => {
2277+ if ( loadingState ?. isLoadingInitialReportActions ) {
2278+ hasSeenLoadingStart = true ;
22752279 return ;
22762280 }
22772281
2278- if ( hasAttemptedFallback ) {
2282+ if ( ! hasSeenLoadingStart ) {
22792283 return ;
22802284 }
2285+
2286+ Onyx . disconnect ( loadingStateConnection ) ;
2287+ const latestReport = allReports ?. [ `${ ONYXKEYS . COLLECTION . REPORT } ${ chat . reportID } ` ] ;
2288+ if ( ! latestReport ?. errorFields ?. notFound || hasAttemptedFallback ) {
2289+ return ;
2290+ }
2291+
22812292 hasAttemptedFallback = true ;
2282- Onyx . disconnect ( reportConnection ) ;
22832293 createAndOpenNewOptimisticChat ( chat . reportID ) ;
22842294 } ,
22852295 } ) ;
22862296
2287- setTimeout ( ( ) => {
2288- Onyx . disconnect ( reportConnection ) ;
2289- } , 10000 ) ;
2290-
22912297 // Re-open existing chats to re-validate server-side access and refresh stale local state.
22922298 openReport ( { reportID : chat . reportID , introSelected, isSelfTourViewed, betas} ) ;
22932299 navigateToReport ( chat . reportID , false ) ;
0 commit comments