From 680670336322d57fa824e38045034dc8caed2529 Mon Sep 17 00:00:00 2001 From: LyAhn Date: Sat, 4 Jul 2026 12:11:00 +0100 Subject: [PATCH] fix(dev): clone mock IPC results to match real invoke semantics Mock handlers return references straight into the in-memory db (e.g. `return db.albums`), so store updates like set({ albums }) kept the same array identity across loads and Zustand never notified subscribers -- the sidebar album list froze after creating an album from the bulk bar. Real invoke() deserializes fresh JSON per call, so production was never affected. structuredClone in the shim restores that fidelity for every mock command at once. --- src/dev/setupMockTauri.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/dev/setupMockTauri.ts b/src/dev/setupMockTauri.ts index c566de0..8525c74 100644 --- a/src/dev/setupMockTauri.ts +++ b/src/dev/setupMockTauri.ts @@ -4,8 +4,19 @@ import { handleMockCommand } from "./mockBackend"; mockWindows("main"); mockConvertFileSrc("windows"); -mockIPC((cmd, payload) => handleMockCommand(cmd, payload), { - shouldMockEvents: true, -}); +mockIPC( + async (cmd, payload) => { + const result = await handleMockCommand(cmd, payload); + // Real invoke() deserializes fresh JSON on every call, so callers never + // share references into backend state and Zustand identity checks see + // every change. Clone here so the mock behaves the same — returning + // `db.albums` directly froze the sidebar because set({ albums }) kept + // the same array identity across loads. + return structuredClone(result); + }, + { + shouldMockEvents: true, + }, +); console.info("[Phokus UI Lab] Mock Tauri backend installed.");