Skip to content

fix(table-core): avoid parent lookup re-entrancy#6441

Merged
KevinVandy merged 1 commit into
betafrom
agent/audit-5630-parent-filter
Jul 24, 2026
Merged

fix(table-core): avoid parent lookup re-entrancy#6441
KevinVandy merged 1 commit into
betafrom
agent/audit-5630-parent-filter

Conversation

@KevinVandy

@KevinVandy KevinVandy commented Jul 18, 2026

Copy link
Copy Markdown
Member

Closes #5630

What changed

  • Resolve structural parent rows from the core row model before consulting the pre-pagination model.
  • Preserve the pre-pagination fallback for generated parent rows, such as grouped rows.
  • Add a regression test for parent-aware column filter functions with both an initial filter and a subsequent filter update.

Why

During filtered-row-model construction, a custom filter function can call row.getParentRow(). The previous lookup entered the pre-pagination pipeline, which requests the filtered model currently being built and reads rowsById from an incomplete result. Looking up structural parents from the already-built core row model avoids this re-entrancy without changing support for generated parents.

Validation

  • pnpm --filter @tanstack/table-core test:lib --run (52 files, 1005 tests)
  • pnpm --filter @tanstack/table-core test:types
  • pnpm --filter @tanstack/table-core test:eslint
  • Prettier check on changed files
  • git diff --check

Summary by CodeRabbit

  • Bug Fixes
    • Improved nested-row filtering so filter functions can reliably inspect structural parent rows.
    • Ensured matching child rows and their relevant parent rows are included correctly in filtered results.
    • Prevented errors when filtering nested data across different parent branches.

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

row_getParentRow now resolves structural parents from the core row model before falling back to the pre-pagination model. Nested column-filtering tests verify parent-aware filtering, returned flat rows, and non-throwing behavior.

Changes

Structural Parent Resolution

Layer / File(s) Summary
Core parent lookup and filtering validation
packages/table-core/src/core/rows/coreRowsFeature.utils.ts, packages/table-core/tests/implementation/features/column-filtering/createFilteredRowModel.test.ts
row_getParentRow returns early without a parent ID, checks core rows first, and falls back to generated rows. Nested filtering tests verify parent-aware results and repeated filter updates without errors.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: preventing parent-row lookup re-entrancy in table-core.
Linked Issues check ✅ Passed The fix resolves parent lookup from the core row model first, and the new test covers parent-aware filtering without re-entrancy errors.
Out of Scope Changes check ✅ Passed The changes stay focused on the bug fix and regression test, with no明显 unrelated scope added.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/audit-5630-parent-filter

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@nx-cloud

nx-cloud Bot commented Jul 18, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 67547ea

Command Status Duration Result
nx affected --targets=test:eslint,test:sherif,t... ✅ Succeeded 8m 10s View ↗
nx run-many --targets=build --exclude=examples/** ✅ Succeeded 49s View ↗

☁️ Nx Cloud last updated this comment at 2026-07-18 00:42:11 UTC

@pkg-pr-new

pkg-pr-new Bot commented Jul 18, 2026

Copy link
Copy Markdown
More templates

@tanstack/alpine-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/alpine-table@6441

@tanstack/angular-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/angular-table@6441

@tanstack/angular-table-devtools

npm i https://pkg.pr.new/TanStack/table/@tanstack/angular-table-devtools@6441

@tanstack/ember-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/ember-table@6441

@tanstack/lit-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/lit-table@6441

@tanstack/match-sorter-utils

npm i https://pkg.pr.new/TanStack/table/@tanstack/match-sorter-utils@6441

@tanstack/preact-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/preact-table@6441

@tanstack/preact-table-devtools

npm i https://pkg.pr.new/TanStack/table/@tanstack/preact-table-devtools@6441

@tanstack/react-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/react-table@6441

@tanstack/react-table-devtools

npm i https://pkg.pr.new/TanStack/table/@tanstack/react-table-devtools@6441

@tanstack/solid-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/solid-table@6441

@tanstack/solid-table-devtools

npm i https://pkg.pr.new/TanStack/table/@tanstack/solid-table-devtools@6441

@tanstack/svelte-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/svelte-table@6441

@tanstack/table-core

npm i https://pkg.pr.new/TanStack/table/@tanstack/table-core@6441

@tanstack/table-devtools

npm i https://pkg.pr.new/TanStack/table/@tanstack/table-devtools@6441

@tanstack/vue-table

npm i https://pkg.pr.new/TanStack/table/@tanstack/vue-table@6441

@tanstack/vue-table-devtools

npm i https://pkg.pr.new/TanStack/table/@tanstack/vue-table-devtools@6441

commit: 67547ea

@KevinVandy
KevinVandy marked this pull request as ready for review July 24, 2026 15:10

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/table-core/src/core/rows/coreRowsFeature.utils.ts`:
- Around line 203-205: Update the parent check in the row-parent resolution
logic to test specifically for an undefined parentId, preserving empty-string
IDs as valid values. Keep the existing undefined return behavior when no parent
ID is provided.

In
`@packages/table-core/tests/implementation/features/column-filtering/createFilteredRowModel.test.ts`:
- Around line 107-129: Add a grandchild to the nested-row fixture in the
relevant filtering test, then add a filter case whose value matches only that
deeper descendant. Assert the filtered flat rows retain the matching descendant
and all of its ancestor rows, while preserving the existing parent-match
assertions to cover recursive parent lookup.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5a9ee65a-52d8-4be6-aa67-1acf9cd782be

📥 Commits

Reviewing files that changed from the base of the PR and between 209699f and 67547ea.

📒 Files selected for processing (2)
  • packages/table-core/src/core/rows/coreRowsFeature.utils.ts
  • packages/table-core/tests/implementation/features/column-filtering/createFilteredRowModel.test.ts

Comment on lines +203 to +205
if (!row.parentId) {
return undefined
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Preserve empty-string row IDs.

Line 203 treats '' as no parent, so custom getRowId implementations using an empty-string ID cannot resolve their children’s parent. Check specifically for undefined.

Proposed fix
-  if (!row.parentId) {
+  if (row.parentId === undefined) {
     return undefined
   }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!row.parentId) {
return undefined
}
if (row.parentId === undefined) {
return undefined
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/table-core/src/core/rows/coreRowsFeature.utils.ts` around lines 203
- 205, Update the parent check in the row-parent resolution logic to test
specifically for an undefined parentId, preserving empty-string IDs as valid
values. Keep the existing undefined return behavior when no parent ID is
provided.

Comment on lines +107 to +129
data: [
{ name: 'parent', subRows: [{ name: 'child' }] },
{ name: 'other', subRows: [{ name: 'nested' }] },
],
getSubRows: (row) => row.subRows,
initialState: {
columnFilters: [{ id: 'name', value: 'parent' }],
},
})

expect(() => table.getFilteredRowModel()).not.toThrow()
expect(rowNames(table.getFilteredRowModel().flatRows).sort()).toEqual([
'child',
'parent',
])

table.setColumnFilters([{ id: 'name', value: 'other' }])

expect(() => table.getFilteredRowModel()).not.toThrow()
expect(rowNames(table.getFilteredRowModel().flatRows).sort()).toEqual([
'nested',
'other',
])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Cover descendant matches across multiple nesting levels.

The fixture only has one child level, and both filter values match parents. Add a grandchild plus a descendant-matching filter case, asserting its ancestor family is retained; this validates recursive parent lookup and the linked issue’s multi-level requirement.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@packages/table-core/tests/implementation/features/column-filtering/createFilteredRowModel.test.ts`
around lines 107 - 129, Add a grandchild to the nested-row fixture in the
relevant filtering test, then add a filter case whose value matches only that
deeper descendant. Assert the filtered flat rows retain the matching descendant
and all of its ancestor rows, while preserving the existing parent-match
assertions to cover recursive parent lookup.

@KevinVandy
KevinVandy merged commit c140a13 into beta Jul 24, 2026
9 checks passed
@KevinVandy
KevinVandy deleted the agent/audit-5630-parent-filter branch July 24, 2026 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Calling row.getParentRow() with expanded, filtered row models and initial filtering value throws an error

1 participant