Skip to content

Build your personal knowledge base with Trilium Notes

fix(type_widgets/relation_map): map emptied when switching fast

Elian Dorand4194c503c14
diff --git a/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx b/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx
index 8ecabacfe2..a13467d6fe 100644
--- a/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx
+++ b/apps/client/src/widgets/type_widgets/relation_map/RelationMap.tsx
@@ -211,7 +211,8 @@ async function useRelationData(noteId: string, mapData: MapData | undefined, map
const [ inverseRelations, setInverseRelations ] = useState<RelationMapPostResponse["inverseRelations"]>();
async function refresh() {
- if (!noteIds) return;
+ const api = mapApiRef.current;
+ if (!noteIds || !api) return;
const data = await server.post<RelationMapPostResponse>("relation-map", { noteIds, relationMapNoteId: noteId });
const relations: ClientRelation[] = [];
@@ -238,8 +239,8 @@ async function useRelationData(noteId: string, mapData: MapData | undefined, map
}
setRelations(relations);
- mapApiRef.current?.loadRelations(relations);
- mapApiRef.current?.cleanupOtherNotes(Object.keys(data.noteTitles));
+ api.loadRelations(relations);
+ api.cleanupOtherNotes(Object.keys(data.noteTitles));
}
useEffect(() => {