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.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
Import: a workout running on this device stays, whether the backup replaces or is merged in
Duarte Santos10ae92828356
diff --git a/frontend/src/store/useStore.import-check.test.jsx b/frontend/src/store/useStore.import-check.test.jsxindex 1f94ece2b..21245355f 100644--- a/frontend/src/store/useStore.import-check.test.jsx+++ b/frontend/src/store/useStore.import-check.test.jsx@@ -88,3 +88,43 @@ describe('importing a backup over a profile that moved on', () => {expect(put.baseRev).toBe(8)})})++// RC review 2026-10-07: a backup imported mid-workout dropped the workout running on this device.+// "Merge them in" set the backup's `active` (none) over it, and the replace took the backup's+// whole copy, `active` included. A running session lives on this device only, so no backup or+// server copy can stand in for it: it stays, in the unit of the copy that replaces this one.+describe('a backup imported while a workout is running', () => {+ const running = { start: 1000, entries: [{ id: 'bench', sets: [{ w: 100, r: 5, done: true }] }] }+ it('"Merge them in" keeps the running workout', async () => {+ signedIn({ ...clone(DEF), _ts: 200, workouts: [workout('w1')], active: clone(running) }, 6)+ api.mockResolvedValueOnce({ state: clone(SERVER), rev: 7 })+ const c = await useStore.getState().importConflict(BACKUP)+ useStore.getState().importBackup(BACKUP, { mergeWith: c })+ expect(useStore.getState().S.active).toEqual(running)+ })+ it('"Replace anyway" and the plain import keep it too', async () => {+ signedIn({ ...clone(DEF), _ts: 200, workouts: [workout('w1')], active: clone(running) }, 6)+ api.mockResolvedValueOnce({ state: clone(SERVER), rev: 7 })+ await useStore.getState().importConflict(BACKUP)+ useStore.getState().importBackup(BACKUP)+ expect(useStore.getState().S.active).toEqual(running)+ useStore.setState({ user: null })+ useStore.getState().importBackup({ ...BACKUP, active: null })+ expect(useStore.getState().S.active).toEqual(running)+ })+ it('in the backup\'s unit when the backup is in another one', async () => {+ signedIn({ ...clone(DEF), _ts: 200, unit: 'kg', workouts: [workout('w1')], active: clone(running) }, 6)+ useStore.setState({ user: null })+ useStore.getState().importBackup({ ...BACKUP, unit: 'lb' })+ const S = useStore.getState().S+ expect(S.unit).toBe('lb')+ expect(S.active.start).toBe(1000)+ expect(S.active.entries[0].sets[0].w).not.toBe(100)+ })+ it('a backup taken mid-workout still brings its session when none runs here', async () => {+ signedIn({ ...clone(DEF), _ts: 200, workouts: [workout('w1')] }, 6)+ useStore.setState({ user: null })+ useStore.getState().importBackup({ ...BACKUP, active: clone(running) })+ expect(useStore.getState().S.active).toEqual(running)+ })+})diff --git a/frontend/src/store/useStore.js b/frontend/src/store/useStore.jsindex b8ac68806..8c72f8c42 100644--- a/frontend/src/store/useStore.js+++ b/frontend/src/store/useStore.js@@ -1363,9 +1363,14 @@ export const useStore = create((set, get) => {const server = read?.state || nullconst now = Math.max(Date.now(), highestStamp(cur) + 1, highestStamp(server) + 1, highestStamp(backup) + 1)const next = sanitizeAccent(Object.assign(clone(DEF), backup))+ // A workout running here lives on this device only: no backup and no server copy holds it,+ // so the import keeps it (in the backup's unit). Only with none running does a backup taken+ // mid-workout bring its own session back. Both the replace and "Merge them in" dropped it.+ const running = carryActive(cur, next) || next.active || nullif (!mergeWith?.state || !uid) {stampRestore(next, [cur, server], now)next._ts = now+ next.active = runningconst at = read?.rev != null ? { rev: read.rev, wid: read.state?._wid } : metaOf().baseget().replaceState(next, !!uid, { baseRev: at?.rev ?? null, baseWid: at?.wid })return@@ -1376,7 +1381,7 @@ export const useStore = create((set, get) => {const merged = keepReset(others, keepReset(cur, Object.assign(clone(DEF), mergeStates(next, others, { prefer: 'a' }))))stampRestore(merged, [cur, mergeWith.state, next], now)merged._ts = now- merged.active = next.active || null+ merged.active = carryActive({ unit: next.unit, active: running }, merged)persist(merged, true)if (mergeWith.rev != null) writeSync(mergeWith.rev, 0, mergeWith.state?._wid)},