Skip to content
Source
Sign inSign up
TanStack/table

fix(react-table, preact-table): refresh AppTable context under cached elements #6631

Mergedgorkemkaramolla(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/6631/headmerged by KevinVandy

🎯 Changes

Fixes the createTableHook part of #6601.

useAppTable creates AppTable once and reads the table from a ref. When the parent's output is cached (React Compiler, useMemo, memo), React skips <table.AppTable>, so the context keeps an old table and useTableContext() shows stale rows after data changes. Since no table state changed, Subscribe doesn't catch it either.

Now AppTable listens for the owner's commits and re-renders only when its table is outdated. Normal (uncached) renders don't get any extra render.

  • react-table: uses useSyncExternalStore
  • preact-table: same idea with a layout effect, since Preact has no useSyncExternalStore
  • Added tests for both (cached and uncached). The cached one fails on main.
  • Added a short note to the React Compiler guide.

This doesn't cover components that get table as a prop outside AppTable. I'll ask about that on the issue.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with pnpm test and pnpm test:e2e, or these tests do not apply to this pull request.
  • I fully understand the code in this pull request, including any code generated with AI assistance.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes
    • Table context now refreshes when data changes, including when the table component is cached, so consumers display the latest rows.
  • Documentation
    • Clarified when table consumers need data or rendered rows passed as props to update correctly.
    1. 🦋 Changeset detected

      Latest commit: 564ab96ea70af7fbb8c3b74b6eacd47f99ed2bac

      The changes in this PR will be included in the next version bump.

      This PR includes changesets to release 2 packages
      NameType
      @tanstack/react-tablePatch
      @tanstack/preact-tablePatch

      Not sure what this means? Click here to learn what changesets are.

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

    2. Review in Change Stack →

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration
      • Configuration used: Repository: TanStack/table/.coderabbit.yaml
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: 9efee5ba-83c8-41aa-9c0a-caadd8ebf45d

      📥 Commits

      Reviewing files that changed from the base of the PR and between a201e16136aae6b592fec8653032bbe8447083b5 and 564ab96ea70af7fbb8c3b74b6eacd47f99ed2bac.


      📒 Files selected for processing (4)
      • packages/preact-table/src/createTableHook.tsx
      • packages/preact-table/tests/unit/createTableHook.test.tsx
      • packages/react-table/src/createTableHook.tsx
      • packages/react-table/tests/createTableHook.test.tsx

      Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.



      📝 Walkthrough

      Walkthrough

      React and Preact AppTable now refresh context consumers when the useAppTable owner provides a different table. Tests cover cached and uncached table elements, as well as stable renders when options do not change. The React Compiler guide describes how external data replacement affects context and selectors.

      Changes

      AppTable context refresh

      Layer / File(s)Summary
      React subscription and usage guidance
      packages/react-table/src/createTableHook.tsx, packages/react-table/tests/createTableHook.test.tsx, docs/framework/react/guide/react-compiler.md, .changeset/fix-apptable-stale-context.md
      React useAppTable memoizes merged options and notifies subscribers when the table changes. AppTable reads the current table through useSyncExternalStore. Tests cover refreshed context and stable renders. The guide describes external data replacement, and the changeset records patch releases for both table packages.
      Preact listener and refresh tests
      packages/preact-table/src/createTableHook.tsx, packages/preact-table/tests/unit/createTableHook.test.tsx
      Preact useAppTable memoizes merged options and notifies listeners when the table changes. AppTable rerenders when its provided table differs from the current table. Tests cover refreshed context and stable renders.

      Priority: ⬇️ Low

      Estimated code review effort: 3 (Moderate) | ~20 minutes

      Change: Bug fix · Severity of issue fixed: Low

      Sequence Diagram(s)

      sequenceDiagram
        participant Owner as useAppTable owner
        participant AppTable
        participant Store as useSyncExternalStore
        participant Consumer as useTableContext consumer
        Owner->>AppTable: provides new table
        AppTable->>Store: notifies subscribers
        Store->>AppTable: reads current table snapshot
        AppTable->>Consumer: provides updated table context

      Suggested reviewers: kevinvandy


      Merge Risk: ⚪ Minimal · up to 564ab

      The context-refresh change is mergeable after normal checks; no actionable issue was established.

      Pre-merge checks | Passed 4 | Failed 1

      ❌ Failed checks (1 warning)

      Check nameStatusExplanationResolution
      Docstring CoverageWarningDocstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 16 functions across 4 files.Write docstrings for the functions missing them to satisfy the coverage threshold.
      ✅ Passed checks (4 passed)
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely identifies the primary change: refreshing AppTable context for cached elements in both React Table and Preact Table.
      Description checkPassedThe description explains the problem, implementation, scope, tests, documentation update, checklist, and changeset status. It matches the repository template and is sufficiently complete.
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.

      • Fix all pre-merge checks with AI
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create a new PR

      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      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.
    3. View your CI Pipeline Execution ↗ for commit 564ab96ea70af7fbb8c3b74b6eacd47f99ed2bac

      CommandStatusDurationResult
      nx affected --targets=test:eslint,test:sherif,t...✅ Succeeded4m 3sView ↗
      nx run-many --targets=build --exclude=examples/**✅ Succeeded37sView ↗

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

    4. More templates

      @tanstack/alpine-table

      npm i https://pkg.pr.new/@tanstack/alpine-table@6631

      @tanstack/angular-table

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

      @tanstack/angular-table-devtools

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

      @tanstack/ember-table

      npm i https://pkg.pr.new/@tanstack/ember-table@6631

      @tanstack/lit-table

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

      @tanstack/match-sorter-utils

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

      @tanstack/octane-table

      npm i https://pkg.pr.new/@tanstack/octane-table@6631

      @tanstack/preact-table

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

      @tanstack/preact-table-devtools

      npm i https://pkg.pr.new/@tanstack/preact-table-devtools@6631

      @tanstack/react-table

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

      @tanstack/react-table-devtools

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

      @tanstack/solid-table

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

      @tanstack/solid-table-devtools

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

      @tanstack/svelte-table

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

      @tanstack/table-core

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

      @tanstack/table-devtools

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

      @tanstack/vue-table

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

      @tanstack/vue-table-devtools

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

      commit: 564ab96

    5. KevinVandy approved these changes

    6. KevinVandy merged this3d3648f

    7. KevinVandy closed this

Sign in to join this conversation.