Repository navigation
Fix extra empty paragraph in a fresh draft after reload - #9
Merged
Merged
Conversation
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.
A fresh browser with no saved draft gained an extra empty paragraph after the first reload.
Root cause
LocalProject.opencreates its ownY.Doc, waits for IndexedDB to sync, and callscreateDocumentif the paragraph store is empty. When the same empty project is opened twice at once (React StrictMode runs theAppeffect twice in development), both opens find an empty store. Each one pushes its own blank paragraph from a different Yjs client.createDocumentclears only the paragraphs its own doc can see, so it can't remove the other one. Both updates end up in IndexedDB, and on reload they merge into two paragraphs: the one the user typed in and an extra empty one.Change
app/src/lib/project.ts:LocalProject.opennow runs opens of the same project ID one at a time, using a module-level map of opens in progress. A second open starts only after the first has synced and written its blank document, so it loads that document instead of creating another. A failed open doesn't block later ones.User impact
A new draft that is edited and reloaded keeps only the paragraphs the user created.
Tests
app/src/lib/local_project.test.ts. It opens the same empty project twice concurrently, destroys both, then reopens the project and checks that it has exactly one paragraph. Without the fix the test fails (2 paragraphs).pnpm run lintandpnpm run testpass locally (15 files, 44 tests).Notes
Closes #8
Agents: claude-code (claude-opus-5-5)