@@ -186,7 +186,7 @@ function ReportActionsView({reportActions: allReportActions, ...props}) {
186
186
const mostRecentIOUReportActionID = useMemo ( ( ) => ReportActionsUtils . getMostRecentIOURequestActionID ( props . reportActions ) , [ props . reportActions ] ) ;
187
187
const prevNetworkRef = useRef ( props . network ) ;
188
188
const prevAuthTokenType = usePrevious ( props . session . authTokenType ) ;
189
- const [ isInitialLinkedView , setIsInitialLinkedView ] = useState ( false ) ;
189
+ const [ isInitialLinkedView , setIsInitialLinkedView ] = useState ( ! ! reportActionID ) ;
190
190
const prevIsSmallScreenWidthRef = useRef ( props . isSmallScreenWidth ) ;
191
191
const reportID = props . report . reportID ;
192
192
const isLoading = ( ! ! reportActionID && props . isLoadingInitialReportActions ) || ! props . isReadyForCommentLinking ;
@@ -430,14 +430,25 @@ function ReportActionsView({reportActions: allReportActions, ...props}) {
430
430
const isTheFirstReportActionIsLinked = firstReportActionID === reportActionID ;
431
431
432
432
useEffect ( ( ) => {
433
+ let timerId ;
434
+
433
435
if ( isTheFirstReportActionIsLinked ) {
434
- // this should be applied after we navigated to linked reportAction
436
+ setIsInitialLinkedView ( true ) ;
437
+ } else {
438
+ // After navigating to the linked reportAction, apply this to correctly set
439
+ // `autoscrollToTopThreshold` prop when linking to a specific reportAction.
435
440
InteractionManager . runAfterInteractions ( ( ) => {
436
- setIsInitialLinkedView ( true ) ;
441
+ // Using a short delay to ensure the view is updated after interactions
442
+ timerId = setTimeout ( ( ) => setIsInitialLinkedView ( false ) , 10 ) ;
437
443
} ) ;
438
- } else {
439
- setIsInitialLinkedView ( false ) ;
440
444
}
445
+
446
+ return ( ) => {
447
+ if ( ! timerId ) {
448
+ return ;
449
+ }
450
+ clearTimeout ( timerId ) ;
451
+ } ;
441
452
} , [ isTheFirstReportActionIsLinked ] ) ;
442
453
443
454
// Comments have not loaded at all yet do nothing
0 commit comments