Skip to content

Build your personal knowledge base with Trilium Notes

fix(table_of_contents): not showing on first render of read-only notes

Elian Doranc23fe7cf1324
diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsx
index e3e750c4a6..215742046f 100644
--- a/apps/client/src/widgets/react/hooks.tsx
+++ b/apps/client/src/widgets/react/hooks.tsx
@@ -1177,7 +1177,7 @@ export function useContentElement(noteContext: NoteContext | null | undefined) {
const requestId = ++requestIdRef.current;
noteContext?.getContentElement().then(contentElement => {
// Prevent stale async.
- if (requestId !== requestIdRef.current) return;
+ if (!contentElement || requestId !== requestIdRef.current) return;
setContentElement(contentElement?.[0] ?? null);
forceUpdate(v => v + 1);
});