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(print): fails if included note could not be found
Elian Dorane0dc25ad230d
diff --git a/apps/client/src/entities/fnote.ts b/apps/client/src/entities/fnote.tsindex 5fe9bc67d4..0f6df098a5 100644--- a/apps/client/src/entities/fnote.ts+++ b/apps/client/src/entities/fnote.ts@@ -240,7 +240,7 @@ export default class FNote {const aNote = this.froca.getNoteFromCache(aNoteId);- if (aNote.isArchived || aNote.isHiddenCompletely()) {+ if (!aNote || aNote.isArchived || aNote.isHiddenCompletely()) {return 1;}diff --git a/apps/client/src/services/content_renderer_text.ts b/apps/client/src/services/content_renderer_text.tsindex d70a425018..fbe9dc218c 100644--- a/apps/client/src/services/content_renderer_text.ts+++ b/apps/client/src/services/content_renderer_text.ts@@ -56,9 +56,14 @@ async function renderIncludedNotes(contentEl: HTMLElement) {// Render and integrate the notes.for (const includeNoteEl of includeNoteEls) {const noteId = includeNoteEl.getAttribute("data-note-id");- if (!noteId) return;+ if (!noteId) continue;const note = froca.getNoteFromCache(noteId);+ if (!note) {+ console.warn(`Unable to include ${noteId} because it could not be found.`);+ continue;+ }+const renderedContent = (await content_renderer.getRenderedContent(note)).$renderedContent;includeNoteEl.replaceChildren(...renderedContent);}diff --git a/apps/client/src/services/froca-interface.ts b/apps/client/src/services/froca-interface.tsindex 156bc684a2..80015cc343 100644--- a/apps/client/src/services/froca-interface.ts+++ b/apps/client/src/services/froca-interface.ts@@ -13,7 +13,7 @@ export interface Froca {getBlob(entityType: string, entityId: string): Promise<FBlob | null>;getNote(noteId: string, silentNotFoundError?: boolean): Promise<FNote | null>;- getNoteFromCache(noteId: string): FNote;+ getNoteFromCache(noteId: string): FNote | undefined;getNotesFromCache(noteIds: string[], silentNotFoundError?: boolean): FNote[];getNotes(noteIds: string[], silentNotFoundError?: boolean): Promise<FNote[]>;diff --git a/apps/client/src/services/froca.ts b/apps/client/src/services/froca.tsindex a1529db722..646db69d57 100644--- a/apps/client/src/services/froca.ts+++ b/apps/client/src/services/froca.ts@@ -288,7 +288,7 @@ class FrocaImpl implements Froca {return (await this.getNotes([noteId], silentNotFoundError))[0];}- getNoteFromCache(noteId: string) {+ getNoteFromCache(noteId: string): FNote | undefined {if (!noteId) {throw new Error("Empty noteId");}diff --git a/apps/client/src/widgets/dialogs/branch_prefix.tsx b/apps/client/src/widgets/dialogs/branch_prefix.tsxindex e715c894f6..e46b3d36ad 100644--- a/apps/client/src/widgets/dialogs/branch_prefix.tsx+++ b/apps/client/src/widgets/dialogs/branch_prefix.tsx@@ -103,7 +103,7 @@ export default function BranchPrefixDialog() {<input class="branch-prefix-input form-control" value={prefix} ref={branchInput}onChange={(e) => setPrefix((e.target as HTMLInputElement).value)} />{isSingleBranch && branches[0] && (- <div class="branch-prefix-note-title input-group-text"> - {branches[0].getNoteFromCache().title}</div>+ <div class="branch-prefix-note-title input-group-text"> - {branches[0].getNoteFromCache()?.title}</div>)}</div></FormGroup>@@ -113,7 +113,7 @@ export default function BranchPrefixDialog() {<ul>{branches.map((branch) => {const note = branch.getNoteFromCache();- return (+ return note && (<li key={branch.branchId}>{branch.prefix && <span className="branch-prefix-current">{branch.prefix} - </span>}{note.title}diff --git a/apps/client/src/widgets/dialogs/recent_changes.tsx b/apps/client/src/widgets/dialogs/recent_changes.tsxindex 295650e545..60de8b1b0a 100644--- a/apps/client/src/widgets/dialogs/recent_changes.tsx+++ b/apps/client/src/widgets/dialogs/recent_changes.tsx@@ -21,7 +21,7 @@ export default function RecentChangesDialog() {const [ refreshCounter, setRefreshCounter ] = useState(0);const [ shown, setShown ] = useState(false);- useTriliumEvent("showRecentChanges", ({ ancestorNoteId }) => {+ useTriliumEvent("showRecentChanges", ({ ancestorNoteId }) => {setAncestorNoteId(ancestorNoteId ?? hoisted_note.getHoistedNoteId());setShown(true);});@@ -91,7 +91,7 @@ function RecentChangesTimeline({ groupedByDate, setShown }: { groupedByDate: Mapreturn (<li className={isDeleted ? "deleted-note" : ""}><span title={change.date}>{formattedTime}</span>- { !isDeleted+ { notePath && !isDeleted? <NoteLink notePath={notePath} title={change.current_title} />: <DeletedNoteLink change={change} setShown={setShown} /> }</li>diff --git a/apps/client/src/widgets/note_tree.ts b/apps/client/src/widgets/note_tree.tsindex 5d15fccd80..c5ee99d86f 100644--- a/apps/client/src/widgets/note_tree.ts+++ b/apps/client/src/widgets/note_tree.ts@@ -574,6 +574,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {.loadSearchNote(noteId).then(() => {const note = froca.getNoteFromCache(noteId);+ if (!note) return [];let childNoteIds = note.getChildNoteIds();@@ -585,6 +586,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {}).then(() => {const note = froca.getNoteFromCache(noteId);+ if (!note) return [];return this.prepareChildren(note);});@@ -740,7 +742,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {const node = $.ui.fancytree.getNode(e as unknown as Event);const note = froca.getNoteFromCache(node.data.noteId);- if (note.isLaunchBarConfig()) {+ if (note?.isLaunchBarConfig()) {import("../menus/launcher_context_menu.js").then(({ default: LauncherContextMenu }) => {const launcherContextMenu = new LauncherContextMenu(this, node);launcherContextMenu.show(e);@@ -775,7 +777,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {if (hideArchivedNotes) {const note = branch.getNoteFromCache();- if (note.hasLabel("archived")) {+ if (!note || note.hasLabel("archived")) {continue;}}@@ -1754,7 +1756,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget {for (const nodeToDuplicate of nodesToDuplicate) {const note = froca.getNoteFromCache(nodeToDuplicate.data.noteId);- if (note.isProtected && !protectedSessionHolder.isProtectedSessionAvailable()) {+ if (note?.isProtected && !protectedSessionHolder.isProtectedSessionAvailable()) {continue;}