From e57eac027fd874b9fc17cbdd5f5a03101dddc347 Mon Sep 17 00:00:00 2001 From: "sebastian.goendoer" Date: Thu, 3 Sep 2026 21:40:11 +0200 Subject: [PATCH] fix: read fresh store value in set-stepper bump to prevent stale closure in supersets In a superset both ExerciseBlock instances subscribe to the same store slice. When one member's field is updated the store clone invalidates all entry references, causing both instances to re-render. The +/- button handlers were closing over the set object from the previous render, so the first tap wrote the correct value but the replacement closure made the next tap operate on stale data -- requiring two taps per visible increment instead of one. Fix: read the current field value directly from the store at call time instead of relying on the render-time snapshot. --- frontend/src/views/Workout.jsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx index a71bfc0..7206b16 100644 --- a/frontend/src/views/Workout.jsx +++ b/frontend/src/views/Workout.jsx @@ -139,8 +139,15 @@ function ExerciseBlock({ entryIdx, compact, onToggle, onField, onAddSet, onRemov // The effort column walks its own scale — see stepEffort. Weight and reps step up from 0 // with no ceiling, as they always did. const bump = (s, i, col, dir) => { - if (col.eff) return onField(i, col.f, stepEffort(col.eff, s[col.f], dir)) - onField(i, col.f, Math.max(0, Math.round(((s[col.f] || 0) + dir * col.step) * 100) / 100)) + // Read the current value directly from the store rather than from the render-time snapshot. + // In a superset both ExerciseBlock instances share the same store subscription, so when one + // member's field changes the partner re-renders too, replacing the closure's `s` reference + // with a fresh clone before the next tap fires. Reading from the store avoids that stale- + // closure problem entirely and keeps every tap operating on the real current value. + const fresh = useStore.getState().S.active?.entries[entryIdx]?.sets[i] + const cur = fresh ? fresh[col.f] : s[col.f] + if (col.eff) return onField(i, col.f, stepEffort(col.eff, cur, dir)) + onField(i, col.f, Math.max(0, Math.round(((cur || 0) + dir * col.step) * 100) / 100)) } // Uses the shared stepper markup so a set row picks up the same control styling // as every other +/- field in the app.