Skip to content
Open
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -201,18 +201,21 @@ const DataTable = <TData, TValue>(props: DataTableProps<TData, TValue>) => {
const handleRowClick = useCallback(
(row: Row<TData>) => {
if (typeof onRowClick === 'function') {
const isAlreadySelected = table.getState().rowSelection[row.id];

if (isAlreadySelected) {
table.setRowSelection({});
} else {
table.setRowSelection({ [row.id]: true });
// When selectedRow is provided the parent controls selection.
if (selectedRow === undefined) {
const isAlreadySelected = table.getState().rowSelection[row.id];
Comment on lines +204 to +206
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Use one consistent controlled/uncontrolled predicate.

This branch uses selectedRow === undefined, but the state-sync effect uses truthy/falsy checks. That mismatch can behave differently for falsy-but-defined IDs and lead to unexpected selection clearing.

Proposed alignment
-    useEffect(() => {
-        if (!selectedRow && table.getIsSomeRowsSelected()) {
+    useEffect(() => {
+        if (selectedRow === undefined && table.getIsSomeRowsSelected()) {
             table.setRowSelection({});
         }
 
-        if (selectedRow && !table.getState().rowSelection[selectedRow]) {
+        if (selectedRow !== undefined && !table.getState().rowSelection[selectedRow]) {
             table.setRowSelection({ [selectedRow]: true });
         }
     }, [selectedRow, table]);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/javascript/doodle-ui/src/components/DataTable/DataTable.tsx` around
lines 204 - 206, The selection-control predicate is inconsistent: one branch
checks selectedRow === undefined while the state-sync effect uses truthy/falsy
checks, which breaks when IDs are falsy (e.g., 0 or ""). Update the state-sync
effect to use the same explicit undefined check (selectedRow === undefined) or
change both places to use a single canonical predicate (e.g., selectedRow ===
undefined for uncontrolled) so selection clearing is consistent; locate the
logic around selectedRow, the branch using
table.getState().rowSelection[row.id], and the state-sync effect and make their
checks identical.


if (isAlreadySelected) {
table.setRowSelection({});
} else {
table.setRowSelection({ [row.id]: true });
}
}

onRowClick(row?.original);
}
},
[onRowClick, table]
[onRowClick, selectedRow, table]
);

const { className: tableClassName, heightContainerClassName, ...restTableProps } = TableProps || {};
Expand Down
Loading