Skip to content

Build your personal knowledge base with Trilium Notes

fix(mind-map): keep a map with icons saveable

Elian Doranadc6ec80b892
diff --git a/apps/client/src/services/spaced_update.ts b/apps/client/src/services/spaced_update.ts
index fe71e0d993..a17d95aa0c 100644
--- a/apps/client/src/services/spaced_update.ts
+++ b/apps/client/src/services/spaced_update.ts
@@ -207,6 +207,10 @@ export default class SpacedUpdate<T = void> {
const restoreOnError = (e: unknown): never => {
this.changed = true;
this.onStateChanged("error");
+ // Said out loud, as a failed commit is. Every caller of this path swallows what is
+ // rethrown, so a snapshot that cannot be taken would otherwise show as a failing save
+ // indicator and nothing else — anywhere.
+ logError(getErrorMessage(e));
// The debounce timer may have already fired and gone idle while the snapshot was
// being captured; schedule a retry so the restored change is not stranded until
// the next scheduleUpdate() call. Going through the retry timer (rather than the
diff --git a/apps/client/src/widgets/type_widgets/helpers/mind_map_icons.spec.ts b/apps/client/src/widgets/type_widgets/helpers/mind_map_icons.spec.ts
index 2a778c46d4..27d1c71515 100644
--- a/apps/client/src/widgets/type_widgets/helpers/mind_map_icons.spec.ts
+++ b/apps/client/src/widgets/type_widgets/helpers/mind_map_icons.spec.ts
@@ -42,6 +42,18 @@ describe("renderIconClasses", () => {
.toEqual([ [ "", "⭐" ], [ "", "phosphor ph-cube" ], [ "", "bx" ] ]);
});
+ it("leaves a dressed icon something to read, for the exporter's sake", () => {
+ // Mind Elixir's SVG exporter reads `childNodes[0].textContent` off every icon it finds, so
+ // a span emptied down to nothing throws there — and the preview is rendered on every save.
+ const container = buildNode("bx bx-star");
+
+ renderIconClasses(container);
+
+ const icon = container.querySelector(".icons > span");
+ expect(icon?.childNodes).toHaveLength(1);
+ expect(icon?.childNodes[0].textContent).toBe("");
+ });
+
it("can be run again over what it has already dressed", () => {
// It runs after every layout, and a layout does not always rebuild the node.
const container = buildNode("bx bx-star");
diff --git a/apps/client/src/widgets/type_widgets/helpers/mind_map_icons.ts b/apps/client/src/widgets/type_widgets/helpers/mind_map_icons.ts
index d9c25a6e31..ba5084600c 100644
--- a/apps/client/src/widgets/type_widgets/helpers/mind_map_icons.ts
+++ b/apps/client/src/widgets/type_widgets/helpers/mind_map_icons.ts
@@ -16,7 +16,11 @@ export function renderIconClasses(container: HTMLElement) {
if (!isIconClass(iconClass)) continue;
iconEl.className = iconClass;
- iconEl.textContent = "";
+ // Emptied down to an empty text node rather than to nothing at all: Mind Elixir's SVG
+ // exporter reads `span.childNodes[0].textContent` for every icon it comes across, and a
+ // span holding no children at all throws — which failed the save of any map with an icon,
+ // the preview being rendered through that exporter.
+ iconEl.replaceChildren(document.createTextNode(""));
}
}