From a59d407f120dfd54e62cb05648162a32d8d8a3d2 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Thu, 20 Nov 2025 20:24:19 +0200 Subject: [PATCH] fix(print/list): note content not shown due to race condition --- .../collections/legacy/ListOrGridView.tsx | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx b/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx index 80087f584..811932128 100644 --- a/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx +++ b/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx @@ -1,4 +1,4 @@ -import { useEffect, useMemo, useRef, useState } from "preact/hooks"; +import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "preact/hooks"; import FNote from "../../../entities/fnote"; import Icon from "../../react/Icon"; import { ViewModeProps } from "../interface"; @@ -12,6 +12,7 @@ import link from "../../../services/link"; import { t } from "../../../services/i18n"; import attribute_renderer from "../../../services/attribute_renderer"; import froca from "../../../services/froca"; +import { RawHtmlBlock } from "../../react/RawHtml"; export function ListView({ note, noteIds: unfilteredNoteIds, highlightedTokens }: ViewModeProps<{}>) { const [ isExpanded ] = useNoteLabelBoolean(note, "expanded"); @@ -35,31 +36,43 @@ export function ListView({ note, noteIds: unfilteredNoteIds, highlightedTokens } ); } +interface NotesWithContent { + note: FNote; + content: string; +} + export function ListPrintView({ note, noteIds: unfilteredNoteIds, highlightedTokens, onReady }: ViewModeProps<{}>) { const noteIds = useFilteredNoteIds(note, unfilteredNoteIds); - const [ notes, setNotes ] = useState(); + const [ notesWithContent, setNotesWithContent ] = useState(); - useEffect(() => { - froca.getNotes(noteIds).then(setNotes); + useLayoutEffect(() => { + froca.getNotes(noteIds).then(async (notes) => { + const notesWithContent: NotesWithContent[] = []; + for (const note of notes) { + const content = await content_renderer.getRenderedContent(note, { + trim: false, + noChildrenList: true + }); + notesWithContent.push({ note, content: content.$renderedContent[0].innerHTML }); + } + setNotesWithContent(notesWithContent); + }); }, [noteIds]); useEffect(() => { - if (notes && onReady) { + if (notesWithContent && onReady) { onReady(); } - }, [ notes, onReady ]); + }, [ notesWithContent, onReady ]); return (