diff --git a/src/public/app/entities/note_short.js b/src/public/app/entities/note_short.js index abccf5b87..45b69d8fd 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;