bito-code-review[bot] commented on code in PR #43184:
URL: https://github.com/apache/superset/pull/43184#discussion_r3786863941
##########
superset-frontend/plugins/plugin-chart-table/src/DataTable/DataTable.tsx:
##########
@@ -289,6 +324,48 @@ export default typedMemo(function DataTable<D extends
object>({
onFilteredDataChange(rowsRef.current, searchText);
}, [filterValue, onFilteredDataChange, rowSignature]);
+ // Emit filtered rows to parent in client-side mode (debounced via RAF).
+ // These hooks must stay above the "no columns" early return below, otherwise
+ // the hook count changes when the column count crosses zero (see #42978).
+ const isMountedRef = useRef(true);
+ useEffect(() => {
+ isMountedRef.current = true;
+ return () => {
+ isMountedRef.current = false;
+ };
+ }, []);
+
+ const rafRef = useRef<number | null>(null);
+ const lastSigRef = useRef<string>('');
+
+ useEffect(() => {
+ if (serverPagination || typeof onFilteredRowsChange !== 'function') {
+ return;
+ }
+
+ const sig = signatureOfRows(rows);
+
+ if (sig !== lastSigRef.current) {
+ lastSigRef.current = sig;
+ if (rafRef.current != null) {
+ cancelAnimationFrame(rafRef.current);
+ }
+ rafRef.current = requestAnimationFrame(() => {
+ if (isMountedRef.current) {
+ // Only emit originals when the signature truly changed
+ onFilteredRowsChange(rows.map(r => r.original as D));
+ }
+ });
+ }
+
+ return () => {
+ if (rafRef.current != null) {
+ cancelAnimationFrame(rafRef.current);
+ rafRef.current = null;
+ }
+ };
+ }, [rows, serverPagination, onFilteredRowsChange]);
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Broken client-side data flow</b></div>
<div id="fix">
Removing this effect breaks `clientView.rows` population in TableChart.tsx
(line 1619). In client-side mode, `clientViewRows` will remain `[]` forever
since `setClientViewRows` is only called via this removed callback. Features
relying on `clientView.rows` (export, snapshot, charts) will receive empty data.
</div>
</div>
<small><i>Code Review Run #f9cf37</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]