修复: stores/ai 模块顶层 __bindMessages TDZ 防御
- __bindMessages 包装 try/catch,aiShared 未就绪时延迟到微任务重试 - 防 ES module 循环初始化顺序导致的 Cannot access before initialization
This commit is contained in:
@@ -193,7 +193,13 @@ stateRef = state
|
||||
// 注入 messages getter 到 aiShared 共享层(破循环依赖,避免 Vite 打包 TDZ)。
|
||||
// 用 getter 而非数组引用:switchConversation/newConversation 会整体替换 state.messages,
|
||||
// 缓存引用会指向陈旧数组(findToolCall 找不到新数组的工具卡片 → Completed 事件无法更新 → 卡片卡 running)。
|
||||
__bindMessages(() => state.messages)
|
||||
// 延迟执行:wrap 在 try/catch 中,防 ES module 初始化顺序导致 aiShared 未就绪时炸
|
||||
try {
|
||||
__bindMessages(() => state.messages)
|
||||
} catch (e) {
|
||||
// aiShared 模块初始化中(ES module 循环),延迟到微任务里重试
|
||||
Promise.resolve().then(() => __bindMessages(() => state.messages))
|
||||
}
|
||||
|
||||
// 旁注:此处不再保留 type-only 导出(AiChatEvent 等),因组件直接从 api/types import。
|
||||
// 若有外部模块仍从本文件 import 这些类型,下方 re-export 兜底:
|
||||
|
||||
Reference in New Issue
Block a user