88 */ 
99
1010import  *  as  React  from  'react' ; 
11- import  { useContext ,  useEffect ,   useRef }  from  'react' ; 
11+ import  { useContext ,  useEffect }  from  'react' ; 
1212import  { BridgeContext }  from  '../context' ; 
1313import  { TreeDispatcherContext }  from  '../Components/TreeContext' ; 
1414import  { useHighlightHostInstance ,  useScrollToHostInstance }  from  '../hooks' ; 
@@ -29,9 +29,8 @@ function SuspenseTimelineInput() {
2929    useHighlightHostInstance ( ) ; 
3030  const  scrollToHostInstance  =  useScrollToHostInstance ( ) ; 
3131
32-   const  { timeline,  timelineIndex,  hoveredTimelineIndex,  playing}  =  useContext ( 
33-     SuspenseTreeStateContext , 
34-   ) ; 
32+   const  { timeline,  timelineIndex,  hoveredTimelineIndex,  playing,  autoScroll}  = 
33+     useContext ( SuspenseTreeStateContext ) ; 
3534
3635  const  min  =  0 ; 
3736  const  max  =  timeline . length  >  0  ? timeline . length  -  1  : 0 ; 
@@ -102,7 +101,6 @@ function SuspenseTimelineInput() {
102101    } ) ; 
103102  } 
104103
105-   const  isInitialMount  =  useRef ( true ) ; 
106104  // TODO: useEffectEvent here once it's supported in all versions DevTools supports. 
107105  // For now we just exclude it from deps since we don't lint those anyway. 
108106  function  changeTimelineIndex ( newIndex : number )  { 
@@ -115,22 +113,21 @@ function SuspenseTimelineInput() {
115113    bridge . send ( 'overrideSuspenseMilestone' ,  { 
116114      suspendedSet, 
117115    } ) ; 
118-     if  ( isInitialMount . current )  { 
119-       // Skip scrolling on initial mount. Only when we're changing the timeline. 
120-       isInitialMount . current  =  false ; 
121-     }  else  { 
122-       // When we're scrubbing through the timeline, scroll the current boundary 
123-       // into view as it was just revealed. This is after we override the milestone 
124-       // to reveal it. 
125-       const  selectedSuspenseID  =  timeline [ timelineIndex ] ; 
126-       scrollToHostInstance ( selectedSuspenseID ) ; 
127-     } 
128116  } 
129117
130118  useEffect ( ( )  =>  { 
131119    changeTimelineIndex ( timelineIndex ) ; 
132120  } ,  [ timelineIndex ] ) ; 
133121
122+   useEffect ( ( )  =>  { 
123+     if  ( autoScroll . id  >  0 )  { 
124+       const  scrollToId  =  autoScroll . id ; 
125+       // Consume the scroll ref so that we only trigger this scroll once. 
126+       autoScroll . id  =  0 ; 
127+       scrollToHostInstance ( scrollToId ) ; 
128+     } 
129+   } ,  [ autoScroll ] ) ; 
130+ 
134131  useEffect ( ( )  =>  { 
135132    if  ( ! playing )  { 
136133      return  undefined ; 
0 commit comments