table icon indicating copy to clipboard operation
table copied to clipboard

fix(table-core): CoreOptions columns and data are readonly

Open Sheraff opened this issue 3 months ago • 3 comments

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.

Sheraff avatar Sep 20 '25 15:09 Sheraff

View your CI Pipeline Execution ↗ for commit e6b7bbdf952510aedf531f8cfac0437e750453b0

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

nx-cloud[bot] avatar Sep 20 '25 15:09 nx-cloud[bot]

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.

coderabbitai[bot] avatar Sep 22 '25 04:09 coderabbitai[bot]

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

pkg-pr-new[bot] avatar Sep 22 '25 07:09 pkg-pr-new[bot]