Skip to content

Conversation

@tychenjiajun
Copy link
Contributor

@tychenjiajun tychenjiajun commented Mar 16, 2024

Summary by CodeRabbit

  • New Features

    • Added an autoResetSorting option at both table and column levels to automatically reset sorting when the sorting state changes, improving consistency with other auto-reset behaviors.
  • Documentation

    • Updated sorting feature docs to include the new autoResetSorting option for tables and columns.
    • Clarified surrounding text and adjusted code snippets and formatting for readability.

@nx-cloud
Copy link

nx-cloud bot commented Mar 16, 2024

View your CI Pipeline Execution ↗ for commit 419bec9

Command Status Duration Result
nx affected --targets=test:format,test:sherif,t... ✅ Succeeded 46m 44s View ↗
nx run-many --targets=build --exclude=examples/** ✅ Succeeded 29s View ↗

☁️ Nx Cloud last updated this comment at 2025-10-15 01:49:56 UTC

@KevinVandy
Copy link
Member

What's the use-case for this? Usually changing the sorting state without user-input is bad UX, right?

@tychenjiajun
Copy link
Contributor Author

What's the use-case for this? Usually changing the sorting state without user-input is bad UX, right?

Personally I agree that changing the sorting state without user-input is bad UX. But there's still some designers prefer automatically resetting the sorting state when data changes.

@tychenjiajun
Copy link
Contributor Author

Also, see #5217

@KevinVandy
Copy link
Member

KevinVandy commented Mar 19, 2024

ok, open to merging this, but need to test more. Definitely agree that this should not be enabled by default like some of the other autoReset options though.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Oct 18, 2024

More templates

@tanstack/angular-table

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

@tanstack/lit-table

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

@tanstack/match-sorter-utils

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

@tanstack/qwik-table

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

@tanstack/react-table

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

@tanstack/react-table-devtools

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

@tanstack/solid-table

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

@tanstack/svelte-table

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

@tanstack/table-core

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

@tanstack/vue-table

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

commit: 419bec9

@changeset-bot
Copy link

changeset-bot bot commented Oct 15, 2025

⚠️ No Changeset found

Latest commit: 419bec9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link

coderabbitai bot commented Oct 15, 2025

Walkthrough

Adds an autoResetSorting option to the sorting feature, exposes a new internal _autoResetSorting hook on the table instance, and wires it to run during sorted row model memoization alongside _autoResetPageIndex. Documentation updated to reflect the new option at both table and column levels.

Changes

Cohort / File(s) Summary
Docs: Sorting options
docs/api/features/sorting.md
Documents new autoResetSorting boolean for Column API and Table Options; minor formatting adjustments.
Core: Row sorting auto-reset
packages/table-core/src/features/RowSorting.ts
Adds SortingOptionsBase.autoResetSorting, exposes SortingInstance._autoResetSorting, implements queued auto-reset of sorting based on options (autoResetAll, autoResetSorting, manualSorting).
Core: Sorted row model memo
packages/table-core/src/utils/getSortedRowModel.ts
In memo setup, invokes table._autoResetSorting() then table._autoResetPageIndex(); converts callback to block to accommodate side-effects.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User/Consumer
  participant T as Table Instance
  participant RS as RowSorting Feature
  participant GM as getSortedRowModel Memo

  U->>T: setOptions / setState (sorting change)
  T->>GM: compute sorted row model (memo)
  GM->>T: _autoResetSorting()  Note over GM,T: New side-effect
  T->>RS: _autoResetSorting()
  RS->>RS: if (autoResetAll || autoResetSorting) && !manualSorting
  alt should auto-reset
    RS-->>T: queue resetSorting() after current cycle
  else no reset
    RS-->>T: do nothing
  end
  GM->>T: _autoResetPageIndex()  Note over GM,T: Existing pattern
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I twitch my whiskers—tables align,
A breeze flips sorts to baseline fine.
With quiet hops, resets take wing,
Memo whispers, “queue the spring.”
Rows re-form in tidy streams—
A rabbit’s order, light as dreams. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request description is missing entirely, so it does not include any of the required template sections for changes, checklist items, or release impact. Please add a description following the repository template, including the “🎯 Changes” section detailing what and why you changed, the “✅ Checklist” confirming testing and contribution steps, and the “🚀 Release Impact” outlining any required changesets or documentation updates.
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 (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title “feat: add autoResetSorting” clearly and concisely describes the primary change, namely introducing the autoResetSorting feature, making it immediately understandable to reviewers.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 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: 3

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 02c203a and 419bec9.

📒 Files selected for processing (3)
  • docs/api/features/sorting.md (2 hunks)
  • packages/table-core/src/features/RowSorting.ts (3 hunks)
  • packages/table-core/src/utils/getSortedRowModel.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
packages/table-core/src/utils/getSortedRowModel.ts (1)
packages/table-core/src/utils.ts (1)
  • getMemoOptions (202-219)
🪛 LanguageTool
docs/api/features/sorting.md

[grammar] ~327-~327: There might be a mistake here.
Context: ...ly reset the sorting state of the table when sorting state changes. ### `sortDescFi...

(QB_NEW_EN)

⏰ 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 (2)
packages/table-core/src/features/RowSorting.ts (1)

255-255: LGTM!

The internal _autoResetSorting method is correctly declared and follows the established pattern for auto-reset hooks.

packages/table-core/src/utils/getSortedRowModel.ts (1)

117-120: LGTM!

The integration of _autoResetSorting() correctly follows the same pattern as _autoResetPageIndex(). The callback is triggered when the memoized row model changes, which occurs when either the sorting state or the underlying data (pre-sorted row model) changes.

Comment on lines +321 to +328
### `autoResetSorting`
```tsx
autoResetSorting?: boolean
```
Enable this setting to automatically reset the sorting state of the table when sorting state changes.
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix the misleading description to accurately describe when auto-reset occurs.

The description states "when sorting state changes," which is circular and inaccurate. The auto-reset is triggered when the underlying data changes (when getPreSortedRowModel() returns a new value), not when the sorting state itself changes.

Apply this diff to fix the documentation:

-Enable this setting to automatically reset the sorting state of the table when sorting state changes.
+Enable this setting to automatically reset the sorting state of the table when the underlying data changes.

Based on static analysis hints.

📝 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
### `autoResetSorting`
```tsx
autoResetSorting?: boolean
```
Enable this setting to automatically reset the sorting state of the table when sorting state changes.
### `autoResetSorting`
🧰 Tools
🪛 LanguageTool

[grammar] ~327-~327: There might be a mistake here.
Context: ...ly reset the sorting state of the table when sorting state changes. ### `sortDescFi...

(QB_NEW_EN)

🤖 Prompt for AI Agents
In docs/api/features/sorting.md around lines 321 to 328, the description for
`autoResetSorting` is misleading: it says it resets "when sorting state changes"
but actually triggers when the underlying data changes (i.e., when
getPreSortedRowModel() returns a new value). Update the wording to state that
enabling `autoResetSorting` will automatically reset the table's sorting state
when the underlying row data changes (pre-sorted row model changes), not when
the sorting state itself changes, and keep the prop signature and example
intact.

Comment on lines +198 to +203
/**
* Enable this setting to automatically reset the sorting state of the table when sorting state changes.
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#autoresetsorting)
* @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
*/
autoResetSorting?: boolean
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Clarify the documentation to accurately describe when auto-reset occurs.

The comment states "when sorting state changes," which is circular and misleading. Based on the implementation, this feature resets sorting when the underlying data changes (specifically when getPreSortedRowModel() returns a new value), not when the sorting state itself changes.

Apply this diff to clarify the documentation:

   /**
-   * Enable this setting to automatically reset the sorting state of the table when sorting state changes.
+   * Enable this setting to automatically reset the sorting state of the table when the underlying data changes.
    * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#autoresetsorting)
    * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
    */
📝 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
/**
* Enable this setting to automatically reset the sorting state of the table when sorting state changes.
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#autoresetsorting)
* @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
*/
autoResetSorting?: boolean
/**
* Enable this setting to automatically reset the sorting state of the table when the underlying data changes.
* @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#autoresetsorting)
* @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
*/
autoResetSorting?: boolean
🤖 Prompt for AI Agents
In packages/table-core/src/features/RowSorting.ts around lines 198 to 203, the
JSDoc for autoResetSorting is misleading because it says "when sorting state
changes" — update the comment to state that autoResetSorting controls whether
sorting is automatically reset when the underlying row data changes
(specifically when getPreSortedRowModel() returns a new value), not when the
sorting state itself changes; keep the existing API Docs and Guide links and
wording about enabling the setting but replace the phrase to reference
data/pre-sorted row model changes.

Comment on lines +532 to +555
let registered = false
let queued = false

table._autoResetSorting = () => {
if (!registered) {
table._queue(() => {
registered = true
})
return
}

if (
table.options.autoResetAll ??
table.options.autoResetSorting ??
!table.options.manualSorting
) {
if (queued) return
queued = true
table._queue(() => {
table.resetSorting()
queued = false
})
}
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

The default behavior contradicts the requirement that auto-reset should not be enabled by default.

The condition on lines 543-546 evaluates to true by default when neither autoResetAll nor autoResetSorting is set and manualSorting is not enabled. This means the feature is enabled by default, which contradicts the maintainer's explicit requirement in the PR comments that "the feature should not be enabled by default, similar to other autoReset options."

Apply this diff to disable the feature by default:

       if (
         table.options.autoResetAll ??
-        table.options.autoResetSorting ??
-        !table.options.manualSorting
+        table.options.autoResetSorting
       ) {

This change ensures that auto-reset only occurs when:

  1. autoResetAll is explicitly set to true, OR
  2. autoResetSorting is explicitly set to true

Without this change, existing applications not using manualSorting will experience unexpected sorting resets when data changes, which could be a breaking change.

📝 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
let registered = false
let queued = false
table._autoResetSorting = () => {
if (!registered) {
table._queue(() => {
registered = true
})
return
}
if (
table.options.autoResetAll ??
table.options.autoResetSorting ??
!table.options.manualSorting
) {
if (queued) return
queued = true
table._queue(() => {
table.resetSorting()
queued = false
})
}
}
let registered = false
let queued = false
table._autoResetSorting = () => {
if (!registered) {
table._queue(() => {
registered = true
})
return
}
if (
table.options.autoResetAll ??
table.options.autoResetSorting
) {
if (queued) return
queued = true
table._queue(() => {
table.resetSorting()
queued = false
})
}
}
🤖 Prompt for AI Agents
In packages/table-core/src/features/RowSorting.ts around lines 532 to 555, the
current condition enables auto-reset by default when neither autoResetAll nor
autoResetSorting is set and manualSorting is false; change the conditional so
auto-reset only runs when autoResetAll or autoResetSorting are explicitly true
(e.g. replace the truthy-coalescing check with an explicit equality check:
table.options.autoResetAll === true || table.options.autoResetSorting === true),
leaving the registered/queued logic and table._queue call intact.

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