[Critical] [Bug] unlockAttunement crashes with ReferenceError — 'state' is undefined #354
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: Critical
File:
src/lib/game/stores/attunementStore.ts(lines 82-83)Description:
Inside the
unlockAttunementfunction (line 79), the code referencesstate.attunements[attunementId]?.activeon line 82, butstateis not a parameter of theunlockAttunementfunction. The function signature isunlockAttunement(attunementId, defeatedGuardians)— there is nostatevariable in scope.The
set()call on line 93 usessas its parameter name, but theunlockAttunementfunction 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 definedat 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 theset()callback.Starting investigation of unlockAttunement ReferenceError. Reading source files now.
Fix applied. The
unlockAttunementfunction was referencingstate.attunements[attunementId]?.activebutstatewas 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]?.activetoconst currentState = _get(); if (currentState.attunements[attunementId]?.active) return false;All 1141 tests pass.
Review complete — fix verified.
The
unlockAttunementfunction now correctly uses_get()to read current state instead of referencing an undefinedstatevariable. The fix is minimal and correct.bug-354-unlock-attunement.test.ts: 7/7 tests passNo remaining issues.