-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix(table-core): CoreOptions columns and data are readonly #6098
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix(table-core): CoreOptions columns and data are readonly #6098
Conversation
View your CI Pipeline Execution ↗ for commit e6b7bbd
☁️ Nx Cloud last updated this comment at |
WalkthroughTypes for data and column collections are changed to readonly arrays across core options, internal helpers, and documentation. CoreInstance’s _getColumnDefs now returns a readonly array. No algorithmic or control-flow changes are introduced. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal). Please share your feedback with us on this Discord post. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
packages/table-core/src/utils/getCoreRowModel.ts (1)
25-25
: Readonly input for accessRows is correct; no functional change.This tightens the contract without breaking callers. One consistency follow‑up: consider making
CoreOptions['getSubRows']
returnreadonly TData[]
to propagate immutability through nested data as well (backward‑compatible sinceTData[]
is assignable toreadonly TData[]
). See suggested diff in table.ts comment below.docs/api/core/table.md (1)
22-22
: Docs correctly reflect readonly fordata
andcolumns
.For completeness with nested rows, consider updating
getSubRows
’ return type to readonly too.Apply this diff:
-getSubRows?: ( - originalRow: TData, - index: number -) => undefined | TData[] +getSubRows?: ( + originalRow: TData, + index: number +) => undefined | readonly TData[]Also applies to: 34-34
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
docs/api/core/table.md
(2 hunks)packages/table-core/src/core/table.ts
(3 hunks)packages/table-core/src/utils/getCoreRowModel.ts
(1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-09-15T15:05:14.117Z
Learnt from: stevenwjy
PR: TanStack/table#6094
File: packages/table-core/src/utils/getGroupedRowModel.ts:74-78
Timestamp: 2025-09-15T15:05:14.117Z
Learning: In TanStack Table's Row interface, the `subRows` property is typed as `Row<TData>[]` (not optional) and the `createRow` function always initializes it as an empty array, so `subRows` is guaranteed to never be undefined.
Applied to files:
docs/api/core/table.md
packages/table-core/src/utils/getCoreRowModel.ts
📚 Learning: 2025-09-15T15:05:14.117Z
Learnt from: stevenwjy
PR: TanStack/table#6094
File: packages/table-core/src/utils/getGroupedRowModel.ts:74-78
Timestamp: 2025-09-15T15:05:14.117Z
Learning: In TanStack Table's Row interface, the `subRows` property is typed as `Row<TData>[]` (not optional) and the `createRow` function always initializes it as an empty array using `subRows ?? []`, so `subRows` is guaranteed to never be undefined.
Applied to files:
docs/api/core/table.md
packages/table-core/src/utils/getCoreRowModel.ts
🧬 Code graph analysis (1)
packages/table-core/src/core/table.ts (1)
packages/table-core/src/types.ts (1)
ColumnDef
(328-331)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Test
- GitHub Check: Preview
🔇 Additional comments (1)
packages/table-core/src/core/table.ts (1)
81-81
: Make getSubRows return readonly and verify no mutations
- Great move to readonly for columns/data and internal getters.
- Change signature to return readonly subrows — apply diff below.
- getSubRows?: (originalRow: TData, index: number) => undefined | TData[] + getSubRows?: (originalRow: TData, index: number) => undefined | readonly TData[]
- Verification: the provided ripgrep run returned "No files were searched", so I could not confirm absence of any mutations to options.data / options.columns / _getColumnDefs — re-run the verification script (or allow a repo run) to ensure no mutating calls or assignments exist.
Also applies to: 87-87, 198-198, 450-450.
When used as the type for a function parameter,
readonly
ensures that the parameter will not be mutated inside the function.The
columns
anddata
array inputs are never modified bytable-core
. They should thus be marked asreadonly
to make this contract explicit. This allows developper to rely on the guarantee they can pass in static objects.Here's an example where this is useful:
In a case like this,
data
comes from thetanstack/query
cache, and as such must be immutable. IfuseReactTable
can guarantee that it won't modify the array we pass in, then we can passdata
directly.Summary by CodeRabbit
Refactor
Documentation