Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

Saving an exercise's settings mid-session without a change keeps the raise and the climb (#275)

Duarte Santosb7834ef2c8ef
diff --git a/frontend/src/lib/session-start.js b/frontend/src/lib/session-start.js
index d0a33fb28..ae725a165 100644
--- a/frontend/src/lib/session-start.js
+++ b/frontend/src/lib/session-start.js
@@ -49,6 +49,29 @@ export function buildPlannedEntry(st, cfg, routine, { noProg = false } = {}) {
return { target, plan, sets, planned: plannedOf(cfg), ...(carried ? { carried: true } : {}) }
}
+/**
+ * What an exercise's settings sheet opens with in a running session: the entry's target with the
+ * sets and reps (the range, the seconds) its routine planned put back in place of today's.
+ *
+ * The sheet edits the plan. Today's target is the prescription, and a double-progression aim, a
+ * bodyweight climb or a set the rep ceiling added has moved it off the plan. Opened at those
+ * numbers, a save that changed nothing stamped them as the plan, and the next build read that as
+ * an edit: "Plan changed", the raise undone within the session, the climb started again the next
+ * time (#275). The weight stays today's, the one on the bar. An entry built before plans were
+ * stamped has only its target.
+ */
+export function plannedConfigOf(entry) {
+ const out = { ...(entry?.target || {}) }
+ const planned = entry?.planned
+ if (!planned) return out
+ for (const key of ['sets', 'reps', 'repsMin', 'sec']) {
+ if (planned[key] != null) out[key] = planned[key]
+ // A plan with no range has no bottom to keep.
+ else if (key === 'repsMin') delete out.repsMin
+ }
+ return out
+}
+
// Returns a bare array of session entries. "Excluded from progression" is per-entry now
// (`entry.noProg`, written only when true) rather than a wrapper flag — a rehab routine merged
// into real work must exclude only its own exercises. The merge helper (lib/session-merge.js)
diff --git a/frontend/src/lib/session-start.test.js b/frontend/src/lib/session-start.test.js
index b774e3d2d..bd2365b40 100644
--- a/frontend/src/lib/session-start.test.js
+++ b/frontend/src/lib/session-start.test.js
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest'
-import { buildSessionEntries } from './session-start.js'
+import { buildSessionEntries, plannedConfigOf } from './session-start.js'
import { readSession } from './progression.js'
import { isWarmupRow } from './workout-model.js'
@@ -143,3 +143,27 @@ describe('buildSessionEntries', () => {
expect(buildSessionEntries(st, r)[0].rid).toBeUndefined()
})
})
+
+// The mid-session settings sheet edits the plan, so it opens at the plan's sets and reps and at
+// today's weight — never at a prescription's aim, climb or added set (#275).
+describe('plannedConfigOf', () => {
+ it('puts the plan\'s sets, reps and range back in place of today\'s', () => {
+ const entry = {
+ target: { id: '0025', mode: 'reps', sets: 3, reps: 9, repsMin: 8, weight: 42.5, prog: 'double' },
+ planned: { sets: 3, reps: 12, repsMin: 8, weight: 40 },
+ }
+ expect(plannedConfigOf(entry)).toEqual({ id: '0025', mode: 'reps', sets: 3, reps: 12, repsMin: 8, weight: 42.5, prog: 'double' })
+ })
+
+ it('drops a bottom the plan does not have, and takes a hold\'s seconds', () => {
+ expect(plannedConfigOf({ target: { sets: 3, reps: 13, repsMin: 10, weight: 0 }, planned: { sets: 2, reps: 10, weight: 0 } }))
+ .toEqual({ sets: 2, reps: 10, weight: 0 })
+ expect(plannedConfigOf({ target: { mode: 'time', sets: 2, sec: 50, weight: 0 }, planned: { sets: 2, sec: 45, weight: 0 } }).sec).toBe(45)
+ })
+
+ it('opens an entry built before plans were stamped at its target', () => {
+ const target = { sets: 2, reps: 8, weight: 60 }
+ expect(plannedConfigOf({ target })).toEqual(target)
+ expect(plannedConfigOf({ target })).not.toBe(target)
+ })
+})
diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsx
index 4b51e8a53..794e2cbd6 100644
--- a/frontend/src/views/Workout.jsx
+++ b/frontend/src/views/Workout.jsx
@@ -18,7 +18,7 @@ import Icon from '../components/Icon.jsx'
import { Button, Check, NumberField } from '../components/ui.jsx'
import { defaultIncrement, weightIncrement, stepWeight } from '../lib/progression.js'
import { progressionGuidance } from '../lib/progression-copy.js'
-import { buildPlannedEntry } from '../lib/session-start.js'
+import { buildPlannedEntry, plannedConfigOf } from '../lib/session-start.js'
import { glyphOf } from '../lib/glyphs.js'
import { isWarmupRow, isDropSet, isRestPauseSet, dropsOf, clustersOf, addDrop, addCluster, removeDropAt, removeClusterAt, setDropAt, setClusterAt, nextDropWeight, nextBurstReps, isSideSet, makeSideSet, setSideField, toggleSide, addSideDrop, removeSideDropAt, setSideDropAt, addSideCluster, removeSideClusterAt, setSideClusterAt } from '../lib/workout-model.js'
import { canMoveActiveWorkoutUnit, moveActiveWorkoutUnit } from '../lib/active-workout-order.js'
@@ -805,7 +805,10 @@ function ActiveWorkout() {
// A combined session's entries each carry a `rid`; progression settings read from that
// entry's own routine, not a session-wide one.
const routine = state.routines.find(r => r.id === entry.rid)
- exConfigSheet(exOr(entryId), entry.target, cfg => {
+ // The sheet opens at the plan's sets and reps rather than today's prescription (see
+ // plannedConfigOf), so saving it unchanged rebuilds the rows the entry already has.
+ const opened = plannedConfigOf(entry)
+ exConfigSheet(exOr(entryId), opened, cfg => {
// Store updates clone the state tree. If this exact object is no longer at the captured
// index, the list changed while the sheet was open; an id check alone cannot distinguish
// duplicate occurrences of the same exercise, so fail closed before cloning again.
@@ -820,6 +823,10 @@ function ActiveWorkout() {
// happens to occupy the same index.
if (!activeEntry || activeEntry.id !== entryId) return
const full = { ...cfg, id: activeEntry.id }
+ // The weight the sheet showed is today's. Left as it was, it is not an edit of the plan's:
+ // stamped as the plan, a later edit of the reps would restart from today's load as though
+ // it had been typed in (nextPrescription), so the plan keeps its own.
+ if ((cfg.weight || 0) === (opened.weight || 0) && activeEntry.planned?.weight != null) full.weight = activeEntry.planned.weight
const activeRoutine = s.routines.find(r => r.id === activeEntry.rid)
// A config without a set count keeps the rows the session already has.
if (!(full.sets > 0)) full.sets = activeEntry.sets.filter(x => !isWarmupRow(x)).length || 1
diff --git a/frontend/src/views/Workout.test.jsx b/frontend/src/views/Workout.test.jsx
index d312a16bd..a9839c3e7 100644
--- a/frontend/src/views/Workout.test.jsx
+++ b/frontend/src/views/Workout.test.jsx
@@ -4,6 +4,9 @@ import { parseHTML } from 'linkedom'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import Workout from './Workout.jsx'
import { nextPrescription } from '../lib/progression.js'
+import { buildCombinedEntries } from '../lib/session-merge.js'
+import { buildCompletedWorkout } from '../lib/finish-workout.js'
+import { isWarmupRow } from '../lib/workout-model.js'
const mocks = vi.hoisted(() => {
const state = {
@@ -631,7 +634,8 @@ describe('progression guidance', () => {
expect(button.getAttribute('type')).toBe('button')
expect(button.getAttribute('aria-label')).toBe('Open progression settings')
expect(mocks.exConfigSheet).toHaveBeenCalledOnce()
- expect(mocks.exConfigSheet.mock.calls[0][1]).toBe(second.target)
+ // An entry with no stamped plan opens at its target.
+ expect(mocks.exConfigSheet.mock.calls[0][1]).toEqual(second.target)
expect(mocks.exConfigSheet.mock.calls[0][4]).toBe(mocks.S.routines[0])
mocks.exConfigSheet.mock.calls[0][2]({ ...second.target, prog: 'double', repsMin: 6 })
@@ -772,6 +776,101 @@ describe('progression settings rebuild the rows like a session start', () => {
})
})
+// The settings sheet edits the plan, so it opens at the plan's sets and reps, not at today's
+// prescription. Opened at today's numbers, a save that changed nothing stamped a double
+// progression's raised session, or a bodyweight climb, as the plan: "Plan changed", the raise
+// undone within the session, the climb started again at the next one (#275).
+describe('saving progression settings unchanged', () => {
+ const BENCH = '0025' // barbell bench press
+ const PUSHUP = '0662' // push-up
+ const rows = entry => entry.sets.filter(s => !isWarmupRow(s)).map(s => [s.w, s.r])
+ // Start the routine for real, tick every row and log it the way finishing a workout does.
+ let day = 1
+ const trainOnce = st => {
+ const entries = buildCombinedEntries(st, ['A']).entries.map(e => ({ ...e, sets: e.sets.map(x => ({ ...x, done: true })) }))
+ const active = { id: 'w' + day, d: `2026-08-${String(day).padStart(2, '0')}`, start: day * 1000, routineIds: ['A'], name: 'A', entries }
+ day++
+ st.workouts.push(buildCompletedWorkout(active, { end: active.start + 1 }))
+ }
+ const history = (cfg, sessions) => {
+ const st = { unit: 'kg', exWeights: {}, routines: [{ id: 'A', name: 'A', ex: [cfg] }], workouts: [] }
+ for (let i = 0; i < sessions; i++) trainOnce(st)
+ return st
+ }
+ // What the sheet hands back when it is saved as it opened: its own fields, nothing else.
+ const unchanged = opened => {
+ const { sets, mode, reps, repsMin, weight, prog, repsMax } = opened
+ return JSON.parse(JSON.stringify({ sets, mode: mode || 'reps', reps, repsMin, weight, prog, repsMax }))
+ }
+ const saveUnchanged = async st => {
+ const built = buildCombinedEntries(st, ['A']).entries
+ await mount(built, 0, { routines: st.routines, workouts: st.workouts })
+ const before = structuredClone(mocks.S.active.entries[0])
+ await pressProgression()
+ const [, opened, save] = mocks.exConfigSheet.mock.calls.at(-1)
+ await act(async () => { save(unchanged(opened)) })
+ return { before, opened, after: mocks.S.active.entries[0] }
+ }
+ // Finish the session in front of you and build the next one from the same routine.
+ const next = st => {
+ const active = structuredClone(mocks.S.active)
+ active.entries.forEach(e => e.sets.forEach(x => { x.done = true }))
+ st.workouts.push(buildCompletedWorkout({ ...active, d: '2026-09-01', routineIds: ['A'] }, { end: Date.now() }))
+ return buildCombinedEntries(st, ['A']).entries[0]
+ }
+
+ it('keeps a double-progression raise in place, and the next session builds on it', async () => {
+ const st = history({ id: BENCH, sets: 3, reps: 12, repsMin: 8, weight: 40, prog: 'double' }, 1)
+ const { before, opened, after } = await saveUnchanged(st)
+ expect(before.plan.kind).toBe('up')
+ expect(opened).toMatchObject({ sets: 3, reps: 12, repsMin: 8 })
+ expect(rows(after)).toEqual([[42.5, 8], [42.5, 8], [42.5, 8]])
+ expect(after.plan.kind).toBe('up')
+ expect(after.planned).toEqual(before.planned)
+ expect(after.target).toMatchObject({ weight: 42.5, reps: 8, repsMin: 8 })
+ expect(container.querySelector('.planline')?.textContent).toBe('Plan: 3 × 8–12')
+ const following = next(st)
+ expect(following.plan.why[0]).not.toBe('Plan changed — starting from your new target.')
+ expect(rows(following)).toEqual([[42.5, 9], [42.5, 9], [42.5, 9]])
+ })
+
+ it('keeps a bodyweight climb, and the next session climbs on from it', async () => {
+ const st = history({ id: PUSHUP, sets: 2, reps: 10, weight: 0, bodyweight: true }, 3)
+ const { before, opened, after } = await saveUnchanged(st)
+ expect(rows(before)).toEqual([[0, 13], [0, 13]])
+ expect(opened).toMatchObject({ sets: 2, reps: 10 })
+ expect(rows(after)).toEqual([[0, 13], [0, 13]])
+ expect(after.planned).toEqual(before.planned)
+ const following = next(st)
+ expect(following.plan.kind).toBe('up')
+ expect(rows(following)).toEqual([[0, 14], [0, 14]])
+ })
+
+ it('keeps a set the rep ceiling added, and the plan line still reads the plan', async () => {
+ const st = history({ id: PUSHUP, sets: 2, reps: 10, repsMax: 11, weight: 0, bodyweight: true }, 2)
+ const { before, opened, after } = await saveUnchanged(st)
+ expect(rows(before)).toEqual([[0, 10], [0, 10], [0, 10]])
+ expect(opened.sets).toBe(2)
+ expect(rows(after)).toEqual([[0, 10], [0, 10], [0, 10]])
+ expect(after.planned).toEqual(before.planned)
+ expect(container.querySelector('.planline')?.textContent).toBe('Plan: 2 × 10 · today 3 × 10')
+ expect(rows(next(st))).toEqual([[0, 11], [0, 11], [0, 11]])
+ })
+
+ it('keeps the plan\'s weight when only the reps are edited, so the restart holds what was lifted', async () => {
+ const st = history({ id: BENCH, sets: 3, reps: 12, repsMin: 8, weight: 40, prog: 'double' }, 1)
+ await mount(buildCombinedEntries(st, ['A']).entries, 0, { routines: st.routines, workouts: st.workouts })
+ await pressProgression()
+ const [, opened, save] = mocks.exConfigSheet.mock.calls.at(-1)
+ expect(opened.weight).toBe(42.5) // today's, the one on the bar
+ await act(async () => { save({ ...unchanged(opened), reps: 10 }) })
+ const after = mocks.S.active.entries[0]
+ expect(after.planned).toEqual({ sets: 3, reps: 10, repsMin: 8, weight: 40 })
+ expect(after.plan.why[0]).toBe('Plan changed — starting from your new target.')
+ expect(rows(after).map(r => r[0])).toEqual([40, 40, 40])
+ })
+})
+
describe('effort cell (colour-coded RIR/RPE quick picker)', () => {
// A rep exercise whose sets can carry an effort rating. `rir` per set is optional — an
// unrated set simply omits the key, which is what the empty cell has to represent.