bito-code-review[bot] commented on code in PR #39661:
URL: https://github.com/apache/superset/pull/39661#discussion_r3881410492


##########
superset-frontend/plugins/plugin-chart-table/src/DataTable/DataTable.tsx:
##########
@@ -244,6 +244,15 @@ export default typedMemo(function DataTable<D extends 
object>({
     ...tableHooks,
   );
 
+  // Clamp pageIndex when filtered data shrinks below current view (#31403).
+  // pageCount is derived from the filtered rows, so zero rows always means
+  // pageCount === 0 and is handled by the second branch.
+  if (pageCount > 0 && pageIndex >= pageCount) {
+    gotoPage(pageCount - 1);
+  } else if (pageCount === 0 && pageIndex !== 0) {
+    gotoPage(0);
+  }

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>State update during render</b></div>
   <div id="fix">
   
   `gotoPage()` dispatches a state update to the `useTable` reducer. Calling it 
directly in the render body (lines 250-254) is a React side-effect 
anti-pattern: it can trigger "Cannot update a component while rendering" 
warnings and, in edge cases, re-render loops. Move the clamp into a `useEffect` 
keyed on `[pageCount, pageIndex, gotoPage]` so the navigation happens after 
commit. `useEffect` is already imported in this file.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #365fe6</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



-- 
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