Skip to content

Fix extra empty paragraph in a fresh draft after reload - #9

Merged
lsegal merged 2 commits into
mainfrom
fix/issue-8-duplicate-blank-document
Oct 3, 2026
Merged

lsegal merged 2 commits into
mainfrom
fix/issue-8-duplicate-blank-document

Conversation

@lsegal

@lsegal lsegal commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

A fresh browser with no saved draft gained an extra empty paragraph after the first reload.

Root cause

LocalProject.open creates its own Y.Doc, waits for IndexedDB to sync, and calls createDocument if the paragraph store is empty. When the same empty project is opened twice at once (React StrictMode runs the App effect twice in development), both opens find an empty store. Each one pushes its own blank paragraph from a different Yjs client. createDocument clears 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.open now 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

  • Added 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 lint and pnpm run test pass locally (15 files, 44 tests).

Notes

  • No changelog entry: the project has no changelog.
  • No screenshots: the change fixes how data is persisted and doesn't change any rendered UI.

Closes #8

Agents: claude-code (claude-opus-5-5)

@lsegal
lsegal marked this pull request as ready for review October 3, 2026 21:44
@lsegal
lsegal merged commit 1bd683b into main Oct 3, 2026
1 check passed
@lsegal
lsegal deleted the fix/issue-8-duplicate-blank-document branch October 3, 2026 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fresh draft gains an extra empty paragraph after first reload

1 participant