From 6040eea3bd9686ff67b084551bce5f7cd1940fd0 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 22 Nov 2025 11:52:16 +0200 Subject: [PATCH] fix(text): note with empty table carries over to new notes --- .../src/widgets/type_widgets/text/CKEditorWithWatchdog.tsx | 6 +----- apps/client/src/widgets/type_widgets/text/EditableText.tsx | 7 ++++--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/apps/client/src/widgets/type_widgets/text/CKEditorWithWatchdog.tsx b/apps/client/src/widgets/type_widgets/text/CKEditorWithWatchdog.tsx index fd6814528..1c3a85e23 100644 --- a/apps/client/src/widgets/type_widgets/text/CKEditorWithWatchdog.tsx +++ b/apps/client/src/widgets/type_widgets/text/CKEditorWithWatchdog.tsx @@ -20,7 +20,6 @@ export interface CKEditorApi { } interface CKEditorWithWatchdogProps extends Pick, "className" | "tabIndex"> { - content: string | undefined; contentLanguage: string | null | undefined; isClassicEditor?: boolean; watchdogRef: RefObject; @@ -35,7 +34,7 @@ interface CKEditorWithWatchdogProps extends Pick, "cla containerRef?: RefObject; } -export default function CKEditorWithWatchdog({ containerRef: externalContainerRef, content, contentLanguage, className, tabIndex, isClassicEditor, watchdogRef: externalWatchdogRef, watchdogConfig, onNotificationWarning, onWatchdogStateChange, onChange, onEditorInitialized, editorApi, templates }: CKEditorWithWatchdogProps) { +export default function CKEditorWithWatchdog({ containerRef: externalContainerRef, contentLanguage, className, tabIndex, isClassicEditor, watchdogRef: externalWatchdogRef, watchdogConfig, onNotificationWarning, onWatchdogStateChange, onChange, onEditorInitialized, editorApi, templates }: CKEditorWithWatchdogProps) { const containerRef = useSyncedRef(externalContainerRef, null); const watchdogRef = useRef(null); const [ uiLanguage ] = useTriliumOption("locale"); @@ -185,9 +184,6 @@ export default function CKEditorWithWatchdog({ containerRef: externalContainerRe return () => watchdog.destroy(); }, [ contentLanguage, templates, uiLanguage ]); - // React to content changes. - useEffect(() => editor?.setData(content ?? ""), [ editor, content ]); - // React to notification warning callback. useEffect(() => { if (!onNotificationWarning || !editor) return; diff --git a/apps/client/src/widgets/type_widgets/text/EditableText.tsx b/apps/client/src/widgets/type_widgets/text/EditableText.tsx index 9b3915abd..e3fa1ecee 100644 --- a/apps/client/src/widgets/type_widgets/text/EditableText.tsx +++ b/apps/client/src/widgets/type_widgets/text/EditableText.tsx @@ -27,7 +27,7 @@ import { deferred } from "@triliumnext/commons"; */ export default function EditableText({ note, parentComponent, ntxId, noteContext }: TypeWidgetProps) { const containerRef = useRef(null); - const [ content, setContent ] = useState(); + const contentRef = useRef(""); const watchdogRef = useRef(null); const editorApiRef = useRef(null); const refreshTouchBarRef = useRef<() => void>(null); @@ -55,7 +55,8 @@ export default function EditableText({ note, parentComponent, ntxId, noteContext }; }, onContentChange(newContent) { - setContent(newContent); + contentRef.current = newContent; + watchdogRef.current?.editor?.setData(newContent); } }); const templates = useTemplates(); @@ -215,7 +216,6 @@ export default function EditableText({ note, parentComponent, ntxId, noteContext containerRef={containerRef} className={`note-detail-editable-text-editor use-tn-links ${codeBlockWordWrap ? "word-wrap" : ""}`} tabIndex={300} - content={content} contentLanguage={language} isClassicEditor={isClassicEditor} editorApi={editorApiRef} @@ -245,6 +245,7 @@ export default function EditableText({ note, parentComponent, ntxId, noteContext } initialized.current.resolve(); + editor.setData(contentRef.current ?? ""); parentComponent?.triggerEvent("textEditorRefreshed", { ntxId, editor }); }} />}