Skip to content

Conversation

Sheraff
Copy link

@Sheraff Sheraff commented Sep 20, 2025

When used as the type for a function parameter, readonly ensures that the parameter will not be mutated inside the function.

The columns and data array inputs are never modified by table-core. They should thus be marked as readonly 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:

const Component = () => {
  const { data } = useQuery({ ... })
  const table = useReactTable({ data, ... })

In a case like this, data comes from the tanstack/query cache, and as such must be immutable. If useReactTable can guarantee that it won't modify the array we pass in, then we can pass data directly.

Summary by CodeRabbit

  • Refactor

    • Table options now use readonly arrays. Both data and columns accept readonly arrays, and related getters return readonly arrays. This enforces immutability and improves type safety. If your code mutates these arrays or relies on mutable types, update it to create new arrays instead.
  • Documentation

    • API docs updated to reflect readonly types for data and columns in the Table APIs.

Copy link

nx-cloud bot commented Sep 20, 2025

View your CI Pipeline Execution ↗ for commit e6b7bbd

Command Status Duration Result
nx run-many --targets=build --exclude=examples/** ✅ Succeeded 29s View ↗

☁️ Nx Cloud last updated this comment at 2025-09-22 07:18:23 UTC

Copy link

coderabbitai bot commented Sep 22, 2025

Walkthrough

Types 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

Cohort / File(s) Change Summary
Public API: readonly arrays
docs/api/core/table.md, packages/table-core/src/core/table.ts
Updated CoreOptions: data: TData[] -> readonly TData[], columns: ColumnDef<TData, any>[] -> readonly ColumnDef<TData, any>[]. Updated CoreInstance: _getColumnDefs(): ColumnDef<TData, unknown>[] -> readonly ColumnDef<TData, unknown>[]. Reflected in docs.
Internal helpers: readonly parameters
packages/table-core/src/utils/getCoreRowModel.ts, packages/table-core/src/core/table.ts
Adjusted helper parameters to accept readonly arrays (e.g., recurseColumns(columnDefs: readonly ColumnDef<...>[]), accessRows(originalRows: readonly TData[])). No logic changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I nudge my paws through rows so neat,
Columns crisp, immutable treat.
Readonly fields, no nibble’s sway—
The table stands in structured array.
I hop, I sort, with gentle care,
A bunny’s oath: don’t mutate there. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly and accurately describes the primary change in the changeset—marking CoreOptions.columns and CoreOptions.data as readonly in table-core types—matches the modified files and PR objectives, and is concise and clear without noise.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

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 @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a 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'] return readonly TData[] to propagate immutability through nested data as well (backward‑compatible since TData[] is assignable to readonly TData[]). See suggested diff in table.ts comment below.

docs/api/core/table.md (1)

22-22: Docs correctly reflect readonly for data and columns.

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

📥 Commits

Reviewing files that changed from the base of the PR and between d538a90 and e6b7bbd.

📒 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.

Copy link

pkg-pr-new bot commented Sep 22, 2025

More templates

@tanstack/angular-table

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

@tanstack/lit-table

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

@tanstack/match-sorter-utils

npm i https://pkg.pr.new/@tanstack/match-sorter-utils@6098

@tanstack/qwik-table

npm i https://pkg.pr.new/@tanstack/qwik-table@6098

@tanstack/react-table

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

@tanstack/react-table-devtools

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

@tanstack/solid-table

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

@tanstack/svelte-table

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

@tanstack/table-core

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

@tanstack/vue-table

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

commit: e6b7bbd

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.

2 participants