@@ -54,3 +54,46 @@ it("leaves the viewport still when a live preview lane is removed before the com
5454 expect ( scroll . scrollTop ) . toBe ( 160 ) ;
5555 act ( ( ) => root . unmount ( ) ) ;
5656} ) ;
57+
58+ // A long project settling hands the rows a new geometry with the same rows on many commits; each scrollTop read
59+ // forced a layout of every clip.
60+ it ( "reads no scroll position for a new geometry that places every row where it was" , ( ) => {
61+ const scroll = document . createElement ( "div" ) ;
62+ let reads = 0 ;
63+ let top = 160 ;
64+ Object . defineProperty ( scroll , "scrollTop" , {
65+ get : ( ) => ( reads ++ , top ) ,
66+ set : ( value : number ) => void ( top = value ) ,
67+ } ) ;
68+ const scrollRef = { current : scroll } ;
69+ const root = createRoot ( document . createElement ( "div" ) ) ;
70+ function Probe ( { geometry } : { geometry : TimelineRowGeometry } ) {
71+ useTimelineRowVirtualization ( {
72+ scrollRef,
73+ rowGeometry : geometry ,
74+ sessionEpoch : 0 ,
75+ viewport : {
76+ scrollTop : 160 ,
77+ scrollLeft : 0 ,
78+ clientWidth : 800 ,
79+ clientHeight : 200 ,
80+ scrollWidth : 800 ,
81+ scrollHeight : 600 ,
82+ isScrolling : false ,
83+ } ,
84+ elements : [ ] ,
85+ selectedElementId : null ,
86+ lastScrollLeftRef : { current : 0 } ,
87+ syncScrollViewport : ( ) => { } ,
88+ } ) ;
89+ return null ;
90+ }
91+ const rows = ( ) => createTimelineRowGeometry ( [ 0 , 1 , 2 ] , [ 48 , 48 , 48 ] ) ;
92+ act ( ( ) => root . render ( < Probe geometry = { rows ( ) } /> ) ) ;
93+ reads = 0 ;
94+ for ( let i = 0 ; i < 3 ; i += 1 ) act ( ( ) => root . render ( < Probe geometry = { rows ( ) } /> ) ) ;
95+ expect ( reads , "no layout read for the same rows" ) . toBe ( 0 ) ;
96+ act ( ( ) => root . render ( < Probe geometry = { createTimelineRowGeometry ( [ 0 , 9 , 1 , 2 ] , [ 48 , 48 , 48 , 48 ] ) } /> ) ) ;
97+ expect ( reads , "a row added still keeps the view anchored" ) . toBeGreaterThan ( 0 ) ;
98+ act ( ( ) => root . unmount ( ) ) ;
99+ } ) ;
0 commit comments