Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Fix: Self-referencing data returned by the API causes the mind map page to freeze. (#19720)

balibabu26a1b76f4f3f
diff --git a/web/src/components/structure-graph/adapters.test.ts b/web/src/components/structure-graph/adapters.test.ts
index 0b999e664c..77ef4e5717 100644
--- a/web/src/components/structure-graph/adapters.test.ts
+++ b/web/src/components/structure-graph/adapters.test.ts
@@ -1,4 +1,8 @@
-import { findEntityDisplayNameByKeyword } from './adapters';
+import { CompilationTemplateKind } from '@/constants/compilation';
+import {
+ adaptMindMapToIndentedTree,
+ findEntityDisplayNameByKeyword,
+} from './adapters';
describe('findEntityDisplayNameByKeyword', () => {
const entities = [
@@ -27,3 +31,29 @@ describe('findEntityDisplayNameByKeyword', () => {
expect(findEntityDisplayNameByKeyword([], 'swallow')).toBe('');
});
});
+
+describe('adaptMindMapToIndentedTree', () => {
+ it('ignores self-referencing relations instead of hanging the tree build', () => {
+ // Regression: a `root -> root` relation recorded root as its own parent,
+ // and the cycle-avoidance walk then spun on it forever — the mind map
+ // stayed on the loading skeleton. The self-loop must be skipped and the
+ // remaining relations still attach normally.
+ const tree = adaptMindMapToIndentedTree({
+ kind: CompilationTemplateKind.MindMap,
+ template_id: 't1',
+ template_name: 'mindmap',
+ entities: [{ name: 'root' }, { name: 'child a' }, { name: 'child b' }],
+ relations: [
+ { from: 'root', to: 'root', type: 'related' },
+ { from: 'root', to: 'child a', type: 'related' },
+ { from: 'root', to: 'child b', type: 'related' },
+ ],
+ });
+
+ expect(tree.id).toBe('root');
+ expect(tree.children?.map((child) => child.id)).toEqual([
+ 'child a',
+ 'child b',
+ ]);
+ });
+});
diff --git a/web/src/components/structure-graph/adapters.tsx b/web/src/components/structure-graph/adapters.tsx
index c285a00caa..5b9bef3d36 100644
--- a/web/src/components/structure-graph/adapters.tsx
+++ b/web/src/components/structure-graph/adapters.tsx
@@ -165,6 +165,11 @@ function buildUniqueTreeDataItems(
for (const relation of relations ?? []) {
if (!relationTypes.includes(relation.type ?? '')) continue;
+ // Self-referencing relation records the node as its own parent, and the
+ // cycle walk below then spins on it forever (cursor never advances).
+ // This is a backend data integrity issue but we defend against it in the
+ // frontend so the UI never hangs.
+ if (relation.from === relation.to) continue;
const parent = map.get(relation.from);
const child = map.get(relation.to);