From 7c7797d35aa4f319fac8402a810a24f1f0cff7ba Mon Sep 17 00:00:00 2001 From: Wael Nasreddine Date: Thu, 25 Dec 2025 15:04:50 -0800 Subject: [PATCH 1/2] fix(share/prev_next): Prevent crashing if candide page is null When a note is not visible, attempting to export it ends up crashing the server with this error: ``` TypeError: ejs:193 191| 192| <% if (hasTree) { %> >> 193| <%- include("prev_next", { note: note, subRoot: subRoot }) %> 194| <% } %> 195| 196| ejs:1 >> 1| <% 2| // TODO: code cleanup + putting this behind a toggle/attribute 3| const previousNote = (() => { 4| // If we are at the subRoot, there is no previous Cannot read properties of undefined (reading 'hasVisibleChildren') at eval (eval at compile (/usr/src/app/main.cjs:553:203), :27:26) at eval (eval at compile (/usr/src/app/main.cjs:553:203), :34:7) at d (/usr/src/app/main.cjs:557:265) at g (/usr/src/app/main.cjs:557:251) at eval (eval at compile (/usr/src/app/main.cjs:553:203), :293:17) at d (/usr/src/app/main.cjs:557:265) at as.render (/usr/src/app/main.cjs:532:458) at Omr (/usr/src/app/main.cjs:581:109552) at Rmr (/usr/src/app/main.cjs:581:107637) at $W.prepareContent (/usr/src/app/main.cjs:653:28) { path: '' ``` fixes #8002 fixes #8162 --- packages/share-theme/src/templates/prev_next.ejs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/share-theme/src/templates/prev_next.ejs b/packages/share-theme/src/templates/prev_next.ejs index ea93cd336..ddc4919f8 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 = (() => { From cb016c4307107d3e7ea57df3b8cbfce0ef457bd0 Mon Sep 17 00:00:00 2001 From: Wael Nasreddine Date: Thu, 25 Dec 2025 16:26:58 -0800 Subject: [PATCH 2/2] Address Gemini's comment --- packages/share-theme/src/templates/prev_next.ejs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/share-theme/src/templates/prev_next.ejs b/packages/share-theme/src/templates/prev_next.ejs index ddc4919f8..38441d2c1 100644 --- a/packages/share-theme/src/templates/prev_next.ejs +++ b/packages/share-theme/src/templates/prev_next.ejs @@ -16,8 +16,13 @@ // should go to the end of the previous tree let candidate = children[index - 1]; while (candidate?.hasVisibleChildren()) { - const children = candidate.getVisibleChildNotes(); - candidate = children[children.length - 1]; + const visibleChildren = candidate.getVisibleChildNotes(); + + if (visibleChildren.length === 0) { + break; + } + + candidate = visibleChildren[visibleChildren.length - 1]; } return candidate ?? null;