Skip to content

fix(note): stop destroying the Tiptap editor manually - #55

Merged
mrsibe merged 1 commit into
mainfrom
fix/note-editor-strictmode
Sep 24, 2026
Merged

mrsibe merged 1 commit into
mainfrom
fix/note-editor-strictmode

Conversation

@mrsibe

@mrsibe mrsibe commented Sep 24, 2026

Copy link
Copy Markdown
Owner

What does this PR do?

Fixes the blank window that appears when clicking Add to Note in a chat while running the app in development.

Why?

NoteEditor registered a cleanup effect that called editor.destroy() on unmount, but @tiptap/react v3's useEditor already owns the editor lifecycle. Under React StrictMode (dev), effects run mount → cleanup → mount, so the second mount received an already destroyed instance; the content-sync effect then read editor.storage.markdown.getMarkdown() and threw. The renderer has no error boundary, so React unmounted the entire tree and the window went blank.

Production builds do not double-invoke effects, which is why the packaged app did not reproduce this.

This surfaced on Add to Note because #15 made that path open the note editor, mounting NoteEditor for the first time.

Related issue

No open issue; reported from manual testing.

What changed?

  • Removed the manual editor.destroy() cleanup effect from NoteEditor and let useEditor manage teardown.
  • Added a comment explaining why manual teardown must not be reintroduced.

How was this tested?

Reproduced and verified with Electron CDP against npm run dev (StrictMode active):

  • Before: clicking "Add to Note" produced TypeError: Cannot read properties of undefined (reading 'getMarkdown') inside <NoteEditor>, and document.body.innerText.length dropped to 0 (blank window).
  • After: the note editor mounts, the created note renders, opening/returning from notes and adding another note produce no exceptions.
  • npm run typecheck:web passes.
  • npm test passes (49/49).
  • npx prettier --check src/renderer/src/components/notebook/note/NoteEditor.tsx passes.

Screenshots / recordings

Not applicable (no visual change when working).

Checklist

  • I have reviewed my own changes.
  • npm run typecheck passes.
  • npm run build passes.
  • I have tested the affected user workflow.
  • I have not included unrelated changes.
  • I have updated documentation when necessary.

Desktop / build changes

  • Not applicable

NoteEditor registered a cleanup effect that called editor.destroy() on
unmount, but @tiptap/react v3's useEditor already owns the editor
lifecycle. Under React StrictMode the effect runs mount → cleanup →
mount, so the manual destroy left the second mount with an already
destroyed instance: the content-sync effect then read
editor.storage.markdown as undefined, threw, and—with no error
boundary—unmounted the whole React tree (blank window).

This surfaced on "Add to Note" in chat because #15 made that path open
the note editor, which mounts NoteEditor for the first time.

Remove the manual destroy and let useEditor manage it.
@github-actions github-actions Bot added the bug Something isn't working label Sep 24, 2026
@mrsibe
mrsibe merged commit 438eed6 into main Sep 24, 2026
4 checks passed
@mrsibe
mrsibe deleted the fix/note-editor-strictmode branch September 24, 2026 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant