From dc8ee132ff21e26e8253a148534ac045b079ba9b Mon Sep 17 00:00:00 2001 From: rxliuli Date: Sat, 7 Dec 2024 05:54:58 +0800 Subject: [PATCH] fix: fix Proxy issue when using svelte5 and immer together --- src/lib/stores/__tests__/converstation.test.ts | 2 ++ src/lib/stores/converstation.svelte.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/stores/__tests__/converstation.test.ts b/src/lib/stores/__tests__/converstation.test.ts index 2b8e3cd..91df69a 100644 --- a/src/lib/stores/__tests__/converstation.test.ts +++ b/src/lib/stores/__tests__/converstation.test.ts @@ -188,6 +188,7 @@ it('send message in old conversation', async () => { createdAt: new Date().toISOString(), updatedAt: new Date().toISOString(), }) + await new Promise((resolve) => setTimeout(resolve, 10)) await convStore.create('chat-2', 'gpt-4o', { id: '3', content: 'Request', @@ -202,6 +203,7 @@ it('send message in old conversation', async () => { createdAt: new Date().toISOString(), updatedAt: new Date().toISOString(), }) + await new Promise((resolve) => setTimeout(resolve, 10)) expect(get(sidebars).map((it) => it.id)).toEqual(['chat-2', 'chat-1']) // send message in old conversation await convStore.addMessage('chat-1', { diff --git a/src/lib/stores/converstation.svelte.ts b/src/lib/stores/converstation.svelte.ts index 7c78bf0..9c9e1b3 100644 --- a/src/lib/stores/converstation.svelte.ts +++ b/src/lib/stores/converstation.svelte.ts @@ -90,7 +90,7 @@ export const convStore = { if (!conversation) { return } - conversation.messages.push(message) + conversation.messages.push($state.snapshot(message)) conversation.updatedAt = new Date().toISOString() }), )