Skip to content

Commit 39e0f35

Browse files
committed
perf(virtual-list): improve height estimates with variant-specific calculations
- Replace generic 50px estimate with variant-specific heights - Add browser-tested calculations: Calendar(32px), Compact(68px), Subtask(48px), Kanban(110px), Default(120px) - Account for MaterialCard padding + content height + TaskItem mb-2 margin - Update test environment to use same variant-specific estimates - Maintain dynamic measureElement for fine-tuning Improves initial virtual list rendering accuracy and scroll performance.
1 parent 41b1f69 commit 39e0f35

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

apps/web/components/task/virtualized-task-list.tsx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,34 @@ export function VirtualizedTaskList({
8585
// Get tasks in sorted order for virtualization
8686
const sortedTasks = sortedTaskIds.map((id) => tasks.find((t) => t.id === id)).filter(Boolean)
8787

88+
// Variant-specific height estimates based on actual browser calculations
89+
// Formula: MaterialCard padding + content height + TaskItem mb-2 margin (8px)
90+
const getEstimateSize = useCallback(() => {
91+
switch (variant) {
92+
case "calendar":
93+
// p-1 (8px total) + minimal content (~16px) + mb-2 (8px) ≈ 32px
94+
return 32
95+
case "compact":
96+
// p-2.5 (20px total) + single row content (40px) + mb-2 (8px) = 68px
97+
return 68
98+
case "subtask":
99+
// p-2 (16px total) + subtask content (~24px) + mb-2 (8px) ≈ 48px
100+
return 48
101+
case "kanban":
102+
// Empirically tested: 110px works better
103+
return 110
104+
case "default":
105+
// p-4 (32px total) + full content (80px) + mb-2 (8px) = 120px
106+
return 120
107+
default:
108+
return 68 // Sensible fallback
109+
}
110+
}, [variant])
111+
88112
const virtualizer = useVirtualizer({
89113
count: sortedTasks.length,
90114
getScrollElement,
91-
estimateSize: () => 50,
115+
estimateSize: getEstimateSize,
92116
overscan: 5,
93117
})
94118

@@ -130,7 +154,7 @@ export function VirtualizedTaskList({
130154

131155
// In test environment, render all items to make them available for queries
132156
const itemsToRender = isTest
133-
? sortedTasks.map((task, index) => ({ task, index, start: index * 50 }))
157+
? sortedTasks.map((task, index) => ({ task, index, start: index * getEstimateSize() }))
134158
: virtualizer
135159
.getVirtualItems()
136160
.map((vi) => ({ task: sortedTasks[vi.index], index: vi.index, start: vi.start }))

0 commit comments

Comments
 (0)