fix: discipline-slice.ts directly mutates state outside of set() #26

Closed
opened 2026-05-18 15:56:06 +02:00 by Anexim · 2 comments
Owner

Severity: Critical

File: src/lib/game/stores/discipline-slice.ts (line 94)

Problem: In processTick, the line disc.paused = true; mutates the discipline state object directly on the current state, bypassing Zustand's state management. This happens inside get() but outside of set().

Impact: Zustand won't detect the change, won't trigger re-renders, and the mutation may be lost or cause inconsistent state. The paused flag may not persist correctly.

Fix: Build a new disciplines map with the paused discipline replaced immutably, then include it in the set() call at the end of processTick:

const newDisciplines = { ...s.disciplines };
// ... inside the loop:
if (!available || available < drain) {
  newDisciplines[id] = { ...disc, paused: true };
  continue;
}
// ... use newDisciplines in the final set()
**Severity:** Critical **File:** `src/lib/game/stores/discipline-slice.ts` (line 94) **Problem:** In `processTick`, the line `disc.paused = true;` mutates the discipline state object **directly** on the current state, bypassing Zustand's state management. This happens inside `get()` but outside of `set()`. **Impact:** Zustand won't detect the change, won't trigger re-renders, and the mutation may be lost or cause inconsistent state. The `paused` flag may not persist correctly. **Fix:** Build a new `disciplines` map with the paused discipline replaced immutably, then include it in the `set()` call at the end of `processTick`: ```ts const newDisciplines = { ...s.disciplines }; // ... inside the loop: if (!available || available < drain) { newDisciplines[id] = { ...disc, paused: true }; continue; } // ... use newDisciplines in the final set() ```
Anexim added the ai:todo label 2026-05-18 15:56:06 +02:00
n8n-gitea was assigned by Anexim 2026-05-18 15:56:06 +02:00
Author
Owner

Starting work on discipline-slice.ts directly mutates state outside set()

Starting work on discipline-slice.ts directly mutates state outside set()
Author
Owner

Fixed: Replaced direct mutation disc.paused = true with immutable newDisciplines[id] = { ...disc, paused: true } in discipline-slice.ts processTick

Fixed: Replaced direct mutation `disc.paused = true` with immutable `newDisciplines[id] = { ...disc, paused: true }` in discipline-slice.ts processTick
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Anexim/Mana-Loop#26