Repository navigation
fix: 命令处理器在执行时读 props,不用组合期捕获的值 - #53
Conversation
命令在它那批 flush 提交后送达,但早于这批引起的重组:处理器若闭包了组合期读到的值,
同一批里改 prop 又发命令时就用了旧值。TextField.setText 的裁剪上限、CodeField.setText
的位数改为处理器里现读 scope.get。components.md §4 与 Commands 的 KDoc 写明这条规则。
新增 iOS 模拟器上的组合级测试(compose.uiTest,只加在 iosTest):同一批把上限 4 提到 10
并 setText("123456"),旧代码两条都裁成 1234。
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
Sorry @HarlonWang, you've used your own review budget of 250,000 diff characters for the last 7 days. You can request another review in 3 days and 20 hours by commenting |
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
Reviewer's Guide本 PR 修复命令处理器捕获组合期 props 导致的陈旧值问题:TextField 和 CodeField 在命令执行时通过 NodeScope.get 读取最新限制,并以 iOS Compose UI 测试覆盖同一 flush 中的 prop 更新与 setText 场景,同时补充时序契约文档。 Sequence diagram for live props during command executionsequenceDiagram
participant Flush
participant NodeScope
participant Handler
participant Recomposition
Flush->>NodeScope: apply prop update
Flush->>NodeScope: enqueue setText command
NodeScope->>Handler: Commands consumes command
Handler->>NodeScope: get(maxLength or length)
NodeScope-->>Handler: latest committed prop
Handler->>Handler: clip or update text
Handler-->>NodeScope: dispatch onChange
NodeScope->>Recomposition: schedule recomposition
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
CodeSeer 审查
结论:批准
摘要
本次改动将 TextField 和 CodeField 的命令处理逻辑改为在执行时通过 scope.get 读取限制值,避免同一批 flush 更新 props 后仍使用上次组合期捕获值。新增的 iOS Compose UI 测试覆盖了两个受影响的 setText 场景,并补充了命令处理器的使用约束文档。基于给出的代码,未发现本次增量引入的可确认问题。
整个 PR 至 438ae85 · gpt-5.6-terra
问题
Sourcery 在 #52 上指出的老问题,与 #52 的改动无关:
NodeScope.Commands的处理器闭包里用的是组合期读到的 prop 值(TextField的maxLength、CodeField的length)。命令在它那批 flush 提交后送达,但早于这批引起的重组,所以同一批里既改了这个 prop 又发了用到它的命令时,处理器拿到的是上一次组合的值:maxLength4 改 10 并setText("123456"),结果裁成1234,onChange也报1234CodeField把length改大再setText,同理修复
处理器在执行时读
scope.get,不捕获组合期的值。scope.get读的是节点 props 这个快照状态,主线程在快照外读到的就是最新提交值,#52 已保证命令晚于提交。只改TextField.clip与CodeField.update两处;LazyColumn.scrollTo本来就现读children.size。规则写进
docs/components.md§4 和Commands的 KDoc:自定义组件的处理器照此办。验证
CommandPropsTest(iosTest,compose.uiTest只加在这个 source set,Android host 测试没有窗口):两条用例各在一批里改上限并setText,断言onChange报完整的123456。对着改动前的Builtins.kt跑,两条都失败,报1234。:compose:testAndroidHostTest、:compose:apiCheck、:compose:iosSimulatorArm64Test、:sample:shared:testAndroidHostTest、:sample:androidApp:assembleDebug全部通过。公开 API 无变化。🤖 Generated with Claude Code
Summary by Sourcery
Fix command handlers to use current props when processing commands that arrive before recomposition.
Bug Fixes:
Enhancements:
Build:
Documentation:
Tests: