Skip to content

feat: keep note drafts offline and add version history - #43

Merged
AmrMsCLL merged 2 commits into
mainfrom
feat/note-history
Oct 5, 2026
Merged

AmrMsCLL merged 2 commits into
mainfrom
feat/note-history

Conversation

@AmrMsCLL

@AmrMsCLL AmrMsCLL commented Oct 5, 2026

Copy link
Copy Markdown
Member

What changed

PR 3e from .claude/.Plans/as2026-10-02-strata-phase-3-technical-design.md. Amr approved decision 4, y-indexeddb. Stacked on #42.

New dependency: y-indexeddb 9.0.12 (MIT, no further dependencies), installed in the Linux container so the lockfile keeps its libc fields.

  • Offline drafts:
    • every open note keeps its Yjs updates in IndexedDB (strata-note-<id>);
    • edits made while offline survive a reload and merge when the connection returns;
    • the status says "Offline. Changes are kept on this device";
    • signing out already deletes every IndexedDB database, so drafts don't outlive the session.
  • Version history (note_versions):
    • a snapshot is taken when the last person leaves a note, and at most every 15 minutes during long sessions;
    • unchanged and empty states are skipped;
    • the maintenance run thins versions: all of them for 7 days, then the latest per day until 90 days, then the latest per week.
  • Endpoints: GET /notes/:id/versions (when and by whom), GET /notes/:id/versions/:versionId (the text), and POST …/restore for editors.
  • Restoring:
    • the restore goes through a Hocuspocus direct connection and replaces the page as a new change, so people editing at that moment see it live and keep working;
    • the current state is saved as a version first, so a restore can itself be undone.
  • History button on each page: pick a version, read its text, and editors can restore it. Viewers can look but not restore.
  • A fix to feat: add notes and a real-time editing server #41: on shutdown the real-time server now terminates open WebSockets. Before, the HTTP server waited for them to time out, so restarts hung for about 30 seconds per open connection. The notes integration spec went from 40 s to 8 s.

Migration (runs on deploy)

20261005040000_note_versions creates note_versions. It changes no existing rows.

Verification

  • Lint, both builds and tsc --noEmit pass.

  • test/integration/notes.spec.ts adds a case covering:

    • a version when the editing session ends, with its author and text;
    • no extra version from a mid-session save;
    • viewers listing but not restoring;
    • a restore reaching a connected editor live, with the pre-restore state kept;
    • thinning back-dated versions down to one per day and one per week.

    All four notes cases pass against Postgres on the local stack.

  • test/notes.spec.tsx adds a case for previewing and restoring, and for viewers having no Restore button.

  • On the real local stack:

    • the editor still loads and saves;
    • the strata-note-<id> IndexedDB database is created;
    • History lists the version from an earlier session.

    Offline editing itself wasn't tried; it would need the network cut in the browser.

@github-actions github-actions Bot added the size/l 201-600 changed lines, excluding lockfiles label Oct 5, 2026
Base automatically changed from feat/notes-editor to main October 5, 2026 19:04
@AmrMsCLL
AmrMsCLL merged commit a23cd20 into main Oct 5, 2026
6 checks passed
@AmrMsCLL
AmrMsCLL deleted the feat/note-history branch October 5, 2026 19:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/l 201-600 changed lines, excluding lockfiles

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant