@@ -64,9 +64,6 @@ export function TopicData({scrollContainerRef, path, database, databaseFullPath}
6464 const [ truncated , setTruncated ] = React . useState ( false ) ;
6565 const [ baseEndOffset , setBaseEndOffset ] = React . useState < number > ( ) ;
6666
67- const startRef = React . useRef < number > ( ) ;
68- startRef . current = startOffset ;
69-
7067 const {
7168 selectedPartition,
7269 selectedOffset,
@@ -213,36 +210,39 @@ export function TopicData({scrollContainerRef, path, database, databaseFullPath}
213210 ( newOffset : number ) => {
214211 const scrollTop = ( newOffset - ( baseOffset ?? 0 ) ) * DEFAULT_TABLE_ROW_HEIGHT ;
215212 const normalizedScrollTop = Math . max ( 0 , scrollTop ) ;
216- scrollContainerRef . current ?. scrollTo ( {
217- top : normalizedScrollTop ,
218- behavior : 'instant' ,
213+ // this is needed to ensure happening after useTableScroll in useLayoutEffect
214+ requestAnimationFrame ( ( ) => {
215+ scrollContainerRef . current ?. scrollTo ( {
216+ top : normalizedScrollTop ,
217+ behavior : 'instant' ,
218+ } ) ;
219219 } ) ;
220220 } ,
221221 [ baseOffset , scrollContainerRef ] ,
222222 ) ;
223223
224224 //this variable is used to scroll to active offset the very first time on open page
225- const initialActiveOffset = React . useRef ( activeOffset ) ;
225+ const initialScrollToOffset = React . useRef ( selectedOffset ?? activeOffset ) ;
226226
227227 React . useEffect ( ( ) => {
228- if ( isFetching ) {
228+ if ( isFetching || isNil ( baseOffset ) ) {
229229 return ;
230230 }
231231
232232 let currentOffset : number | undefined ;
233- if ( isNil ( initialActiveOffset . current ) ) {
233+ if ( isNil ( initialScrollToOffset . current ) ) {
234234 const messages = currentData ?. Messages ;
235235 if ( messages ?. length ) {
236236 currentOffset = safeParseNumber ( messages [ 0 ] . Offset ) ;
237237 }
238238 } else {
239- currentOffset = safeParseNumber ( initialActiveOffset . current ) ;
240- initialActiveOffset . current = undefined ;
239+ currentOffset = safeParseNumber ( initialScrollToOffset . current ) ;
240+ initialScrollToOffset . current = undefined ;
241241 }
242242 if ( ! isNil ( currentOffset ) ) {
243243 scrollToOffset ( currentOffset ) ;
244244 }
245- } , [ currentData , isFetching , scrollToOffset ] ) ;
245+ } , [ currentData , isFetching , scrollToOffset , baseOffset ] ) ;
246246
247247 const renderControls = React . useCallback ( ( ) => {
248248 return (
0 commit comments