@@ -48,28 +48,12 @@ export const useVirtualizedTbodies = <T, F>({
4848 const endRow = visibleRowRange . end ;
4949
5050 const renderChunks = React . useCallback ( ( ) => {
51- const chunks : React . ReactElement [ ] = [ ] ;
52-
5351 // Calculate which chunks contain visible rows
5452 const totalChunks = Math . ceil ( totalItems / chunkSize ) ;
5553 const startChunk = Math . max ( 0 , Math . floor ( startRow / chunkSize ) ) ;
5654 const endChunk = Math . min ( totalChunks - 1 , Math . floor ( endRow / chunkSize ) ) ;
5755
58- // Push start spacer for rows before visible range
59- const startSpacerHeight = startRow * rowHeight ;
60- if ( startSpacerHeight > 0 ) {
61- chunks . push (
62- < tbody
63- key = "spacer-start"
64- style = { {
65- height : `${ startSpacerHeight } px` ,
66- display : 'block' ,
67- } }
68- /> ,
69- ) ;
70- }
71-
72- // Collect active chunks and calculate height for visible rows only
56+ // Collect active chunks
7357 const activeChunkElements : React . ReactElement [ ] = [ ] ;
7458
7559 for ( let i = startChunk ; i <= endChunk ; i ++ ) {
@@ -98,41 +82,19 @@ export const useVirtualizedTbodies = <T, F>({
9882 ) ;
9983 }
10084
101- // Wrap active chunks in a single tbody
102- if ( activeChunkElements . length > 0 ) {
103- // Calculate height based on visible rows only
104- const visibleRowCount = endRow - startRow + 1 ;
105- const totalActiveHeight = visibleRowCount * rowHeight ;
106-
107- chunks . push (
108- < tbody
109- key = "active-chunks"
110- style = { {
111- height : `${ totalActiveHeight } px` ,
112- display : 'table-row-group' ,
113- } }
114- >
115- { activeChunkElements }
116- </ tbody > ,
117- ) ;
118- }
119-
120- // Add end spacer for rows after visible range
121- const endSpacerHeight = Math . max ( 0 , ( totalItems - startRow - 1 ) * rowHeight ) ;
122-
123- if ( endSpacerHeight > 0 ) {
124- chunks . push (
125- < tbody
126- key = "spacer-end"
127- style = { {
128- height : `${ endSpacerHeight } px` ,
129- display : 'block' ,
130- } }
131- /> ,
132- ) ;
133- }
85+ const activeChunksTopOffset = startRow * rowHeight ;
13486
135- return chunks ;
87+ return (
88+ < tbody
89+ style = { {
90+ position : 'absolute' ,
91+ transform : `translateY(${ activeChunksTopOffset } px)` ,
92+ willChange : 'transform' ,
93+ } }
94+ >
95+ { activeChunkElements }
96+ </ tbody >
97+ ) ;
13698 } , [
13799 startRow ,
138100 endRow ,
0 commit comments