rusackas commented on PR #34562:
URL: https://github.com/apache/superset/pull/34562#issuecomment-3857801218

   ## Addressed CodeAnt AI Performance Feedback
   
   Good catch on the performance issue! I've updated the implementation.
   
   ### The Problem
   Using `key={filterText}` caused the table to remount on **every keystroke** 
while typing in the filter, which:
   - Repeatedly resets pagination and sorting state
   - Causes visible UI jank for large datasets
   - Creates unnecessary work for React reconciliation
   
   ### The Solution
   Changed from `key={filterText}` to `key={pageCount}`:
   ```tsx
   key={Math.ceil(filteredData.length / dataSize) || 1}
   ```
   
   This means the table only remounts when the **number of pages actually 
changes**, not on every keystroke. This:
   - ✅ Still fixes the "currentPage > totalPages" error (the original bug)
   - ✅ Avoids unnecessary remounts while typing
   - ✅ Better performance for large tables
   
   ### Why Not `key={filterText ? 'filtered' : 'unfiltered'}`?
   The CodeAnt suggestion of `'filtered' : 'unfiltered'` wouldn't fully fix the 
bug because:
   1. User is on page 3, types "A" → remounts (filtered), goes to page 1 ✓
   2. User types "B" (now "AB") → **no remount** because still filtered
   3. If "AB" matches fewer items than "A", pagination could still be invalid ✗
   
   Using the page count as the key ensures we remount exactly when needed - 
when the pagination would become invalid.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to