Skip to content

Build your personal knowledge base with Trilium Notes

fix(tree): expand a subtree below a note with very many children

Elian Dorana7fd11e42e8c
diff --git a/packages/trilium-core/src/routes/api/branches.spec.ts b/packages/trilium-core/src/routes/api/branches.spec.ts
index f75bbd8d65..0a4bf6cd41 100644
--- a/packages/trilium-core/src/routes/api/branches.spec.ts
+++ b/packages/trilium-core/src/routes/api/branches.spec.ts
@@ -331,6 +331,34 @@ describe("Branches API (core)", () => {
getContext().init(() => load());
}
});
+
+ it("expands a note with more children than a call can take as arguments", async () => {
+ const anchor = await createTextNote(api, { title: "Crowded anchor" });
+ const childCount = 200_000;
+ registerVirtualNoteProvider({
+ namespace: "_vbig",
+ parentNoteId: anchor.noteId,
+ getSubtree: () => [{
+ id: "_vbig",
+ title: "Crowded note",
+ type: "book",
+ children: Array.from({ length: childCount }, (_, index) => ({
+ id: `_vbig${index}`, title: `Child ${index}`, type: "text" as const
+ }))
+ }]
+ });
+
+ try {
+ getContext().init(() => load());
+
+ const res = await api.put<{ branchIds: string[] }>(`/api/branches/${anchor.noteId}__vbig/expanded-subtree/1`);
+ expect(res.status).toBe(200);
+ expect(res.body.branchIds).toHaveLength(childCount + 1);
+ } finally {
+ unregisterVirtualNoteProvider("_vbig");
+ getContext().init(() => load());
+ }
+ }, 60_000);
});
describe("prefixes", () => {
diff --git a/packages/trilium-core/src/routes/api/branches.ts b/packages/trilium-core/src/routes/api/branches.ts
index fbc8096a93..ae757b9b2b 100644
--- a/packages/trilium-core/src/routes/api/branches.ts
+++ b/packages/trilium-core/src/routes/api/branches.ts
@@ -192,7 +192,11 @@ function setExpandedForSubtree(req: Request<{ branchId: string, expanded: string
if (!visitedNoteIds.has(branch.noteId)) {
visitedNoteIds.add(branch.noteId);
- pending.push(...branch.childNote.getChildBranches().filter((child) => !!child));
+ for (const childBranch of branch.childNote.getChildBranches()) {
+ if (childBranch) {
+ pending.push(childBranch);
+ }
+ }
}
}