[Critical] [Bug] unlockAttunement crashes with ReferenceError — 'state' is undefined #354

Closed
opened 2026-06-10 19:23:33 +02:00 by Anexim · 3 comments
Owner

Severity: Critical
File: src/lib/game/stores/attunementStore.ts (lines 82-83)

Description:
Inside the unlockAttunement function (line 79), the code references state.attunements[attunementId]?.active on line 82, but state is not a parameter of the unlockAttunement function. The function signature is unlockAttunement(attunementId, defeatedGuardians) — there is no state variable in scope.

The set() call on line 93 uses s as its parameter name, but the unlockAttunement function is a standalone helper that doesn't have access to that scope.

Impact: Crash — attempting to unlock the Invoker attunement (or any attunement) throws a ReferenceError: state is not defined at runtime. This makes the Invoker attunement permanently inaccessible through normal gameplay.

Fix needed: The function should use useAttunementStore.getState() to read the current state, or the function should be rewritten to work within the set() callback.

**Severity:** Critical **File:** `src/lib/game/stores/attunementStore.ts` (lines 82-83) **Description:** Inside the `unlockAttunement` function (line 79), the code references `state.attunements[attunementId]?.active` on line 82, but `state` is not a parameter of the `unlockAttunement` function. The function signature is `unlockAttunement(attunementId, defeatedGuardians)` — there is no `state` variable in scope. The `set()` call on line 93 uses `s` as its parameter name, but the `unlockAttunement` function is a standalone helper that doesn't have access to that scope. **Impact:** Crash — attempting to unlock the Invoker attunement (or any attunement) throws a `ReferenceError: state is not defined` at runtime. This makes the Invoker attunement permanently inaccessible through normal gameplay. **Fix needed:** The function should use `useAttunementStore.getState()` to read the current state, or the function should be rewritten to work within the `set()` callback.
Anexim added the ai:todo label 2026-06-10 19:23:33 +02:00
n8n-gitea was assigned by Anexim 2026-06-10 19:23:33 +02:00
Anexim added ai:in-progress and removed ai:todo labels 2026-06-10 20:24:35 +02:00
Author
Owner

Starting investigation of unlockAttunement ReferenceError. Reading source files now.

Starting investigation of unlockAttunement ReferenceError. Reading source files now.
Anexim added ai:review and removed ai:in-progress labels 2026-06-10 20:41:37 +02:00
Author
Owner

Fix applied. The unlockAttunement function was referencing state.attunements[attunementId]?.active but state was not in scope — the function signature only receives (attunementId, defeatedGuardians).

Root cause: The function is a standalone action (not a set() callback), so it needs to use _get() to read current state.

Fix: Changed line 82 from state.attunements[attunementId]?.active to const currentState = _get(); if (currentState.attunements[attunementId]?.active) return false;

All 1141 tests pass.

**Fix applied.** The `unlockAttunement` function was referencing `state.attunements[attunementId]?.active` but `state` was not in scope — the function signature only receives `(attunementId, defeatedGuardians)`. **Root cause:** The function is a standalone action (not a `set()` callback), so it needs to use `_get()` to read current state. **Fix:** Changed line 82 from `state.attunements[attunementId]?.active` to `const currentState = _get(); if (currentState.attunements[attunementId]?.active) return false;` All 1141 tests pass.
Anexim added ai:done and removed ai:review labels 2026-06-11 12:37:51 +02:00
Author
Owner

Review complete — fix verified.

The unlockAttunement function now correctly uses _get() to read current state instead of referencing an undefined state variable. The fix is minimal and correct.

  • Regression test bug-354-unlock-attunement.test.ts: 7/7 tests pass
  • Full suite: 68 files, 1158 tests — all green

No remaining issues.

**Review complete — fix verified.** The `unlockAttunement` function now correctly uses `_get()` to read current state instead of referencing an undefined `state` variable. The fix is minimal and correct. - Regression test `bug-354-unlock-attunement.test.ts`: 7/7 tests pass - Full suite: 68 files, 1158 tests — all green No remaining issues.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Anexim/Mana-Loop#354