From f6682fe3ac82ab15082c8fb988a73cbd48803488 Mon Sep 17 00:00:00 2001 From: Dayuan Jiang <34411969+DayuanJiang@users.noreply.github.com> Date: Mon, 8 Dec 2025 10:10:52 +0900 Subject: [PATCH] fix(diagram): wrap XML in mxfile structure when canvas is empty (#156) When clicking an example diagram on a clean page (no existing diagram), the code was passing raw ... format XML directly to DrawIO. However, DrawIO expects the full mxfile/diagram/mxGraphModel/root structure. This fix provides a default mxfile template when chartXML is empty, ensuring replaceNodes properly wraps the content before loading into DrawIO. Co-authored-by: dayuan.jiang --- components/chat-message-display.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/components/chat-message-display.tsx b/components/chat-message-display.tsx index 3c618ef..73fc11b 100644 --- a/components/chat-message-display.tsx +++ b/components/chat-message-display.tsx @@ -177,10 +177,12 @@ export function ChatMessageDisplay({ const currentXml = xml || "" const convertedXml = convertToLegalXml(currentXml) if (convertedXml !== previousXML.current) { - // If chartXML is empty, use the converted XML directly - const replacedXML = chartXML - ? replaceNodes(chartXML, convertedXml) - : convertedXml + // If chartXML is empty, create a default mxfile structure to use with replaceNodes + // This ensures the XML is properly wrapped in mxfile/diagram/mxGraphModel format + const baseXML = + chartXML || + `` + const replacedXML = replaceNodes(baseXML, convertedXml) const validationError = validateMxCellStructure(replacedXML) if (!validationError) {