From a6324862297f0edeabb9d1f7e21450d0f6a28d7e Mon Sep 17 00:00:00 2001 From: lzinga Date: Tue, 30 Dec 2025 11:35:48 -0800 Subject: [PATCH 1/2] fix(mermaid) diagrams not saving content and SVG attachment --- apps/client/src/widgets/type_widgets/Mermaid.tsx | 1 + apps/client/src/widgets/type_widgets/code/Code.tsx | 6 ++++-- .../widgets/type_widgets/helpers/SvgSplitEditor.tsx | 12 ++++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/apps/client/src/widgets/type_widgets/Mermaid.tsx b/apps/client/src/widgets/type_widgets/Mermaid.tsx index 65574aa01..9403c4cf6 100644 --- a/apps/client/src/widgets/type_widgets/Mermaid.tsx +++ b/apps/client/src/widgets/type_widgets/Mermaid.tsx @@ -29,6 +29,7 @@ export default function Mermaid(props: TypeWidgetProps) { ); diff --git a/apps/client/src/widgets/type_widgets/code/Code.tsx b/apps/client/src/widgets/type_widgets/code/Code.tsx index 1c08ee808..b3c8686fa 100644 --- a/apps/client/src/widgets/type_widgets/code/Code.tsx +++ b/apps/client/src/widgets/type_widgets/code/Code.tsx @@ -1,6 +1,7 @@ import "./code.css"; import { default as VanillaCodeMirror, getThemeById } from "@triliumnext/codemirror"; +import { NoteType } from "@triliumnext/commons"; import { useEffect, useRef, useState } from "preact/hooks"; import appContext, { CommandListenerData } from "../../../components/app_context"; @@ -24,6 +25,7 @@ export interface EditableCodeProps extends TypeWidgetProps, Omit void; /** Invoked after the content of the note has been uploaded to the server, using a spaced update. */ @@ -72,14 +74,14 @@ function formatViewSource(note: FNote, content: string) { return content; } -export function EditableCode({ note, ntxId, noteContext, debounceUpdate, parentComponent, updateInterval, onContentChanged, dataSaved, ...editorProps }: EditableCodeProps) { +export function EditableCode({ note, ntxId, noteContext, debounceUpdate, parentComponent, updateInterval, noteType = "code", onContentChanged, dataSaved, ...editorProps }: EditableCodeProps) { const editorRef = useRef(null); const containerRef = useRef(null); const [ vimKeymapEnabled ] = useTriliumOptionBool("vimKeymapEnabled"); const mime = useNoteProperty(note, "mime"); const spacedUpdate = useEditorSpacedUpdate({ note, - noteType: "code", + noteType, noteContext, getData: () => ({ content: editorRef.current?.getText() ?? "" }), onContentChange: (content) => { diff --git a/apps/client/src/widgets/type_widgets/helpers/SvgSplitEditor.tsx b/apps/client/src/widgets/type_widgets/helpers/SvgSplitEditor.tsx index 3c9eff27a..04fd78829 100644 --- a/apps/client/src/widgets/type_widgets/helpers/SvgSplitEditor.tsx +++ b/apps/client/src/widgets/type_widgets/helpers/SvgSplitEditor.tsx @@ -1,4 +1,4 @@ -import { useEffect, useRef, useState } from "preact/hooks"; +import { useCallback, useEffect, useRef, useState } from "preact/hooks"; import { t } from "../../../services/i18n"; import SplitEditor, { PreviewButton, SplitEditorProps } from "./SplitEditor"; import { RawHtmlBlock } from "../../react/RawHtml"; @@ -55,7 +55,9 @@ export default function SvgSplitEditor({ ntxId, note, attachmentName, renderSvg, } // Save as attachment. - function onSave() { + const onSave = useCallback(() => { + if (!svg) return; // Don't save if SVG hasn't been rendered yet + const payload = { role: "image", title: `${attachmentName}.svg`, @@ -65,16 +67,18 @@ export default function SvgSplitEditor({ ntxId, note, attachmentName, renderSvg, }; server.post(`notes/${note.noteId}/attachments?matchBy=title`, payload); - } + }, [ svg, attachmentName, note.noteId ]); // Save the SVG when entering a note only when it does not have an attachment. useEffect(() => { + if (!svg) return; // Wait until SVG is rendered + note?.getAttachments().then((attachments) => { if (!attachments.find((a) => a.title === `${attachmentName}.svg`)) { onSave(); } }); - }, [ note ]); + }, [ note, svg, attachmentName, onSave ]); // Import/export useTriliumEvent("exportSvg", async({ ntxId: eventNtxId }) => { From 0cf23c7d7c156c4c4895c7dfffac7aa5fe1ce71d Mon Sep 17 00:00:00 2001 From: Lucas Date: Tue, 30 Dec 2025 11:56:34 -0800 Subject: [PATCH 2/2] Update apps/client/src/widgets/type_widgets/helpers/SvgSplitEditor.tsx Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- apps/client/src/widgets/type_widgets/helpers/SvgSplitEditor.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/client/src/widgets/type_widgets/helpers/SvgSplitEditor.tsx b/apps/client/src/widgets/type_widgets/helpers/SvgSplitEditor.tsx index 04fd78829..9a1c1dd4e 100644 --- a/apps/client/src/widgets/type_widgets/helpers/SvgSplitEditor.tsx +++ b/apps/client/src/widgets/type_widgets/helpers/SvgSplitEditor.tsx @@ -77,7 +77,7 @@ export default function SvgSplitEditor({ ntxId, note, attachmentName, renderSvg, if (!attachments.find((a) => a.title === `${attachmentName}.svg`)) { onSave(); } - }); + }).catch(e => console.error("Failed to get attachments for SVGSplitEditor", e)); }, [ note, svg, attachmentName, onSave ]); // Import/export