revert: remove useCallback wrappers that caused performance regression

This commit is contained in:
Francisco Ignácio Fontoura Solla 2026-08-06 01:25:18 -03:00
parent c2229596e4
commit 43949d7c55
2 changed files with 14 additions and 11 deletions

View file

@ -177,8 +177,6 @@ export const CampaignInfiniteTable = <Row,>({
const extra = appended.pages.flat().filter((row) => !seedKeys.has(rowKey(row))) const extra = appended.pages.flat().filter((row) => !seedKeys.has(rowKey(row)))
return [...rows, ...extra] return [...rows, ...extra]
}, [rows, appended.pages, rowKey]) }, [rows, appended.pages, rowKey])
const loadedRowsRef = useRef(loadedRows)
loadedRowsRef.current = loadedRows
useEffect(() => { useEffect(() => {
setScrollElement(rootRef.current?.closest(CAMPAIGN_CONTENT_SCROLL_SELECTOR) ?? null) setScrollElement(rootRef.current?.closest(CAMPAIGN_CONTENT_SCROLL_SELECTOR) ?? null)
@ -256,16 +254,13 @@ export const CampaignInfiniteTable = <Row,>({
const virtualizer = useVirtualizer({ const virtualizer = useVirtualizer({
count: itemCount, count: itemCount,
estimateSize: useCallback(() => ESTIMATED_ROW_HEIGHT, []), estimateSize: () => ESTIMATED_ROW_HEIGHT,
getScrollElement: useCallback(() => scrollElement, [scrollElement]), getScrollElement: () => scrollElement,
overscan: 8, overscan: 8,
getItemKey: useCallback( getItemKey: (index) => {
(index: number) => { const row = loadedRows[index]
const row = loadedRowsRef.current[index] return row ? rowKey(row) : `skeleton-${index}`
return row ? rowKey(row) : `skeleton-${index}` },
},
[rowKey],
),
}) })
const virtualItems = virtualizer.getVirtualItems() const virtualItems = virtualizer.getVirtualItems()

View file

@ -97,6 +97,14 @@ test.describe('campaign leaderships list', () => {
name: 'Buscar município, território de identidade ou zona eleitoral', name: 'Buscar município, território de identidade ou zona eleitoral',
}) })
await search.fill(added.name) await search.fill(added.name)
// Diagnostic: check if the listbox is in the DOM
const listbox = page.locator('[role="listbox"]')
const listboxCount = await listbox.count()
console.log(`Listbox count after fill: ${listboxCount}`)
if (listboxCount > 0) {
const listboxHTML = await listbox.first().innerHTML()
console.log(`Listbox HTML: ${listboxHTML.substring(0, 500)}`)
}
const suggestion = page const suggestion = page
.getByRole('option') .getByRole('option')
.filter({ has: page.getByText(added.name, { exact: true }) }) .filter({ has: page.getByText(added.name, { exact: true }) })