Skip to content

Build your personal knowledge base with Trilium Notes

fix(revisions): SVG not rendering (closes #10191)

Elian Doran63afb17a1a64
diff --git a/apps/client/src/widgets/dialogs/revisions.tsx b/apps/client/src/widgets/dialogs/revisions.tsx
index c9ec149bd3..3098d9c6d8 100644
--- a/apps/client/src/widgets/dialogs/revisions.tsx
+++ b/apps/client/src/widgets/dialogs/revisions.tsx
@@ -663,7 +663,7 @@ function RevisionContent({ noteContent, revisionItem, fullRevision, showDiff }:
//Base64 of other format images may be embedded in svg
const encodedSVG = encodeURIComponent(content as string);
return <img
- src={`data:${fullRevision.mime};utf8,${encodedSVG}`}
+ src={`data:${fullRevision.mime},${encodedSVG}`}
style={IMAGE_STYLE} />;
}
default: {
diff --git a/packages/trilium-core/src/routes/api/revisions.spec.ts b/packages/trilium-core/src/routes/api/revisions.spec.ts
index 9094cb7df8..7ad0c943f2 100644
--- a/packages/trilium-core/src/routes/api/revisions.spec.ts
+++ b/packages/trilium-core/src/routes/api/revisions.spec.ts
@@ -298,6 +298,20 @@ describe("Revisions API (core)", () => {
// Base64 output, decodes back to the original content.
expect(Buffer.from(res.body.content, "base64").toString()).toContain("binary-image-bytes");
});
+
+ it("returns SVG image revision content as raw text, not base64", async () => {
+ // SVG is text-based and is rendered client-side from a URL-encoded data URI, so it must not
+ // be base64-encoded (regression from the Uint8Array compatibility refactor — see getRevision).
+ const svg = "<svg xmlns='http://www.w3.org/2000/svg'><rect/></svg>";
+ const revisionId = await createTypedRevision("image", "image/svg+xml", svg);
+
+ const res = await api.get<{ content: string; type: string; mime: string }>(`/api/revisions/${revisionId}`);
+ expect(res.status).toBe(200);
+ expect(res.body.type).toBe("image");
+ expect(res.body.mime).toBe("image/svg+xml");
+ // Returned verbatim, not base64-encoded.
+ expect(res.body.content).toBe(svg);
+ });
});
describe("excess revisions", () => {
diff --git a/packages/trilium-core/src/routes/api/revisions.ts b/packages/trilium-core/src/routes/api/revisions.ts
index ad28ac231c..a79ada7246 100644
--- a/packages/trilium-core/src/routes/api/revisions.ts
+++ b/packages/trilium-core/src/routes/api/revisions.ts
@@ -52,7 +52,9 @@ function getRevision(req: Request<{ revisionId: string }>) {
} else {
revision.content = revision.getContent();
- if (revision.content && revision.type === "image") {
+ // SVG is text-based and is rendered client-side from a UTF-8 (URL-encoded) data URI, so it is
+ // returned as-is. Other (binary) image formats are base64-encoded for transport in the JSON response.
+ if (revision.content && revision.type === "image" && revision.mime !== "image/svg+xml") {
revision.content = binary_utils.encodeBase64(revision.content);
}
}