🐛 fix(im): conversation.messages 入 IDB 前用 toRaw 解 Proxy,否则 structuredClone 抛 DataCloneError 静默丢消息

im
YunaiV 2026-04-26 17:57:50 +08:00
parent f1d44c8267
commit 9a4e79e4ef
1 changed files with 4 additions and 1 deletions

View File

@ -1,4 +1,5 @@
import { defineStore } from 'pinia'
import { toRaw } from 'vue'
import { store } from '@/store'
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
@ -168,10 +169,12 @@ export const useConversationStore = defineStore('imConversationStore', {
Array.isArray(target) ? target : target ? [target] : []
).filter((c) => !c.deleted)
for (const conversation of conversationsToFlush) {
// toRaw 拆掉 Vue reactive ProxyIDB 的 structuredClone 不接受 Proxy
// 不拆会抛 DataCloneError 静默落盘失败(只 meta 写得进去messages 永远丢)
tasks.push(
imStorage.setItem(
StorageKeys.conversationMessage(userId, conversation.type, conversation.targetId),
conversation.messages
toRaw(conversation.messages)
)
)
}