{"record":{"id":"a731173693682bea","repo":"DayuanJiang/next-ai-draw-io","slug":"no-encoded-data-found-in-the-diagram-element","errorCode":null,"errorMessage":"No encoded data found in the diagram element","messagePattern":"No encoded data found in the diagram element","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/utils.ts","lineNumber":1713,"sourceCode":"        function decodeHtmlEntities(str: string) {\n            const textarea = document.createElement(\"textarea\") // Use built-in element\n            textarea.innerHTML = str\n            return textarea.value\n        }\n        const xmlContent = decodeHtmlEntities(encodedContent)\n\n        // 4. Parse the XML content\n        const xmlDoc = parser.parseFromString(xmlContent, \"text/xml\")\n        const diagramElement = xmlDoc.querySelector(\"diagram\")\n\n        if (!diagramElement) {\n            throw new Error(\"No diagram element found\")\n        }\n        // 5. Extract base64 encoded data\n        const base64EncodedData = diagramElement.textContent\n\n        if (!base64EncodedData) {\n            throw new Error(\"No encoded data found in the diagram element\")\n        }\n\n        // 6. Decode base64 data\n        const binaryString = atob(base64EncodedData)\n\n        // 7. Convert binary string to Uint8Array\n        const len = binaryString.length\n        const bytes = new Uint8Array(len)\n        for (let i = 0; i < len; i++) {\n            bytes[i] = binaryString.charCodeAt(i)\n        }\n\n        // 8. Decompress data using pako (equivalent to zlib.decompress with wbits=-15)\n        const decompressedData = pako.inflate(bytes, { windowBits: -15 })\n\n        // 9. Convert the decompressed data to a string\n        const decoder = new TextDecoder(\"utf-8\")\n        const decodedString = decoder.decode(decompressedData)","sourceCodeStart":1695,"sourceCodeEnd":1731,"githubUrl":"https://github.com/DayuanJiang/next-ai-draw-io/blob/155ef4f7acd29c9d46fb6fc35c92e6e6955a6ce1/lib/utils.ts#L1695-L1731","documentation":"A <diagram> element was found, but its textContent is empty, so there is no base64-encoded compressed diagram data to inflate. In draw.io files each <diagram> holds base64 (deflate-raw + urlencode) mxGraphModel data; an empty one means the page exists but has no stored content.","triggerScenarios":"Calling the decoder on an <mxfile> whose <diagram> element is self-closing or whitespace-only (e.g. '<diagram id=\"x\" name=\"p\"/>'), or a diagram whose content was stripped during processing.","commonSituations":"Hand-constructed mxfile XML that adds the diagram element but forgets the encoded body; sanitizers/XML transforms that drop text nodes; empty placeholder pages created by string templating.","solutions":["Skip empty diagrams or treat them as blank pages instead of decoding","If constructing pages programmatically, embed the base64 body: '<diagram>' + btoa(deflatedMxGraphModel) + '</diagram>'","Validate textContent is non-empty before calling and report which page id/name is empty","Regenerate the file from draw.io if the source is corrupt"],"exampleFix":"// before\nconst xml = decodeDiagramFromSvg(dataUri) // '<diagram id=\"1\" name=\"p\"/>'\n\n// after\nconst diagrams = [...mxfileDoc.querySelectorAll('diagram')].filter(d => d.textContent?.trim())\nif (!diagrams.length) throw new Error('file has no pages with content')","handlingStrategy":"validation","validationCode":"const diagrams = [...mxfileDoc.querySelectorAll('diagram')].filter(d => d.textContent?.trim())\nif (diagrams.length === 0) throw new Error('mxfile contains no diagram with encoded data')","typeGuard":"function diagramHasPayload(d: Element): boolean {\n  return Boolean(d.textContent && d.textContent.trim().length > 0)\n}","tryCatchPattern":"for (const d of diagrams) { if (!diagramHasPayload(d)) continue; results.push(decodeDiagram(d)) }","preventionTips":["Treat empty <diagram> elements as blank pages and skip them","When generating pages, always include the base64 body","Filter by textContent before decoding"],"tags":["drawio","base64","empty-element","parsing"],"backgroundTag":"missing-payload-data","analyzedSha":"155ef4f7acd29c9d46fb6fc35c92e6e6955a6ce1","analyzedAt":"2026-08-27T11:40:38.297Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}