From 34fc30b8dba5d3f95e7b17da744362cecd9af07a Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 30 Aug 2025 19:48:05 +0300 Subject: [PATCH] chore(react/collections): avoid intersection observer when not needed --- apps/client/src/widgets/collections/NoteList.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/client/src/widgets/collections/NoteList.tsx b/apps/client/src/widgets/collections/NoteList.tsx index 05ddc34fe..d8bfabf85 100644 --- a/apps/client/src/widgets/collections/NoteList.tsx +++ b/apps/client/src/widgets/collections/NoteList.tsx @@ -11,18 +11,23 @@ interface NoteListProps { highlightedTokens?: string[] | null; } -export default function NoteList({ note: providedNote, highlightedTokens }: NoteListProps) { +export default function NoteList({ note: providedNote, highlightedTokens, displayOnlyCollections }: NoteListProps) { const widgetRef = useRef(null); - const { note: contextNote } = useNoteContext(); + const { note: contextNote, noteContext } = useNoteContext(); const note = providedNote ?? contextNote; const viewType = useNoteViewType(note); const noteIds = useNoteIds(note, viewType); const isFullHeight = (viewType !== "list" && viewType !== "grid"); const [ isIntersecting, setIsIntersecting ] = useState(false); const shouldRender = (isFullHeight || isIntersecting); - const isEnabled = (note && !!viewType && shouldRender); + const isEnabled = (note && noteContext?.hasNoteList() && !!viewType && shouldRender); useEffect(() => { + if (isFullHeight || displayOnlyCollections) { + // Double role: no need to check if the note list is visible if the view is full-height, but also prevent legacy views if `displayOnlyCollections` is true. + return; + } + const observer = new IntersectionObserver( (entries) => { if (!isIntersecting) {