[priority: 4] discipline-slice.ts mutates nested element objects directly — bypasses Zustand reactivity #70
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Severity: 4 — High
File:
src/lib/game/stores/discipline-slice.ts, line 97Description:
In
processTick(), theelementsobject is shallow-copied, but nested element objects are still references to the originals:This mutation happens outside of Zustand, meaning state changes are invisible to React subscribers and won't trigger re-renders until the next
set()call.Fix: Clone each element before mutation:
Starting work on Issue 70: discipline-slice.ts mutates nested element objects directly, bypassing Zustand reactivity. The shallow copy on line 97 (
const elements = { ...mana.elements }) doesn't clone nested objects, soelements[def.manaType].current -= drainmutates the original state. Fix: clone each element before mutation.Fixed: Replaced direct nested object mutation
elements[def.manaType].current -= drainwith immutable spread patternelements[def.manaType] = { ...elements[def.manaType], current: elements[def.manaType].current - drain }. Also added a safety checkelse if (elements[def.manaType])before accessing the nested property.