fix(state): 将 stateKey 作为 GenuiBlock 状态身份 - #76
Merged
Conversation
wang-kaopu
force-pushed
the
fix/genui-state-key
branch
from
August 28, 2026 13:18
65d0c98 to
125f0de
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
GenuiBlock的 durable state 只在 mount 时根据stateKey初始化。如果同一个 mounted instance 从
stateKey=A更新成stateKey=B:让每个调用方都手动同时传
key={stateKey}可以绕开问题,但会把状态身份 invariant 泄漏给所有 surface。修复
把状态身份约束收回
GenuiBlock:GenuiBlock根据 durablestateKey为内部 stateful instance 设置 React key;stateKey改变时,内部 instance 自动 remount 并重新加载对应 durable state;stateKey === undefined时使用稳定的 volatile identity,保证流式 spec 更新不会因为内容变化不断 remount。因此调用方只需要传
stateKey,无需额外维护 Reactkey。测试
新增行为级回归测试:
state-a的持久状态不会泄漏并写入state-b;stateKey的 streaming spec 增长时,正在输入的本地状态继续保留。验证
提交 PR 前已执行:
pnpm run checklib/产物