Skip to content

Build your personal knowledge base with Trilium Notes

fix(share/prev_next): Prevent crashing if candide page is null

Wael Nasreddine7c7797d35aa4
diff --git a/packages/share-theme/src/templates/prev_next.ejs b/packages/share-theme/src/templates/prev_next.ejs
index ea93cd3362..ddc4919f86 100644
--- a/packages/share-theme/src/templates/prev_next.ejs
+++ b/packages/share-theme/src/templates/prev_next.ejs
@@ -15,13 +15,12 @@
// We are not the first child at this level so previous
// should go to the end of the previous tree
let candidate = children[index - 1];
- while (candidate.hasVisibleChildren()) {
+ while (candidate?.hasVisibleChildren()) {
const children = candidate.getVisibleChildNotes();
- const lastChild = children[children.length - 1];
- candidate = lastChild;
+ candidate = children[children.length - 1];
}
- return candidate;
+ return candidate ?? null;
})();
const nextNote = (() => {