feat(M3): Yjs local persistence + autosave + undo/redo#6
Merged
Conversation
Replaces the in-memory Zustand shape store with a Yjs Y.Doc persisted to IndexedDB via y-indexeddb. Canvas state survives page reload without any explicit save action. - @notux/sync: boardDoc (Y.Doc cache), indexedDbProvider (IndexedDB persistence cache), pageMap (getPageMap / findPageMap helpers) - shapeStore: rewritten around Y.Map<pageId, Y.Map<shapeId, YShape>>; adds initBoard(boardId) with promise-cache for idempotency, synced and lastSaved Zustand fields for UI - useUndoManager hook: Y.UndoManager scoped per page, exposes undo/redo + canUndo/canRedo; wired to Ctrl+Z / Ctrl+Shift+Z in CanvasStage - Board.tsx: awaits initBoard before rendering canvas, shows spinner - SaveStatus.tsx: fixed badge showing "Saved [relative time]" once synced https://claude.ai/code/session_01GqTM9M6Nsoy4GTWQsdYUxg
The lockfile was missing @notux/sync and yjs entries for packages/canvas because pnpm install was run before the manual package.json edits were applied. This caused CI --frozen-lockfile to fail immediately. https://claude.ai/code/session_01GqTM9M6Nsoy4GTWQsdYUxg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Y.Docbacked byy-indexeddb. Canvas state survives page reload with zero explicit save calls — IndexedDB syncs on every transaction automatically.SaveStatuscomponent readssynced+lastSavedfrom the shape store and shows a fixed "Saved just now / Xs ago" badge once the board is loaded.Y.UndoManagerscoped per page;Ctrl+Z/Ctrl+Shift+Z(andCtrl+Y) wired inCanvasStage. Stack state exposed viauseUndoManagerhook.ShapeStoreinterface (listShapes,addShape,updateShape,deleteShape,transact) is unchanged.Changed files
packages/sync/src/boardDoc.tsY.Doccache keyed by boardIdpackages/sync/src/indexedDbProvider.tsIndexeddbPersistencecache keyed by boardIdpackages/sync/src/pageMap.tsfindPageMap(read-only) +getPageMap(create-on-write)packages/sync/src/index.tspackages/canvas/src/store/shapeStore.tsinitBoard,synced,lastSavedpackages/canvas/src/hooks/useUndoManager.tsY.UndoManagerhook per pagepackages/canvas/src/CanvasStage.tsxuseUndoManager, wire Ctrl+Z/Y/Shift+Zapps/web/src/routes/Board.tsxinitBoard, show spinner, render<SaveStatus />apps/web/src/features/canvas/SaveStatus.tsxTest plan
pnpm typecheckpasses (all 5 packages)https://claude.ai/code/session_01GqTM9M6Nsoy4GTWQsdYUxg
Generated by Claude Code