fix: 闪退真凶——装载历史缓存后 transInflight 为 nil

crash.log 实锤:panic: assignment to entry in nil map,
docTranslation(hover 渲染帧内)。

合并判空是错的:loadTranslations 只装 a.trans,缓存有数据后
a.trans 永远非 nil,跳过了 transInflight 初始化——hover 一个
未缓存符号就往 nil map 写,主线程渲染帧直接炸。两次崩溃同因。

修复:两个 map 分别判空;loadTranslations 同时初始化两个。
回归测试:TestDocTranslationNilInflightWithLoadedCache。
This commit is contained in:
zerorigin committed 2026-11-04 17:40:04 +08:00
1 parent 665efb6027
commit e7de0bd93a
2 files changed
+28

No files matched your search

+6
View File
@@ -36,8 +36,13 @@ func (a *App) docTranslation(text string) string {
if a.transInflight[key] {
return text
}
// 两个 map 分别判空:loadTranslations 只装 a.trans(有历史缓存时它
// 非 nil),transInflight 仍是 nil——之前合并判空导致往 nil map 写,
// 渲染帧里直接 panic 闪退(crash.log 实锤)。
if a.trans == nil {
a.trans = map[string]string{}
}
if a.transInflight == nil {
a.transInflight = map[string]bool{}
}
a.transInflight[key] = true
@@ -98,6 +103,7 @@ func (a *App) loadTranslations() {
return
}
a.trans = map[string]string{}
a.transInflight = map[string]bool{}
for k, v := range m {
if k != "" && v != "" {
// 旧版缓存 key 是原文,统一规范化,能被预热与懒翻译共同命中。