From 7c490d8b72205c9482969c673431bd5454a0a5dd Mon Sep 17 00:00:00 2001 From: "Romain DEP." Date: Fri, 29 Aug 2025 01:57:18 +0200 Subject: [PATCH] fix(tree): defend against stray null values that may occur when multiple sorting overrides are defined fixes #6820 --- apps/server/src/services/tree.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/server/src/services/tree.ts b/apps/server/src/services/tree.ts index 71f432395..54013e895 100644 --- a/apps/server/src/services/tree.ts +++ b/apps/server/src/services/tree.ts @@ -133,6 +133,9 @@ function sortNotes(parentNoteId: string, customSortBy: string = "title", reverse const topBEl = fetchValue(b, "top"); if (topAEl !== topBEl) { + if (topAEl === null) return 1; + if (topBEl === null) return -1; + // since "top" should not be reversible, we'll reverse it once more to nullify this effect return compare(topAEl, topBEl) * (reverse ? -1 : 1); } @@ -141,6 +144,9 @@ function sortNotes(parentNoteId: string, customSortBy: string = "title", reverse const bottomBEl = fetchValue(b, "bottom"); if (bottomAEl !== bottomBEl) { + if (bottomAEl === null) return -1; + if (bottomBEl === null) return 1; + // since "bottom" should not be reversible, we'll reverse it once more to nullify this effect return compare(bottomBEl, bottomAEl) * (reverse ? -1 : 1); }