Skip to content

fix(react-table): fix infinite rerender issue in useLegacyTable#6202

Merged
KevinVandy merged 1 commit intoalphafrom
fix/react-use-legacy-table-infinite-rerender
Mar 12, 2026
Merged

fix(react-table): fix infinite rerender issue in useLegacyTable#6202
KevinVandy merged 1 commit intoalphafrom
fix/react-use-legacy-table-infinite-rerender

Conversation

@riccardoperra
Copy link
Collaborator

@riccardoperra riccardoperra commented Mar 12, 2026

This pr removes the useStore call in useLegacyTable since it's already used by the useTable hook with shallow selector. Table reference will change when that state is updated so we shouldn't need to call it twice in both hooks

https://github.com/TanStack/table/blob/alpha/packages/react-table/src/useTable.ts#L114-L122

I've also updated the Subscribe component to use the shallow selector to restore the default behavior we have in other adapters and previous tanstack store versions

@changeset-bot
Copy link

changeset-bot bot commented Mar 12, 2026

⚠️ No Changeset found

Latest commit: 00feb71

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.

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

@nx-cloud
Copy link

nx-cloud bot commented Mar 12, 2026

View your CI Pipeline Execution ↗ for commit 00feb71

Command Status Duration Result
nx affected --targets=test:eslint,test:sherif,t... ✅ Succeeded 55s View ↗
nx run-many --targets=build -p @tanstack/table-... ✅ Succeeded 4s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-12 18:15:53 UTC

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 12, 2026

📝 Walkthrough

Walkthrough

Two related state subscription updates: Subscribe.ts adds shallow equality comparison to store subscriptions, while useLegacyTable.ts refactors to pass state selectors directly to useTable, eliminating a separate state variable and simplifying the subscription pattern.

Changes

Cohort / File(s) Summary
State Subscription Improvements
packages/react-table/src/Subscribe.ts
Added shallow equality comparison to store subscription via third argument to useStore(). Enables shallower reactivity for selected state.
State Selection Refactoring
packages/react-table/src/useLegacyTable.ts
Refactored state selection pattern to pass state selector directly to useTable instead of creating separate useStore subscription. Simplified getState exposure from local variable to table.state, updated imports and dependency arrays accordingly.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Shallow waters, state runs deep,
No extra renders—comparisons keep,
Selectors nested, patterns refined,
Simpler subscriptions, peace of mind! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing an infinite rerender issue in useLegacyTable by removing the redundant useStore call.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/react-use-legacy-table-infinite-rerender
📝 Coding Plan
  • Generate coding plan for human review comments

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.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 12, 2026

More templates

@tanstack/angular-table

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

@tanstack/lit-table

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

@tanstack/match-sorter-utils

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

@tanstack/preact-table

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

@tanstack/react-table

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

@tanstack/react-table-devtools

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

@tanstack/solid-table

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

@tanstack/solid-table-devtools

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

@tanstack/svelte-table

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

@tanstack/table-core

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

@tanstack/table-devtools

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

@tanstack/vue-table

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

commit: fea472d

getState: () => table.state,
}) as LegacyReactTable<TData>,
[table, state],
[table],
Copy link
Member

Choose a reason for hiding this comment

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

I'm trying to remember why I even did had a dedicated useStore call here, I think it might have had something to do with the react compiler. I'm fine shipping this though

Copy link
Collaborator Author

@riccardoperra riccardoperra Mar 12, 2026

Choose a reason for hiding this comment

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

mmh could it be because previously there were some updates done in useEffect with queueMicrotask to update the baseStore? That's something we removed after state store updates automatically when options changes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Anyway, I just tested the useLegacyTable example with this configuration and it seems working the same

 react({
      babel: {
        plugins: ['babel-plugin-react-compiler'],
      },
    }),

props: SubscribeProps<TFeatures, TData, TSelected>,
): ReturnType<FunctionComponent> {
const selected = useStore(props.table.store, props.selector)
const selected = useStore(props.table.store, props.selector, shallow)
Copy link
Member

Choose a reason for hiding this comment

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

thanks, this was needed.

Copy link
Contributor

@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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/react-table/src/useLegacyTable.ts`:
- Around line 18-19: The file imports unused symbols—remove the unused imports
useCallback, shallow, and useStore from the import lines in useLegacyTable.ts;
specifically delete useCallback from the 'react' import and remove shallow and
useStore from the '@tanstack/react-store' import so only actually used exports
remain, then run a quick lint/type-check to confirm no references remain.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e7b5b707-7ade-4df7-9d6c-dad090172eed

📥 Commits

Reviewing files that changed from the base of the PR and between 34df449 and 00feb71.

📒 Files selected for processing (2)
  • packages/react-table/src/Subscribe.ts
  • packages/react-table/src/useLegacyTable.ts

Comment on lines +18 to +19
import { useCallback, useMemo } from 'react'
import { shallow, useStore } from '@tanstack/react-store'
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion | 🟠 Major

Remove unused imports.

useCallback, shallow, and useStore are imported but not used in this file. These appear to be leftovers from the refactoring.

🧹 Proposed fix to remove unused imports
-import { useCallback, useMemo } from 'react'
-import { shallow, useStore } from '@tanstack/react-store'
+import { useMemo } from 'react'
📝 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
import { useCallback, useMemo } from 'react'
import { shallow, useStore } from '@tanstack/react-store'
import { useMemo } from 'react'
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/react-table/src/useLegacyTable.ts` around lines 18 - 19, The file
imports unused symbols—remove the unused imports useCallback, shallow, and
useStore from the import lines in useLegacyTable.ts; specifically delete
useCallback from the 'react' import and remove shallow and useStore from the
'@tanstack/react-store' import so only actually used exports remain, then run a
quick lint/type-check to confirm no references remain.

@KevinVandy KevinVandy merged commit 114e45d into alpha Mar 12, 2026
4 checks passed
@KevinVandy KevinVandy deleted the fix/react-use-legacy-table-infinite-rerender branch March 12, 2026 18:21
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