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.

Undo: a routine put back that never had an edit time stays without one, so an older app's offline rename survives

Duarte Santos65c06570091a
diff --git a/frontend/src/lib/sync-merge.js b/frontend/src/lib/sync-merge.js
index 718b39bd6..3062842eb 100644
--- a/frontend/src/lib/sync-merge.js
+++ b/frontend/src/lib/sync-merge.js
@@ -1032,9 +1032,10 @@ export function stampChange(prev, next, wall = Date.now()) {
// A routine put back by an Undo keeps the edit time it had: what puts it back is the add-back
// on record (stampDeletions), not an edit of it. Stamped as edited now, it was the newer version
// to an older app's merge (v1.3.9 keeps a routine whole, by `_ts`), and a rename made there
- // offline was lost to the Undo. Only a routine removed after its last edit counts.
+ // offline was lost to the Undo. Only a routine removed after its last edit counts, and one that
+ // never had an edit time (the seed's, a template's, one from before stamps) stays without one.
const gone = isMap(prev?.deleted?.routines) ? prev.deleted.routines : {}
- const putBack = r => Number(gone[r.id]) > 0 && Number(r._ts) > 0 && Number(r._ts) < Number(gone[r.id]) &&
+ const putBack = r => Number(gone[r.id]) > 0 && (!(Number(r._ts) > 0) || Number(r._ts) < Number(gone[r.id])) &&
!list(prev?.routines).some(x => x?.id === r.id)
stampRoutines(prev?.routines, next.routines, now, putBack)
stampCustomEx(prev?.customEx, next.customEx, now)
diff --git a/frontend/src/views/Plan.swipe.test.jsx b/frontend/src/views/Plan.swipe.test.jsx
index e67ef00ab..7c4d713c6 100644
--- a/frontend/src/views/Plan.swipe.test.jsx
+++ b/frontend/src/views/Plan.swipe.test.jsx
@@ -106,9 +106,9 @@ describe('the routines list', () => {
expect(nav).not.toHaveBeenCalled()
undo()
- // the same routines in the same order; the store stamps the one put back as an edit (_ts)
- expect(S().routines.map(({ _ts, ...r }) => r)).toEqual(before.routines)
- expect(S().routines[1]._ts).toBeGreaterThan(0)
+ // the same routines in the same order, the one put back without an edit time it never had
+ // (stamped "now", it beat a rename an older app made offline before the swipe)
+ expect(S().routines).toEqual(before.routines)
expect(S().week).toEqual(before.week)
expect(S().dayPlan).toEqual(before.dayPlan)
expect(rowOf('Pull A')).toBeTruthy()
diff --git a/frontend/src/views/undo-concurrent.test.jsx b/frontend/src/views/undo-concurrent.test.jsx
index 84e2e9c54..08eb711f3 100644
--- a/frontend/src/views/undo-concurrent.test.jsx
+++ b/frontend/src/views/undo-concurrent.test.jsx
@@ -127,6 +127,26 @@ describe('Undo of a routine swiped away in Plan, with an older app (v1.3.9) on t
expect(m.week[3]).toEqual(['b'])
}
})
+ // RC verify 2026-10-07: a routine with no edit time (the seed's, a template's, one from before
+ // stamps and never edited since) was stamped "now" by the Undo, the newer version to v1.3.9.
+ it('a rename made there offline survives the Undo of a routine that had no edit time', () => {
+ useStore.setState({ S: (() => { const s = clone(S()); delete s.routines[1]._ts; return s })() })
+ const base = S()
+ const old = clone(base)
+ old.routines[1].name = 'Pull heavy'; old.routines[1]._ts = T0; old._ts = T0 // v1.3.9, offline
+ deleteRoutineWithUndo('b')
+ undo()
+ expect(S().routines.find(r => r.id === 'b')._ts).toBeUndefined()
+ const server = clone(S())
+ const pushed = v139Merge(old, server)
+ stampPut(server, pushed, { overRead: true, stamped: false, now: Date.now() + 1 })
+ expect(pushed.routines.find(r => r.id === 'b').name).toBe('Pull heavy')
+ for (const m of both(S(), pushed)) {
+ expect(m.routines.map(r => r.id)).toEqual(['a', 'b', 'c'])
+ expect(m.routines.find(r => r.id === 'b').name).toBe('Pull heavy')
+ expect(m.week[3]).toEqual(['b'])
+ }
+ })
it('a weekday another device changed before it saw the removal survives the Undo', () => {
const other = change(S(), s => { s.week[3] = ['b', 'c'] }, Date.now() - 1000)
deleteRoutineWithUndo('b')