From 88ea0e836faa0399d14c1f2685c74e483df48f4e Mon Sep 17 00:00:00 2001 From: csl666 <12984448+csl6666666@user.noreply.gitee.com> Date: Fri, 24 Oct 2025 19:20:49 +0800 Subject: [PATCH 1/4] WIP: My RowExpanding.ts fix --- examples/react/basic/src/data.ts | 44 +++++++++++++++++++ .../table-core/src/features/RowExpanding.ts | 11 ++++- 2 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 examples/react/basic/src/data.ts diff --git a/examples/react/basic/src/data.ts b/examples/react/basic/src/data.ts new file mode 100644 index 0000000000..aed34a9b99 --- /dev/null +++ b/examples/react/basic/src/data.ts @@ -0,0 +1,44 @@ +export type Person = { + firstName: string; + lastName: string; + age: number; + visits: number; + subRows?: Person[]; // <-- Key to nesting! +}; + +export const defaultData: Person[] = [ + { + firstName: 'Tanner', + lastName: 'Linsley', + age: 24, + visits: 100, + subRows: [ // These are the nested rows for Tanner + { + firstName: 'Kevin', + lastName: 'Vandy', + age: 27, + visits: 200, + }, + { + firstName: 'John', + lastName: 'Doe', + age: 45, + visits: 20, + subRows: [ // Deeper nesting is possible + { + firstName: 'Child', + lastName: 'Doe', + age: 5, + visits: 1, + }, + ], + }, + ], + }, + { + firstName: 'Jane', + lastName: 'Doe', + age: 40, + visits: 80, + }, +]; \ No newline at end of file diff --git a/packages/table-core/src/features/RowExpanding.ts b/packages/table-core/src/features/RowExpanding.ts index 15da45e0ea..736224a73b 100644 --- a/packages/table-core/src/features/RowExpanding.ts +++ b/packages/table-core/src/features/RowExpanding.ts @@ -311,8 +311,15 @@ export const RowExpanding: TableFeature = { } if (exists && !expanded) { - const { [row.id]: _, ...rest } = oldExpanded - return rest + const currentExpandedState = table.getState().expanded as ExpandedStateList; + const rowIds = Object.keys(currentExpandedState); + const updatedExpandedState = rowIds.reduce((acc, rowId) => { + if (!rowId.startsWith(row.id)) { + acc[rowId] = !!(currentExpandedState[rowId]); + } + return acc; + }, {} as ExpandedStateList); + return updatedExpandedState; } return old From 207f890b99fdcdca8d47814c6ea97ad11cade9d3 Mon Sep 17 00:00:00 2001 From: ugjjffu <56184119+ugjjffu@users.noreply.github.com> Date: Fri, 24 Oct 2025 23:03:30 +0800 Subject: [PATCH 2/4] Update packages/table-core/src/features/RowExpanding.ts agree Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- packages/table-core/src/features/RowExpanding.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/table-core/src/features/RowExpanding.ts b/packages/table-core/src/features/RowExpanding.ts index 736224a73b..21eb336bc2 100644 --- a/packages/table-core/src/features/RowExpanding.ts +++ b/packages/table-core/src/features/RowExpanding.ts @@ -311,15 +311,12 @@ export const RowExpanding: TableFeature = { } if (exists && !expanded) { - const currentExpandedState = table.getState().expanded as ExpandedStateList; - const rowIds = Object.keys(currentExpandedState); - const updatedExpandedState = rowIds.reduce((acc, rowId) => { - if (!rowId.startsWith(row.id)) { - acc[rowId] = !!(currentExpandedState[rowId]); + return Object.keys(oldExpanded).reduce((acc, rowId) => { + if (rowId !== row.id && !rowId.startsWith(row.id + '.')) { + acc[rowId] = oldExpanded[rowId]; } return acc; }, {} as ExpandedStateList); - return updatedExpandedState; } return old From 79797d18d24da5d1bb5d8072663c4958d69b67ef Mon Sep 17 00:00:00 2001 From: ugjjffu <56184119+ugjjffu@users.noreply.github.com> Date: Fri, 24 Oct 2025 23:31:20 +0800 Subject: [PATCH 3/4] Delete examples/react/basic/src/data.ts remove abundant data.ts --- examples/react/basic/src/data.ts | 44 -------------------------------- 1 file changed, 44 deletions(-) delete mode 100644 examples/react/basic/src/data.ts diff --git a/examples/react/basic/src/data.ts b/examples/react/basic/src/data.ts deleted file mode 100644 index aed34a9b99..0000000000 --- a/examples/react/basic/src/data.ts +++ /dev/null @@ -1,44 +0,0 @@ -export type Person = { - firstName: string; - lastName: string; - age: number; - visits: number; - subRows?: Person[]; // <-- Key to nesting! -}; - -export const defaultData: Person[] = [ - { - firstName: 'Tanner', - lastName: 'Linsley', - age: 24, - visits: 100, - subRows: [ // These are the nested rows for Tanner - { - firstName: 'Kevin', - lastName: 'Vandy', - age: 27, - visits: 200, - }, - { - firstName: 'John', - lastName: 'Doe', - age: 45, - visits: 20, - subRows: [ // Deeper nesting is possible - { - firstName: 'Child', - lastName: 'Doe', - age: 5, - visits: 1, - }, - ], - }, - ], - }, - { - firstName: 'Jane', - lastName: 'Doe', - age: 40, - visits: 80, - }, -]; \ No newline at end of file From 15f4c80e43185f81281ba3245cc2714b1ffd4b4e Mon Sep 17 00:00:00 2001 From: csl666 <12984448+csl6666666@user.noreply.gitee.com> Date: Sat, 25 Oct 2025 00:32:24 +0800 Subject: [PATCH 4/4] add changeset --- .changeset/every-grapes-judge.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/every-grapes-judge.md diff --git a/.changeset/every-grapes-judge.md b/.changeset/every-grapes-judge.md new file mode 100644 index 0000000000..7f64075285 --- /dev/null +++ b/.changeset/every-grapes-judge.md @@ -0,0 +1,5 @@ +--- +'@tanstack/table-core': major +--- + +fix API to calculate max expanded row depth