Skip to content

Build your personal knowledge base with Trilium Notes

fix(hidden_subtree): launcher branches created both in visible & available (closes #6537)

Elian Doran425ade52125e
diff --git a/apps/server/src/services/hidden_subtree.spec.ts b/apps/server/src/services/hidden_subtree.spec.ts
index 95c4c4318a..811aebe9b4 100644
--- a/apps/server/src/services/hidden_subtree.spec.ts
+++ b/apps/server/src/services/hidden_subtree.spec.ts
@@ -83,6 +83,23 @@ describe("Hidden Subtree", () => {
expect(updatedJumpToNote?.title).not.toBe("Renamed");
});
+ it("maintains launchers hidden, if they were shown by default but moved by the user", () => {
+ const launcher = becca.getNote("_lbLlmChat");
+ const branch = launcher?.getParentBranches()[0];
+ expect(branch).toBeDefined();
+ expect(branch!.parentNoteId).toBe("_lbVisibleLaunchers");
+ expect(launcher).toBeDefined();
+
+ cls.init(() => {
+ branches.moveBranchToNote(branch!, "_lbAvailableLaunchers");
+ hiddenSubtreeService.checkHiddenSubtree();
+ });
+
+ const newBranches = launcher?.getParentBranches().filter(b => !b.isDeleted);
+ expect(newBranches).toHaveLength(1);
+ expect(newBranches![0].parentNoteId).toBe("_lbAvailableLaunchers");
+ });
+
it("can restore names in all languages", async () => {
const done = deferred<void>();
cls.wrap(async () => {
diff --git a/apps/server/src/services/hidden_subtree.ts b/apps/server/src/services/hidden_subtree.ts
index ec69f0154a..22096ca2cf 100644
--- a/apps/server/src/services/hidden_subtree.ts
+++ b/apps/server/src/services/hidden_subtree.ts
@@ -356,20 +356,22 @@ function checkHiddenSubtreeRecursively(parentNoteId: string, item: HiddenSubtree
} else {
branch = note.getParentBranches().find((branch) => branch.parentNoteId === parentNoteId);
- // If the note exists but doesn't have a branch in the expected parent,
- // create the missing branch to ensure it's in the correct location
- if (!branch) {
- branch = new BBranch({
- noteId: item.id,
- parentNoteId: parentNoteId,
- notePosition: item.notePosition !== undefined ? item.notePosition : undefined,
- isExpanded: item.isExpanded !== undefined ? item.isExpanded : false
- }).save();
- }
-
// Clean up any branches that shouldn't exist according to the meta definition
// For hidden subtree notes, we want to ensure they only exist in their designated locations
if (item.enforceBranches || item.id.startsWith("_help")) {
+ // If the note exists but doesn't have a branch in the expected parent,
+ // create the missing branch to ensure it's in the correct location
+ if (!branch) {
+ console.log("Creating missing branch for note", item.id, "under parent", parentNoteId);
+ branch = new BBranch({
+ noteId: item.id,
+ parentNoteId: parentNoteId,
+ notePosition: item.notePosition !== undefined ? item.notePosition : undefined,
+ isExpanded: item.isExpanded !== undefined ? item.isExpanded : false
+ }).save();
+ }
+
+ // Remove any branches that are not in the expected parent.
const expectedParents = getExpectedParentIds(item.id, hiddenSubtreeDefinition);
const currentBranches = note.getParentBranches();