jethac opened a new issue, #42978:
URL: https://github.com/apache/superset/issues/42978

   ### Bug description
   
   `DataTable` declares five hooks *after* an early return, so a table chart 
that transitions between "no columns" and "has columns" changes its hook count 
between renders and React throws.
   
   `superset-frontend/plugins/plugin-chart-table/src/DataTable/DataTable.tsx` 
returns early when there are no columns (line ~344):
   
   ```tsx
   if (!columns || columns.length === 0) {
     return (wrapStickyTable ? wrapStickyTable(getNoResults) : getNoResults()) 
as JSX.Element;
   }
   ```
   
   Five hooks — `isMountedRef`, the mount `useEffect`, `rafRef`, `lastSigRef`, 
and the `useEffect` that emits filtered rows through `onFilteredRowsChange` — 
are declared roughly 130 lines below it (first one at line ~476). Crossing that 
boundary in either direction violates the Rules of Hooks:
   
   - 0 columns → N columns: `Rendered more hooks than during the previous 
render.`
   - N columns → 0 columns: `Rendered fewer hooks than expected. This may be 
caused by an accidental early return statement.`
   
   Either throw takes the chart out on an error boundary. `TableChart` renders 
one `DataTable` instance and derives `columns` from the query result, so the 
crossing happens whenever a table chart re-queries between a columns-less 
result and one with columns.
   
   This is currently invisible to CI: `react-hooks/rules-of-hooks` is `warn` in 
`oxlint.json` and `npm run lint` passes `--quiet`. There are 47 violations of 
that rule in the tree, 5 of them in this file.
   
   ### Expected results
   
   A table chart that re-queries from an empty result to a populated one (or 
back) re-renders without throwing.
   
   ### Actual results
   
   React throws on the hook-count change and the chart unmounts to an error 
boundary.
   
   ### Proposed fix
   
   Move the five hooks above the early return. It is a move, not a rewrite — no 
hook body, dependency array, or emit condition needs to change. `stableRowKey`, 
`hashString` and `signatureOfRows` close over nothing and can move to module 
scope.
   
   One behaviour note worth stating: the emit effect would then also run while 
the table has no columns, so a consumer of `onFilteredRowsChange` receives one 
`[]` emission it does not get today. The only in-tree consumer is `TableChart`, 
whose `clientViewRows` is already initialised to `[]` and already pushes 
`{rows: [], count: 0}` on mount, so that emission is redundant rather than new 
information.
   
   Measured on `superset-frontend` with `oxlint --config oxlint.json 
--format=json`: `rules-of-hooks` 47 → 42, total diagnostics 1470 → 1465, 
`exhaustive-deps` unchanged at 381.
   
   Verified against `master` at `3539c41dab`. Happy to open a PR.


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