Skip to content

Build your personal knowledge base with Trilium Notes

fix infinite cycle when template is descendant of an instance

zadam0040334e89f9
diff --git a/src/public/app/entities/note_short.js b/src/public/app/entities/note_short.js
index abccf5b87c..45b69d8fdb 100644
--- a/src/public/app/entities/note_short.js
+++ b/src/public/app/entities/note_short.js
@@ -493,11 +493,20 @@ class NoteShort {
});
}
- hasAncestor(ancestorNote) {
+ hasAncestor(ancestorNote, visitedNoteIds) {
if (this.noteId === ancestorNote.noteId) {
return true;
}
+ if (!visitedNoteIds) {
+ visitedNoteIds = new Set();
+ } else if (visitedNoteIds.has(this.noteId)) {
+ // to avoid infinite cycle when template is descendent of the instance
+ return false;
+ }
+
+ visitedNoteIds.add(this.noteId);
+
for (const templateNote of this.getTemplateNotes()) {
if (templateNote.hasAncestor(ancestorNote)) {
return true;