fix(sync): read the app inbox from the database and repair split devices #164

Merged
maximus merged 2 commits from issue-152-inbox-server-id into master 2026-10-26 00:59:29 +00:00

2 commits

Author SHA1 Message Date
le king fu
3cf8be3dcf fix(sync): bound the wait on the persisted settings before the inbox repair
zustand's persist never finishes a failed load (a storage that throws, or
corrupted JSON under simpl-liste-settings): onFinishHydration is never
called and hasHydrated stays false. whenSettingsHydrated waited for it
without bound, so repairInbox never settled and the splash screen stayed
up at every launch (review of PR #164).

- onRehydrateStorage records the load error.
- whenSettingsHydrated goes through waitForHydration (src/lib/hydration.ts,
  pure, node-tested), which rejects on that error or after 5 s. The
  rejection skips the repair through the existing catch of prepareInbox,
  and ensureInbox and the startup go on.
- tests/hydration.test.mjs also pins the failure mode against the zustand
  persist middleware of the repo; the smoke test locks the store wiring
  (mutation R6 of the review now fails it).

Refs #152

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 20:35:06 -04:00
le king fu
0156aee011 fix(sync): read the app inbox from the database and repair split devices
After the first sync the app kept reading the fixed local inbox id, which
the server never knows: the Inbox tab looked empty, tasks created there
were refused, and ensureInbox recreated the fixed list at every launch.

- getInboxId() is async and returns the local isInbox list, preferring a
  server inbox over the fixed id (pickInboxId, most recent first like the
  server); the fixed id only remains before the first sync.
- ensureInbox() creates the fixed id only when no inbox exists at all.
- repairInbox() runs at startup, after the settings store is hydrated and
  before the first sync: tasks under the fixed id move to the server inbox
  and are queued again (create, update, current tags, pending tag
  removals, dated in push order), their pending entries are discarded,
  other pending entries pointing at the fixed id are rewritten, list
  entries of the fixed inbox are dropped, and the fixed list is deleted.
  The decisions live in planInboxRepair (syncRules.ts, pure, node-tested
  against a model of POST /api/sync: zero refusals after the repair).
- initialReset on an account without an inbox creates one under a new
  UUID and pushes it, instead of falling back to the fixed id.
- The new task screen loads its default list asynchronously.

test: reproduces #152 (tests/syncRules.test.mjs, smoke wiring guard)

Refs #152

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 20:20:24 -04:00