codeant-ai-for-open-source[bot] commented on code in PR #42097:
URL: https://github.com/apache/superset/pull/42097#discussion_r3597137492
##########
superset-frontend/src/visualizations/TimeTable/TimeTable.tsx:
##########
@@ -115,29 +142,35 @@ const TimeTable = ({
});
}, [columnConfigs, data, rowType, rows, url]);
- const defaultSort =
- rowType === 'column' && columnConfigs.length
- ? [
- {
- id: columnConfigs[0].key,
- desc: true,
- },
- ]
- : [];
+ const defaultSort = useMemo(
+ () =>
+ rowType === 'column' && columnConfigs.length
+ ? [
+ {
+ id: columnConfigs[0].key,
+ desc: true,
+ },
+ ]
+ : [],
+ [rowType, columnConfigs],
+ );
return (
<TimeTableStyles
data-test="time-table"
className={className}
height={height}
+ hideTable={!isSizeStable}
>
- <TableView
- className="table-no-hover"
- columns={memoizedColumns}
- data={memoizedRows}
- initialSortBy={defaultSort}
- withPagination={false}
- />
+ {isSizeStable && (
+ <TableView
+ className="table-no-hover"
+ columns={memoizedColumns}
+ data={memoizedRows}
+ initialSortBy={defaultSort}
+ withPagination={false}
+ />
+ )}
Review Comment:
**Suggestion:** Conditionally unmounting `TableView` during resize resets
its internal react-table state on every resize cycle, so user-selected
sort/filter/pagination state is lost after resizing. Keep the table mounted and
only hide or pause expensive rendering work (for example via CSS visibility or
a lightweight overlay) so interaction state persists. [logic error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
❌ Time-series Table charts lose user sorting after resize.
⚠️ Dashboard resizing disrupts ongoing table-based data analysis.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. In `superset-frontend/src/visualizations/presets/MainPreset.ts:66`,
`TimeTableChartPlugin` is registered with `key: VizType.TimeTable`, and in
`superset-frontend/src/visualizations/TimeTable/index.ts:9-16` its
`loadChart` points to
`./TimeTable`, so any “Time-series Table” viz renders `TimeTable` from
`TimeTable.tsx:40-48`.
2. When the chart renders, `TimeTable` computes `defaultSort` in
`TimeTable.tsx:145-155`
and passes it as `initialSortBy={defaultSort}` to `<TableView>` in
`TimeTable.tsx:165-172`, while `TableView`’s internal React Table state is
initialized
from `initialSortBy` via `initialState.sortBy` in
`packages/superset-ui-core/src/components/TableView/TableView.tsx:44-51` and
`useTable(..., { initialState })` in lines 61-69.
3. A user changes the sort order by clicking a column header in the rendered
table
(handled inside `TableCollection` via `setSortBy` passed from `TableView` at
`TableView.tsx:53-60,105-121`), which updates the internal `sortBy` state
but is not
reflected back into any `TimeTable` props (no controlled `sortBy` is passed).
4. When the browser window or dashboard tile is resized, the `resize`
listener in
`TimeTable.tsx:56-71` runs `handleResize`, which sets `isSizeStable` to
`false` (line 58)
and causes the JSX condition `{isSizeStable && <TableView ... />}` at
`TimeTable.tsx:165-172` to become false; React unmounts `TableView`,
discarding its
internal `useTable` state, and after 300ms of no further resize events the
timer flips
`isSizeStable` back to `true` (lines 60-62), remounting `TableView` as a
fresh instance
that re-initializes sorting from `initialSortBy`, so any user-selected
sort/filter state
is lost after every resize cycle.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=cbce76a29bf14cd2834bf937418d3f03&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=cbce76a29bf14cd2834bf937418d3f03&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset-frontend/src/visualizations/TimeTable/TimeTable.tsx
**Line:** 165:173
**Comment:**
*Logic Error: Conditionally unmounting `TableView` during resize resets
its internal react-table state on every resize cycle, so user-selected
sort/filter/pagination state is lost after resizing. Keep the table mounted and
only hide or pause expensive rendering work (for example via CSS visibility or
a lightweight overlay) so interaction state persists.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42097&comment_hash=88c6e8c0bdc18d90f906d91408c71577e1ffde1b99d7e0195969894d70c5df57&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42097&comment_hash=88c6e8c0bdc18d90f906d91408c71577e1ffde1b99d7e0195969894d70c5df57&reaction=dislike'>👎</a>
--
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]