I'm trying to update a state using server$ for the first time the user visits the website, but it is saying that the signal is readonly and can't be updated
my code:
const syncState = server$(async function (state) {
const sessionId = this.cookie.get("session-id");
if (!sessionId) return;
const storedValue = await redisClient.get(`session:${sessionId.value}`);
if (storedValue) {
Object.assign(state, JSON.parse(storedValue));
}
});
const state = useStore<PresentationStore["state"]>(() => ({
id: "0",
}));
syncState(state)
throws:
/home/patrickkmatias/repos/shaliah/node_modules/@qwik.dev/core/dist/core.mjs:1128
target[prop] = value;
^
TypeError: Cannot assign to read only property 'id' of object '#<Object>'
at setNewValueAndTriggerEffects (/home/patrickkmatias/repos/shaliah/node_modules/@qwik.dev/core/dist/core.mjs:1128:16)
at StoreHandler.set (/home/patrickkmatias/repos/shaliah/node_modules/@qwik.dev/core/dist/core.mjs:1065:9)
at Function.assign (<anonymous>)
at Object.eval (/home/patrickkmatias/repos/shaliah/src/contexts/PresentationContext.tsx:23:29)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async Object.qrl2 (/home/patrickkmatias/repos/shaliah/node_modules/@qwik.dev/core/dist/core.mjs:7913:20)
at async qrl2 (/home/patrickkmatias/repos/shaliah/node_modules/@qwik.dev/core/dist/core.mjs:7913:20)
Node.js v22.14.0
it happens even with a plain object, without being a signal.