Repository navigation
fix(companion): 冷启动后打开「她的设定」不再用默认值覆盖人设 - #2061
Closed
xxxxdx040716 wants to merge 1 commit into
Closed
xxxxdx040716 wants to merge 1 commit into
xxxxdx040716 wants to merge 1 commit into
Conversation
人设和名字存在 SharedPreferences(companion_persona_v1 / companion_name), CompanionPersonaController / CompanionNameSetting 的 build() 先返回空值, 再在后台异步读取。 「她的设定」页在 initState 里同步读 provider,退出时 dispose 又无条件把 字段写回:冷启动后第一次打开这一页时,读到的还是空值,页面显示默认人设, 退出那一刻就把保存的 custom 和「称呼」写成了默认值(名字通常能保住, 因为名字读取更早)。 另外完整模式的发送路径(companion_agent_full_session.dart 的 prepare) 也同步读 provider,冷启动后第一条消息可能带着默认人设发出去。 改动: - CompanionNameSetting 增加 ready future(与 CompanionPersonaController 一致); - 设定页等两个 provider ready 之后再填字段,加载中显示转圈;初始化没完成 就退出时不写回; - 完整模式 prepare 先等 ready 再构建 profile。
|
Hi @xxxxdx040716,感谢关注 dsh-Go。 dsh-Go 目前不接受任何外部 Pull Request(代码、文档、配置、模板都不接收),所以这个 PR 会被自动关闭。 有功能建议、改进想法或 bug 反馈,请开 issue:https://github.com/ccch1mneyyy/dsh-Go/issues/new/choose 维护者明确需要这份实现时会手动 reopen;其他人 reopen 会被再次关闭。 政策见 https://github.com/ccch1mneyyy/dsh-Go/blob/main/CONTRIBUTING.md 与 https://github.com/ccch1mneyyy/dsh-Go/blob/main/AGENTS.md |
|
Caution Review failedThe pull request is closed.
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. |
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.
现象
关闭 App 后重新进入伙伴小屋,第一次打开「她的设定」时,之前保存的自定义人设和「称呼」会被默认人设覆盖(名字通常还在)。1.3.0 可稳定复现;1.4.0 的同一个页面代码没有变化,1.4.0 因为进小屋会先读一次设定,触发概率变低,但代码层面的时序问题还在。
复现
原因
companion_persona_v1/companion_name),CompanionPersonaController/CompanionNameSetting的build()先返回空值,再在后台异步_load()。CompanionPersonaPage.initState同步ref.read(...):冷启动后 provider 还没读完时拿到空值,页面按默认人设显示。dispose无条件把字段写回(_write),默认值于是覆盖了保存的custom和callMe。companion_agent_full_session.dart的prepare()也同步读取,冷启动后第一条消息可能带着默认人设发出(下一条恢复)。改动
CompanionNameSetting增加ready(与CompanionPersonaController一致),调用方可以等名字读完。ready之后再填字段,加载中显示转圈;初始化没完成就退出时不写回。prepare()先等ready再构建 profile。测试
本机没有 Flutter/Dart SDK,未编译、未跑
flutter analyze/flutter test,只确认补丁能干净应用到当前 main(5ebbfd7)。合并前建议先跑flutter analyze与flutter test app/test/companion;需要的话我可以补一条冷启动回归测试(打开设定页不作修改直接退出,companion_persona_v1不应变化)。