Skip to content

Commit aac8f0e

Browse files
committed
fix: merge fetched chunks
1 parent 2b45f1c commit aac8f0e

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

src/components/PaginatedTable/PaginatedTable.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export interface PaginatedTableProps<T, F> {
3737
keepCache?: boolean;
3838
}
3939

40-
const DEFAULT_PAGINATION_LIMIT = 20;
40+
const DEFAULT_PAGINATION_LIMIT = 10;
4141

4242
export const PaginatedTable = <T, F>({
4343
limit: chunkSize = DEFAULT_PAGINATION_LIMIT,
@@ -142,7 +142,6 @@ export const PaginatedTable = <T, F>({
142142
const isActive = shouldRender || shouldFetch;
143143

144144
if (isActive) {
145-
// Render active chunk normally
146145
chunks.push(
147146
<TableChunk<T, F>
148147
key={i}
@@ -164,26 +163,28 @@ export const PaginatedTable = <T, F>({
164163
keepCache={keepCache}
165164
/>,
166165
);
166+
}
167+
168+
if (shouldRender) {
167169
i++;
168170
} else {
169171
// Find consecutive inactive chunks and merge them
170172
const startIndex = i;
171173
let totalHeight = 0;
172174

173-
while (
174-
i < chunkStates.length &&
175-
!chunkStates[i].shouldRender &&
176-
!chunkStates[i].shouldFetch
177-
) {
175+
while (i < chunkStates.length && !chunkStates[i].shouldRender) {
178176
const currentChunkSize =
179177
i === chunkStates.length - 1 ? lastChunkSize : chunkSize;
180178
totalHeight += currentChunkSize * rowHeight;
181179
i++;
182180
}
183181

184-
// Render merged empty tbody for consecutive inactive chunks
182+
// Render merged separator for consecutive inactive chunks
185183
chunks.push(
186-
<tr style={{height: `${totalHeight}px`}} key={`merged-${startIndex}-${i - 1}`}>
184+
<tr
185+
style={{height: `${totalHeight}px`}}
186+
key={`separator-${startIndex}-${i - 1}`}
187+
>
187188
<td colSpan={columns.length} style={{padding: 0, border: 'none'}} />
188189
</tr>,
189190
);

src/components/PaginatedTable/TableChunk.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,5 @@ export const TableChunk = typedMemo(function TableChunk<T, F>({
151151
));
152152
};
153153

154-
return shouldRender ? (
155-
renderContent()
156-
) : (
157-
<tr style={{height: `${dataLength * rowHeight}px`}}>
158-
<td colSpan={columns.length} style={{padding: 0, border: 'none'}} />
159-
</tr>
160-
);
154+
return shouldRender ? renderContent() : null;
161155
});

src/components/PaginatedTable/useScrollBasedChunks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ interface ChunkState {
2121
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
2222

2323
// Bad performance in Safari - reduce overscan counts
24-
const DEFAULT_RENDER_OVERSCAN = isSafari ? 1 : 2;
24+
const DEFAULT_RENDER_OVERSCAN = isSafari ? 0 : 0;
2525
const DEFAULT_FETCH_OVERSCAN = 4;
2626

2727
export const useScrollBasedChunks = ({

0 commit comments

Comments
 (0)