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
Sync: another account signing in on a full browser storage still keeps what the first was owed — the copy makes room for it
Duarte Santos77891c4bb04b
diff --git a/frontend/src/store/useStore.js b/frontend/src/store/useStore.jsindex 6d874088f..510d31c6f 100644--- a/frontend/src/store/useStore.js+++ b/frontend/src/store/useStore.js@@ -535,7 +535,13 @@ export const useStore = create((set, get) => {state.active = S.active || prev?.active || nullconst entry = { server: server || null, uid, name: get().user?.id === uid ? get().user.name || '' : '', at: Date.now(), state }all[key] = entry- try { localStorage.setItem(STASH_KEY, JSON.stringify(all)) } catch { /* full — the file may still take it */ }+ // A second full copy beside the first may not fit (a profile near the size limit): the copy+ // in storage is wiped next anyway, so it makes the room.+ const v = JSON.stringify(all)+ try { localStorage.setItem(STASH_KEY, v) }+ catch {+ try { localStorage.removeItem(KEY); localStorage.setItem(STASH_KEY, v) } catch { /* still full — the file may still take it */ }+ }if (MOBILE) keeping = readStashes().then(f => writeStashes({ ...f, [key]: entry })).catch(() => {})}const stashOwed = async () => {diff --git a/frontend/src/store/useStore.sync-status.test.jsx b/frontend/src/store/useStore.sync-status.test.jsxindex 2b8167662..2d8c22eb6 100644--- a/frontend/src/store/useStore.sync-status.test.jsx+++ b/frontend/src/store/useStore.sync-status.test.jsx@@ -315,6 +315,32 @@ describe('another account signing in on a copy that still owes the first', () =>expect(await useStore.getState().keptChanges()).toEqual([])})+ it('on a device with no room for a second copy beside the first, the copy makes room for what it owed', async () => {+ const S = { ...clone(DEF), _ts: 300, workouts: [workout('w1'), { ...workout('w-week', '2026-09-18'), note: 'x'.repeat(20000) }] }+ signedIn(S)+ localStorage.setItem('gym_state_v1', JSON.stringify(S))+ localStorage.setItem('gym_sync', JSON.stringify({ rev: 1, ts: 100 }))+ localStorage.setItem('gym_dirty', '1')+ // A quota: room for one copy of this profile and a little more, never for two.+ const used = () => Object.keys(localStorage).reduce((n, k) => n + k.length + localStorage.getItem(k).length, 0)+ const quota = used() + 5000+ const setItem = localStorage.setItem.bind(localStorage)+ const full = vi.spyOn(localStorage, 'setItem').mockImplementation((k, v) => {+ const prev = localStorage.getItem(k)+ if (used() - (prev == null ? 0 : k.length + prev.length) + k.length + String(v).length > quota) throw new DOMException('The quota has been exceeded.', 'QuotaExceededError')+ return setItem(k, v)+ })+ try {+ api.mockImplementation(twosServer)+ useStore.getState().setUser({ id: 'user-2', name: 'Two' })+ await useStore.getState().adoptProfile(async () => false)+ } finally { full.mockRestore() }++ expect(ids(useStore.getState().S.workouts)).toEqual(['b1'])+ expect(await useStore.getState().keptChanges()).toEqual([{ server: location.origin, uid: USER.id, name: 'One', at: expect.any(Number) }])+ expect(ids(JSON.parse(localStorage.getItem('gym_stash'))[location.origin + '|' + USER.id].state.workouts)).toEqual(['w1', 'w-week'])+ })+it('a copy that owes nothing is replaced as before, with nothing kept', async () => {signedIn({ ...clone(DEF), _ts: 100, workouts: [workout('w1')] })localStorage.setItem('gym_sync', JSON.stringify({ rev: 1, ts: 100 }))