diff --git a/.changeset/every-parks-raise.md b/.changeset/every-parks-raise.md new file mode 100644 index 0000000000..45fe8634b8 --- /dev/null +++ b/.changeset/every-parks-raise.md @@ -0,0 +1,5 @@ +--- +'@tanstack/table-core': patch +--- + +Prevents non expandable rows from being added to the state when the old state was true diff --git a/packages/table-core/src/features/RowExpanding.ts b/packages/table-core/src/features/RowExpanding.ts index 15da45e0ea..74052f632f 100644 --- a/packages/table-core/src/features/RowExpanding.ts +++ b/packages/table-core/src/features/RowExpanding.ts @@ -294,8 +294,11 @@ export const RowExpanding: TableFeature = { let oldExpanded: ExpandedStateList = {} if (old === true) { - Object.keys(table.getRowModel().rowsById).forEach(rowId => { - oldExpanded[rowId] = true + const rowIds = table.getRowModel().rowsById + Object.keys(rowIds).forEach(rowId => { + if (rowIds[rowId]?.getCanExpand()) { + oldExpanded[rowId] = true + } }) } else { oldExpanded = old