Skip to content

Build your personal knowledge base with Trilium Notes

fix(note_list): skip rendering of included notes for performance (closes #8017)

Elian Doran4625efda7f61
diff --git a/apps/client/src/services/content_renderer.ts b/apps/client/src/services/content_renderer.ts
index 9b059101c7..38bb779ac6 100644
--- a/apps/client/src/services/content_renderer.ts
+++ b/apps/client/src/services/content_renderer.ts
@@ -23,6 +23,8 @@ export interface RenderOptions {
imageHasZoom?: boolean;
/** If enabled, it will prevent the default behavior in which an empty note would display a list of children. */
noChildrenList?: boolean;
+ /** If enabled, it will prevent rendering of included notes. */
+ noIncludedNotes?: boolean;
/** Set of note IDs that have already been seen during rendering to prevent infinite recursion. */
seenNoteIds?: Set<string>;
}
diff --git a/apps/client/src/services/content_renderer_text.spec.ts b/apps/client/src/services/content_renderer_text.spec.ts
index 3bd9b65540..6480e1991f 100644
--- a/apps/client/src/services/content_renderer_text.spec.ts
+++ b/apps/client/src/services/content_renderer_text.spec.ts
@@ -27,6 +27,27 @@ describe("Text content renderer", () => {
expect(contentEl.querySelectorAll("section.include-note p").length).toBe(1);
});
+ it("skips rendering included note", async () => {
+ const contentEl = document.createElement("div");
+ const includedNote = buildNote({
+ title: "Included note",
+ content: "<p>This is the included note.</p>"
+ });
+ const note = buildNote({
+ title: "New note",
+ content: trimIndentation`
+ <p>
+ Hi there
+ </p>
+ <section class="include-note" data-note-id="${includedNote.noteId}" data-box-size="medium">
+ &nbsp;
+ </section>
+ `
+ });
+ await renderText(note, $(contentEl), { noIncludedNotes: true });
+ expect(contentEl.querySelectorAll("section.include-note").length).toBe(0);
+ });
+
it("doesn't enter infinite loop on direct recursion", async () => {
const contentEl = document.createElement("div");
const note = buildNote({
diff --git a/apps/client/src/services/content_renderer_text.ts b/apps/client/src/services/content_renderer_text.ts
index 72d67d4d54..a3f277c492 100644
--- a/apps/client/src/services/content_renderer_text.ts
+++ b/apps/client/src/services/content_renderer_text.ts
@@ -18,7 +18,11 @@ export default async function renderText(note: FNote | FAttachment, $renderedCon
const seenNoteIds = options.seenNoteIds ?? new Set<string>();
seenNoteIds.add("noteId" in note ? note.noteId : note.attachmentId);
- await renderIncludedNotes($renderedContent[0], seenNoteIds);
+ if (!options.noIncludedNotes) {
+ await renderIncludedNotes($renderedContent[0], seenNoteIds);
+ } else {
+ $renderedContent.find("section.include-note").remove();
+ }
if ($renderedContent.find("span.math-tex").length > 0) {
renderMathInElement($renderedContent[0], { trust: true });
diff --git a/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx b/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx
index 8180e6d65c..9a0c7391db 100644
--- a/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx
+++ b/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx
@@ -153,7 +153,8 @@ function NoteContent({ note, trim, noChildrenList, highlightedTokens }: { note:
useEffect(() => {
content_renderer.getRenderedContent(note, {
trim,
- noChildrenList
+ noChildrenList,
+ noIncludedNotes: true
})
.then(({ $renderedContent, type }) => {
if (!contentRef.current) return;