"Sign All Pacts" ignores max pacts limit — stale closure bug #251
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?
Steps to reproduce:
Expected: Only signs up to
maxPacts(base 1, increased bypactCapacityprestige upgrade)Actual: Signs ALL 49 pacts regardless of max pacts limit. Shows "Signed Pacts: 49 | Max Pacts: 1"
Root cause: In
PactDebugSection.tsx, thesignAllPactsfunction iterates over all guardian floors and callsforcePact(floor)for each. TheforcePactfunction checkssignedPacts.length >= maxPacts, butsignedPactsis captured from the component's state at render time via closure. Since React hasn't re-rendered between iterations,signedPacts.lengthalways sees the initial value (0), so the check never triggers.Fix: In
signAllPacts, either:signedPacts.lengthfrom the store directly (usePrestigeStore.getState().signedPacts.length) inside the loopAffected file:
src/components/game/tabs/DebugTab/PactDebugSection.tsx(thesignAllPactsfunction, lines ~115-121)Store:
usePrestigeStore(signedPacts, addSignedPact)Starting fix. The stale closure bug is in signAllPacts — it reads signedPacts.length from the render-time closure, which is always 0 during the loop. Fix: read from store.getState() inside the loop.
Fixed stale closure bug in PactDebugSection.tsx. Both
forcePactandsignAllPactsnow readsignedPactsdirectly fromusePrestigeStore.getState()instead of using the render-time closure value. This ensures themaxPactscheck works correctly when signing multiple pacts in a loop. All 43 DebugTab tests pass.