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

This commit is contained in:
Elian Doran 2026-01-08 16:50:27 +02:00
parent 3c168d750d
commit 4625efda7f
No known key found for this signature in database
4 changed files with 30 additions and 2 deletions

View File

@ -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>;
}

View File

@ -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({

View File

@ -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 });

View File

@ -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;