From 205e2bbbe0c099d72607a3622def0d5ee7ef856f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ullrich=20Sch=C3=A4fer?= Date: Sat, 11 Apr 2026 03:00:51 +0200 Subject: [PATCH] Fix notes not loading on session reload - Initialize CodeMirror with existing Y.Text content (doc: yjs.notes.toString()) so text is visible immediately, not just after the next remote change - Use dedicated Y.UndoManager for notes instead of sharing with waypoints undo manager (different tracked origins caused conflicts) - Use yUndoManagerKeymap for proper Yjs-aware undo/redo Co-Authored-By: Claude Opus 4.6 (1M context) --- apps/planner/app/components/NotesPanel.tsx | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/apps/planner/app/components/NotesPanel.tsx b/apps/planner/app/components/NotesPanel.tsx index 4b91620..179d9ac 100644 --- a/apps/planner/app/components/NotesPanel.tsx +++ b/apps/planner/app/components/NotesPanel.tsx @@ -2,9 +2,9 @@ import { useEffect, useRef } from "react"; import { useTranslation } from "react-i18next"; import { EditorView, keymap, placeholder } from "@codemirror/view"; import { EditorState } from "@codemirror/state"; -import { defaultKeymap, history, historyKeymap } from "@codemirror/commands"; -import { syntaxHighlighting, defaultHighlightStyle } from "@codemirror/language"; -import { yCollab } from "y-codemirror.next"; +import { defaultKeymap } from "@codemirror/commands"; +import { yCollab, yUndoManagerKeymap } from "y-codemirror.next"; +import * as Y from "yjs"; import type { YjsState } from "~/lib/use-yjs"; interface NotesPanelProps { @@ -16,9 +16,6 @@ const theme = EditorView.theme({ height: "100%", fontSize: "13px", }, - ".cm-editor": { - height: "100%", - }, ".cm-scroller": { overflow: "auto", fontFamily: "inherit", @@ -33,7 +30,6 @@ const theme = EditorView.theme({ "&.cm-focused": { outline: "none", }, - // Remote cursor styling ".cm-ySelectionInfo": { fontSize: "10px", fontFamily: "system-ui, sans-serif", @@ -66,16 +62,18 @@ export function NotesPanel({ yjs }: NotesPanelProps) { }); } + // Dedicated undo manager for notes (separate from waypoints undo) + const notesUndoManager = new Y.UndoManager(yjs.notes); + const state = EditorState.create({ + doc: yjs.notes.toString(), extensions: [ - keymap.of([...defaultKeymap, ...historyKeymap]), - history(), - syntaxHighlighting(defaultHighlightStyle), + keymap.of([...yUndoManagerKeymap, ...defaultKeymap]), EditorView.lineWrapping, placeholder(t("notes.placeholder")), theme, yCollab(yjs.notes, yjs.awareness, { - undoManager: yjs.undoManager, + undoManager: notesUndoManager, }), ], }); @@ -89,6 +87,7 @@ export function NotesPanel({ yjs }: NotesPanelProps) { return () => { view.destroy(); + notesUndoManager.destroy(); viewRef.current = null; }; }, [yjs]);