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.
This commit is contained in:
sebastian.goendoer committed 2026-09-03 21:40:11 +02:00
1 parent 272bf785ee
commit e57eac027f
1 file changed
+9 -2
+9 -2
View File
@@ -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.