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(notes): stop capturing a note from rebuilding a deleted journal
Elian Doranf0fe9f178b1f
diff --git a/apps/client/src/services/note_autocomplete.spec.ts b/apps/client/src/services/note_autocomplete.spec.tsindex 5ce08e955e..4bc2396566 100644--- a/apps/client/src/services/note_autocomplete.spec.ts+++ b/apps/client/src/services/note_autocomplete.spec.ts@@ -322,6 +322,16 @@ describe("autocompleteSource (via dataset)", () => {expect(translate).toHaveBeenCalledWith("note_autocomplete.create-note-into", { term: "New", parentTitle: title });});+ it("says top level for a database with neither an inbox nor a journal", async () => {+ getInboxTarget.mockResolvedValueOnce({ kind: "root", noteId: "root", title: "root" });+ server.get = vi.fn(async () => []) as typeof server.get;+ const { dataset } = initAndGetSource({ allowCreatingNotes: true });+ const rows = await runSource(dataset, "New");+ // The root note's title would be meaningless in the label, so it is not used.+ expect(rows[0].highlightedNotePathTitle).toBe("note_autocomplete.create-note-into-root");+ expect(translate).toHaveBeenCalledWith("note_autocomplete.create-note-into-root", { term: "New" });+ });+it("names the day note, which has no title of its own until it is created", async () => {getInboxTarget.mockResolvedValueOnce({ kind: "dayNote" });server.get = vi.fn(async () => []) as typeof server.get;diff --git a/apps/client/src/services/note_autocomplete.ts b/apps/client/src/services/note_autocomplete.tsindex c912818e51..7a17e8ce72 100644--- a/apps/client/src/services/note_autocomplete.ts+++ b/apps/client/src/services/note_autocomplete.ts@@ -41,7 +41,7 @@ async function getInboxTarget() {/** Labels the creation entry with the note the capture would land in. */function buildCreateNoteTitle(term: string, target: InboxTargetResponse | null) {- if (!target || (target.kind !== "dayNote" && !target.title)) {+ if (!target) {return t("note_autocomplete.create-note", { term });}@@ -49,6 +49,15 @@ function buildCreateNoteTitle(term: string, target: InboxTargetResponse | null)return t("note_autocomplete.create-note-into-day-note", { term });}+ // The root note's own title names nothing the user recognises in the tree.+ if (target.kind === "root") {+ return t("note_autocomplete.create-note-into-root", { term });+ }++ if (!target.title) {+ return t("note_autocomplete.create-note", { term });+ }+return t("note_autocomplete.create-note-into", { term, parentTitle: target.title });}diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 5675fba742..16e80f38ca 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -2980,6 +2980,7 @@"create-note": "Create note \"{{term}}\"","create-note-into": "Create note \"{{term}}\" in {{parentTitle}}","create-note-into-day-note": "Create note \"{{term}}\" in today's day note",+ "create-note-into-root": "Create note \"{{term}}\" at the top level","create-child-note": "Create child note \"{{term}}\"","insert-external-link": "Insert external link to \"{{term}}\"","clear-text-field": "Clear text field",diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Jump to & command palette.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Jump to & command palette.htmlindex abb3236d00..6253b7262a 100644--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Jump to & command palette.html+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Navigation/Jump to & command palette.html@@ -25,10 +25,12 @@note title and selecting one of two options:<ul><li><em>Create note</em> places it in the <a class="reference-link" href="#root/_help_S0Fos78ZfcY7">Note Inbox</a>:- the note labelled <code spellcheck="false">#inbox</code>, or today's <a class="reference-link"- href="#root/_help_l0tKav7yLHGF">Day Notes</a> if there is none. While- hoisted into a <a class="reference-link" href="#root/_help_9sRHySam5fXb">Workspaces</a>,- the workspace's own inbox is used, falling back to the workspace root itself.</li>+ the note labelled <code spellcheck="false">#inbox</code>, today's <a class="reference-link"+ href="#root/_help_l0tKav7yLHGF">Day Notes</a> if there is none, or the+ top level if there is no journal either. While hoisted into a <a class="reference-link"+ href="#root/_help_9sRHySam5fXb">Workspaces</a>, the workspace's own inbox+ is used, falling back to the workspace root itself. The option names the+ destination, so it is always visible before the note is created.</li><li><em>Create child note</em> places it under the note that is currentlyopen.</li></ul>diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Notes/Note Inbox.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Notes/Note Inbox.htmlindex 5e2e617c74..b5c6809f0a 100644--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Notes/Note Inbox.html+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Basic Concepts and Features/Notes/Note Inbox.html@@ -18,8 +18,10 @@<p>Only one note should carry this label. If there are multiple notes, onlyone will be used by the application.</p><aside class="admonition note">- <p>If there is no inbox note, Trilium will fall back to today's <a href="#root/_help_l0tKav7yLHGF">day note</a> instead,- creating it and its calendar ancestors if they do not exist yet.</p>+ <p>If there is no inbox note, Trilium will fall back to today's <a href="#root/_help_l0tKav7yLHGF">day note</a>,+ creating it and its calendar ancestors as needed. If the journal has been+ removed altogether, the note is created at the top level instead of a new+ journal being built for it.</p></aside><h2>Workspace inboxes</h2><p>Each <a href="#root/_help_9sRHySam5fXb">workspace</a> can have its own inbox,diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Links/Internal (reference) links.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Links/Internal (reference) links.htmlindex 22254331e0..1309890e21 100644--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Links/Internal (reference) links.html+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Links/Internal (reference) links.html@@ -12,9 +12,9 @@<li>Searching for the title of the desired note to link. It's also possibleto create new notes from this dialog by typing a non-existing note titleand selecting either <em>Create note</em>, which places it in the <a class="reference-link"- href="#root/_help_S0Fos78ZfcY7">Note Inbox</a> (today's day note if no- inbox is set), or <em>Create child note</em>, which places it under the note- being edited.</li>+ href="#root/_help_S0Fos78ZfcY7">Note Inbox</a> (today's day note, or the+ top level, when no inbox is set), or <em>Create child note</em>, which places+ it under the note being edited.</li></ol><p>There are two link types which you can select when creating the link tothe note:</p>diff --git a/docs/User Guide/User Guide/Basic Concepts and Features/Navigation/Jump to & command palette.md b/docs/User Guide/User Guide/Basic Concepts and Features/Navigation/Jump to & command palette.mdindex 6625487c7c..f29b7e3a8b 100644--- a/docs/User Guide/User Guide/Basic Concepts and Features/Navigation/Jump to & command palette.md+++ b/docs/User Guide/User Guide/Basic Concepts and Features/Navigation/Jump to & command palette.md@@ -17,7 +17,7 @@ In addition to searching for notes, it is also possible to search for commands.* By default, when there is no text entered it will display the most recent notes.* Using the keyboard, use the up or down arrow keys to navigate between items. Press <kbd>Enter</kbd> to open the desired note.* If the note doesn't exist, it's possible to create it by typing the desired note title and selecting one of two options:- * _Create note_ places it in the <a class="reference-link" href="../Notes/Note%20Inbox.md">Note Inbox</a>: the note labelled `#inbox`, or today's <a class="reference-link" href="../../Advanced%20Usage/Advanced%20Showcases/Day%20Notes.md">Day Notes</a> if there is none. While hoisted into a <a class="reference-link" href="Workspaces.md">Workspaces</a>, the workspace's own inbox is used, falling back to the workspace root itself.+ * _Create note_ places it in the <a class="reference-link" href="../Notes/Note%20Inbox.md">Note Inbox</a>: the note labelled `#inbox`, today's <a class="reference-link" href="../../Advanced%20Usage/Advanced%20Showcases/Day%20Notes.md">Day Notes</a> if there is none, or the top level if there is no journal either. While hoisted into a <a class="reference-link" href="Workspaces.md">Workspaces</a>, the workspace's own inbox is used, falling back to the workspace root itself. The option names the destination, so it is always visible before the note is created.* _Create child note_ places it under the note that is currently open.## Recent notesdiff --git a/docs/User Guide/User Guide/Basic Concepts and Features/Notes/Note Inbox.md b/docs/User Guide/User Guide/Basic Concepts and Features/Notes/Note Inbox.mdindex 0407bc2780..d9ac3b4622 100644--- a/docs/User Guide/User Guide/Basic Concepts and Features/Notes/Note Inbox.md+++ b/docs/User Guide/User Guide/Basic Concepts and Features/Notes/Note Inbox.md@@ -16,7 +16,7 @@ To create a note inbox, apply the `#inbox` [label](../../Advanced%20Usage/AttribOnly one note should carry this label. If there are multiple notes, only one will be used by the application.> [!NOTE]-> If there is no inbox note, Trilium will fall back to today's [day note](../../Advanced%20Usage/Advanced%20Showcases/Day%20Notes.md) instead, creating it and its calendar ancestors if they do not exist yet.+> If there is no inbox note, Trilium will fall back to today's [day note](../../Advanced%20Usage/Advanced%20Showcases/Day%20Notes.md), creating it and its calendar ancestors as needed. If the journal has been removed altogether, the note is created at the top level instead of a new journal being built for it.## Workspace inboxesdiff --git a/docs/User Guide/User Guide/Note Types/Text/Links/Internal (reference) links.md b/docs/User Guide/User Guide/Note Types/Text/Links/Internal (reference) links.mdindex a0815ef91f..0417850053 100644--- a/docs/User Guide/User Guide/Note Types/Text/Links/Internal (reference) links.md+++ b/docs/User Guide/User Guide/Note Types/Text/Links/Internal (reference) links.md@@ -8,7 +8,7 @@ You can open an internal link by clicking it. You can also see a read-only previInternal links can be created at the current position in a text note by:1. Pressing <kbd>Ctrl</kbd> + <kbd>L</kbd> or the <img src="Internal (reference) links_image.png" width="20" height="17"> button underneath the <img src="1_Internal (reference) links_image.png" width="34" height="16"> menu in the <a class="reference-link" href="../Formatting%20toolbar.md">Formatting toolbar</a>.-2. Searching for the title of the desired note to link. It's also possible to create new notes from this dialog by typing a non-existing note title and selecting either _Create note_, which places it in the <a class="reference-link" href="../../../Basic%20Concepts%20and%20Features/Notes/Note%20Inbox.md">Note Inbox</a> (today's day note if no inbox is set), or _Create child note_, which places it under the note being edited.+2. Searching for the title of the desired note to link. It's also possible to create new notes from this dialog by typing a non-existing note title and selecting either _Create note_, which places it in the <a class="reference-link" href="../../../Basic%20Concepts%20and%20Features/Notes/Note%20Inbox.md">Note Inbox</a> (today's day note, or the top level, when no inbox is set), or _Create child note_, which places it under the note being edited.There are two link types which you can select when creating the link to the note:diff --git a/packages/commons/src/lib/server_api.ts b/packages/commons/src/lib/server_api.tsindex 653f732101..85ee9530ec 100644--- a/packages/commons/src/lib/server_api.ts+++ b/packages/commons/src/lib/server_api.ts@@ -797,7 +797,7 @@ export type SaveSearchNoteResponse = CloneResponse;* Which rule decided where a quickly captured note goes. `dayNote` is the only one that* names no note, because the day note is created when the capture happens.*/-export type InboxTargetKind = "inbox" | "workspaceInbox" | "workspaceRoot" | "dayNote";+export type InboxTargetKind = "inbox" | "workspaceInbox" | "workspaceRoot" | "dayNote" | "root";/** Where `POST /api/notes/:id/children` would put a note captured into the inbox. */export interface InboxTargetResponse {diff --git a/packages/trilium-core/src/services/date_notes.ts b/packages/trilium-core/src/services/date_notes.tsindex b6deb42ae0..f53c4f209f 100644--- a/packages/trilium-core/src/services/date_notes.ts+++ b/packages/trilium-core/src/services/date_notes.ts@@ -434,8 +434,18 @@ function getTodayNote(rootNote: BNote | null = null) {return getDayNote(dayjs().format("YYYY-MM-DD"), rootNote);}+/**+ * Whether a journal exists. `getRootCalendarNote()` builds one when it finds none, which is+ * what asking for a day note means; callers that are only capturing a note check this first so+ * that a deleted journal stays deleted.+ */+function hasCalendarRoot() {+ return !!attributeService.getNoteWithLabel(CALENDAR_ROOT_LABEL);+}+export default {getRootCalendarNote,+ hasCalendarRoot,getYearNote,getQuarterNote,getMonthNote,diff --git a/packages/trilium-core/src/services/special_notes.spec.ts b/packages/trilium-core/src/services/special_notes.spec.tsindex baefc4dd0a..5ff5efaf49 100644--- a/packages/trilium-core/src/services/special_notes.spec.ts+++ b/packages/trilium-core/src/services/special_notes.spec.ts@@ -158,7 +158,9 @@ describe("special_notes (core, real DB)", () => {});it("falls back to the day note when no #inbox label exists at the root", () => {- vi.spyOn(attributeService, "getNoteWithLabel").mockReturnValue(null);+ // A journal has to exist, or the capture stays at the top level instead.+ vi.spyOn(attributeService, "getNoteWithLabel").mockImplementation((name: string) =>+ name === "calendarRoot" ? becca.getNoteOrThrow("root").getChildNotes()[0] : null);// getDayNote may create the day note, so it needs a CLS context.const result = getContext().init(() => specialNotes.getInboxNote("2026-05-29"));@@ -202,7 +204,8 @@ describe("special_notes (core, real DB)", () => {});it("reports the day note without creating it", () => {- vi.spyOn(attributeService, "getNoteWithLabel").mockReturnValue(null);+ vi.spyOn(attributeService, "getNoteWithLabel").mockImplementation((name: string) =>+ name === "calendarRoot" ? becca.getNoteOrThrow("root").getChildNotes()[0] : null);const noteCountBefore = Object.keys(becca.notes).length;// No CLS context: reaching getDayNote() would need one, so this also proves it is@@ -211,16 +214,15 @@ describe("special_notes (core, real DB)", () => {expect(Object.keys(becca.notes).length).toBe(noteCountBefore);});- it("still reports the day note when the journal has been deleted, because the capture recreates it", () => {+ it("keeps a capture at the top level when the journal has been deleted, rather than rebuilding it", () => {// Nulls both labels this path consults, #inbox and #calendarRoot.vi.spyOn(attributeService, "getNoteWithLabel").mockReturnValue(null);+ const noteCountBefore = Object.keys(becca.notes).length;- expect(specialNotes.getInboxTarget()).toMatchObject({ kind: "dayNote" });-- // Not root: getInboxNote() rebuilds the calendar rather than falling back to it.- const created = getContext().init(() => specialNotes.getInboxNote("2026-05-29"));- expect(created.noteId).not.toBe("root");- expect(created.getParentNotes().some((p) => p.noteId === "root")).toBe(false);+ expect(specialNotes.getInboxTarget()).toMatchObject({ kind: "root", noteId: "root" });+ expect(specialNotes.getInboxNote("2026-05-29").noteId).toBe("root");+ // No calendar was built on the way.+ expect(Object.keys(becca.notes).length).toBe(noteCountBefore);});it("distinguishes the workspace inbox, a plain inbox and the workspace root", () => {diff --git a/packages/trilium-core/src/services/special_notes.ts b/packages/trilium-core/src/services/special_notes.tsindex cf86b78953..8bbcb12f4a 100644--- a/packages/trilium-core/src/services/special_notes.ts+++ b/packages/trilium-core/src/services/special_notes.ts@@ -48,7 +48,13 @@ function resolveInboxTarget(): { kind: InboxTargetKind; note?: BNote } {return { kind: "inbox", note: inbox };}- return { kind: "dayNote" };+ // Capturing a note is not a request for a journal, so a database without one keeps the note+ // at the top level rather than having a calendar built around it (#11034).+ if (dateNoteService.hasCalendarRoot()) {+ return { kind: "dayNote" };+ }++ return { kind: "root", note: workspaceNote };}function getInboxTarget(): InboxTargetResponse {