svelte-table: controlled expanded and pagination state resets straight after every change

未关闭
#6,640 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@NickSpag 已经在做这个了。

开始于 2026年10月22日。

  • #6641 来自 @NickSpag —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
typescript
领域
frontend

调研方向

Read the Svelte adapter’s options store in packages/svelte-table/src/reactivity.svelte.ts and the options sync effect in packages/svelte-table/src/createTable.svelte.ts, then trace how packages/table-core/src/core/row-models/createCoreRowModel.ts memoizes data and triggers auto-resets. Reproduce with the linked standalone example and check controlled expansion, pagination, and row.original identity. Done means controlled state persists across changes and unchanged caller data retains its identity.

由索引模型根据 Issue 内容生成。

描述

TanStack Table version

svelte-table 9.3.1 (and table-core 9.3.1). First seen on 9.2.4.

Framework/Library version

svelte 5.57.0

Describe the bug and the steps to reproduce it

When expanded or pagination is controlled through state and on*Change, and with a plain array (constant/$derived value/TanStack Query result) for data, row.toggleExpanded() and table.nextPage() dont do anything. The table applies the change and then resets the slice to its initial value, on every click. With data held in $state the bug doesn't show, because Svelte keeps the existing proxy.

The Svelte adapter's options store is a deep $state (reactivity.svelte.ts#L35). On each options sync, the $effect.pre in createTable (createTable.svelte.ts#L87-L102) writes a new options object that holds the caller's raw data array, and $state wraps that array in a new proxy each time. So table.options.data gets a new identity on every sync, even though data itself hasn't changed. The core row model memoizes on table.options.data and runs the auto-resets whenever it recomputes (createCoreRowModel.ts#L31-L38). Changing a controlled slice re-runs the sync, so every change undoes itself.

#6374 is this bug for pagination. It was closed with autoResetPageIndex: false as the workaround; autoResetExpanded: false works the same way for expansion. Both also turn off the reset for genuine data changes. The same proxying means row.original is a Svelte proxy, not the object the caller passed in.

The three tests in the standalone repro fail on 9.2.4, 9.2.6 and 9.3.1 every run:
https://github.com/NickSpag/svelte-table-controlled-state-repro

Steps:

  1. Render ControlledExpanded.svelte.
  2. Click "Ada: closed". It stays closed: onExpandedChange receives { "0": true }, then {} from table_resetExpanded.
  3. "same data" renders false.
Your Minimal, Reproducible Example - (Sandbox Highly Recommended)

https://stackblitz.com/github/NickSpag/svelte-table-controlled-state-repro

Screenshots or Videos (Optional)

No response

Do you intend to try to help solve this bug with your own PR?

Yes, I am also opening a PR that solves the problem along side this issue

Terms & Code of Conduct
  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
主要语言
TypeScript
星标
28.5k
派生
3.6k
平均合并
18 小时 5 分钟
30 天内合并 PR
12

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

TanStack/table 的其他 Issue

查看 TanStack/table 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。