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.
This commit is contained in:
@@ -4,8 +4,19 @@ import { handleMockCommand } from "./mockBackend";
|
|||||||
mockWindows("main");
|
mockWindows("main");
|
||||||
mockConvertFileSrc("windows");
|
mockConvertFileSrc("windows");
|
||||||
|
|
||||||
mockIPC((cmd, payload) => handleMockCommand(cmd, payload), {
|
mockIPC(
|
||||||
shouldMockEvents: true,
|
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.");
|
console.info("[Phokus UI Lab] Mock Tauri backend installed.");
|
||||||
|
|||||||
Reference in New Issue
Block a user