Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(client): SVG export downloads nothing — revert blob URL to data URL
Elian Doran74e6321ee21d
diff --git a/apps/client/src/services/utils.spec.ts b/apps/client/src/services/utils.spec.tsindex 46a4399e94..1caa707827 100644--- a/apps/client/src/services/utils.spec.ts+++ b/apps/client/src/services/utils.spec.ts@@ -683,15 +683,16 @@ describe("SVG downloads (default export)", () => {return blobs;}- it("downloadSvg downloads the SVG string as a blob URL", async () => {+ it("downloadSvg downloads the SVG string as a data URL (a blob-URL anchor click after " ++ "the export's awaits is silently blocked without user activation)", () => {const downloads = captureDownload();- const blobs = captureObjectUrls();utils.downloadSvg("diagram", `<svg><text>a & b</text></svg>`);- expect(downloads).toEqual([ { name: "diagram.svg", href: "blob:mock-1" } ]);- expect(blobs).toHaveLength(1);- expect(blobs[0].type).toContain("image/svg+xml");- expect(await blobs[0].text()).toBe(`<svg><text>a & b</text></svg>`);+ expect(downloads).toHaveLength(1);+ expect(downloads[0].name).toBe("diagram.svg");+ const href = downloads[0].href ?? "";+ expect(href.startsWith("data:image/svg+xml;charset=utf-8,")).toBe(true);+ expect(decodeURIComponent(href.split(",")[1])).toBe(`<svg><text>a & b</text></svg>`);});it("downloadSvgAsPng rasterizes at the given scale and downloads a PNG", async () => {diff --git a/apps/client/src/services/utils.ts b/apps/client/src/services/utils.tsindex 3ac2fafbad..12b93dea45 100644--- a/apps/client/src/services/utils.ts+++ b/apps/client/src/services/utils.ts@@ -616,11 +616,11 @@ export function createImageSrcUrl(note: FNote) {* @param svgContent the content of the SVG file to download.*/function downloadSvg(nameWithoutExtension: string, svgContent: string) {- const blob = new Blob([ svgContent ], { type: "image/svg+xml;charset=utf-8" });- const url = URL.createObjectURL(blob);- triggerDownload(`${nameWithoutExtension}.svg`, url);- // Defer revocation so the in-flight download isn't cancelled (as downloadImage in image.ts).- setTimeout(() => URL.revokeObjectURL(url), 10_000);+ // The download MUST go through a data: URL, not a blob URL: export runs after awaits have+ // consumed the transient user-activation, and a blob-URL anchor click without activation is+ // silently blocked (same constraint documented in spreadsheet/export.tsx `download()`).+ const dataUrl = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(svgContent)}`;+ triggerDownload(`${nameWithoutExtension}.svg`, dataUrl);}/**