Skip to content

fix(state): 将 stateKey 作为 GenuiBlock 状态身份 - #76

Merged
wang-kaopu merged 4 commits into
omdsh-dev:mainfrom
wang-kaopu:fix/genui-state-key
Aug 28, 2026
Merged

fix(state): 将 stateKey 作为 GenuiBlock 状态身份#76
wang-kaopu merged 4 commits into
omdsh-dev:mainfrom
wang-kaopu:fix/genui-state-key

Conversation

@wang-kaopu

Copy link
Copy Markdown
Collaborator

问题

GenuiBlock 的 durable state 只在 mount 时根据 stateKey 初始化。

如果同一个 mounted instance 从 stateKey=A 更新成 stateKey=B

  • A 的内存状态仍然保留;
  • 后续 persistence effect 却已经使用 B;
  • 旧状态可能因此被写入新的 durable key。

让每个调用方都手动同时传 key={stateKey} 可以绕开问题,但会把状态身份 invariant 泄漏给所有 surface。

修复

把状态身份约束收回 GenuiBlock

  • 外层 GenuiBlock 根据 durable stateKey 为内部 stateful instance 设置 React key;
  • stateKey 改变时,内部 instance 自动 remount 并重新加载对应 durable state;
  • stateKey === undefined 时使用稳定的 volatile identity,保证流式 spec 更新不会因为内容变化不断 remount。

因此调用方只需要传 stateKey,无需额外维护 React key

测试

新增行为级回归测试:

  • state-a 的持久状态不会泄漏并写入 state-b
  • 从 B 切回 A 可以恢复 A 自己的 durable state;
  • stateKey 的 streaming spec 增长时,正在输入的本地状态继续保留。

验证

提交 PR 前已执行:

  • pnpm run check
  • 同步提交重新构建的 lib/ 产物

@wang-kaopu
wang-kaopu force-pushed the fix/genui-state-key branch from 65d0c98 to 125f0de Compare August 28, 2026 13:18
@wang-kaopu
wang-kaopu merged commit 42d1da2 into omdsh-dev:main Aug 28, 2026
2 checks passed
@wang-kaopu
wang-kaopu deleted the fix/genui-state-key branch August 28, 2026 13:19
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.

1 participant