fix: prevent demo mode from overwriting real user data #22

Merged
uwayss merged 1 commit from claude/fix-demo-mode-data-loss into main 2026-08-30 23:15:20 +00:00
Collaborator

Fixes #18 — Demo mode could permanently destroy the user's real data.

Problem

persistState() tried to distinguish "real" data from demo data by checking useAppStore.getState(), but that's the same in-memory store that had just been overwritten with MOCK_DEEDS / fake demo logs when demo mode was enabled — it was circular, not a real fallback to disk. As a result, any store action while demo mode was active (logging a deed, adding a deed, etc.) would write the fake demo data to disk, overwriting the user's real save file. Turning demo mode back off then reloaded from disk, which now only contained demo data — the user's real deeds/logs were gone for good.

Fix

Added a realDeeds/realLogs slice to the store that holds the user's actual data and is never touched by demo mode. All mutating actions now route through a small helper (applyDeedDataUpdate) that updates the displayed deeds/logs always, but only updates realDeeds/realLogs when demo mode is off. persistState() now always saves from realDeeds/realLogs, so demo data can never reach disk.

Test plan

  • npm run checks:tsc passes
  • npm run checks:lint passes (pre-existing unrelated warnings only)
  • Manually verify: enable demo mode, log a prayer, disable demo mode — real data should be intact
Fixes #18 — Demo mode could permanently destroy the user's real data. ## Problem `persistState()` tried to distinguish "real" data from demo data by checking `useAppStore.getState()`, but that's the *same* in-memory store that had just been overwritten with `MOCK_DEEDS` / fake demo logs when demo mode was enabled — it was circular, not a real fallback to disk. As a result, any store action while demo mode was active (logging a deed, adding a deed, etc.) would write the fake demo data to disk, overwriting the user's real save file. Turning demo mode back off then reloaded from disk, which now only contained demo data — the user's real deeds/logs were gone for good. ## Fix Added a `realDeeds`/`realLogs` slice to the store that holds the user's actual data and is never touched by demo mode. All mutating actions now route through a small helper (`applyDeedDataUpdate`) that updates the displayed `deeds`/`logs` always, but only updates `realDeeds`/`realLogs` when demo mode is off. `persistState()` now always saves from `realDeeds`/`realLogs`, so demo data can never reach disk. ## Test plan - [x] `npm run checks:tsc` passes - [x] `npm run checks:lint` passes (pre-existing unrelated warnings only) - [ ] Manually verify: enable demo mode, log a prayer, disable demo mode — real data should be intact
fix: prevent demo mode from overwriting real user data
Some checks failed
Checks / checks (pull_request) Failing after 22s
935cf5c165
persistState() tried to detect "real" vs demo data by re-reading the
same in-memory store it had just overwritten with MOCK_DEEDS/demo
logs, so any store action while demo mode was on (logging a deed,
adding a deed, etc.) wrote fake demo data to disk over the user's
actual save file. Disabling demo mode then reloaded from disk, which
now only contained demo data — permanently losing the user's real
data.

Track the user's real deeds/logs in a separate realDeeds/realLogs
slice that demo mode never touches, and always persist from that
slice instead of the displayed deeds/logs.
uwayss force-pushed claude/fix-demo-mode-data-loss from 935cf5c165
Some checks failed
Checks / checks (pull_request) Failing after 22s
to ca25231851
All checks were successful
Checks / checks (pull_request) Successful in 23s
2026-08-30 21:31:40 +00:00
Compare
uwayss merged commit 152500cd97 into main 2026-08-30 23:15:20 +00:00
uwayss deleted branch claude/fix-demo-mode-data-loss 2026-08-30 23:15:20 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
uwayss/muhsin!22
No description provided.