Skip to content

fix(dashboard): drop null sourceHandle/targetHandle before passing to React Flow (#330)#401

Open
tirth8205 wants to merge 1 commit into
Egonex-AI:mainfrom
tirth8205:fix/dashboard-react-flow-null-handle
Open

fix(dashboard): drop null sourceHandle/targetHandle before passing to React Flow (#330)#401
tirth8205 wants to merge 1 commit into
Egonex-AI:mainfrom
tirth8205:fix/dashboard-react-flow-null-handle

Conversation

@tirth8205

Copy link
Copy Markdown
Contributor

Summary

Closes #330. When a user searches for a node (e.g. login) and clicks
the first result, the dashboard freezes with:

[React Flow]: Couldn't create edge for source handle id: "null", edge id: e-35.

The freeze is caused by React Flow's error008 warning loop: every
frame, React Flow tries to resolve the missing handle, fails, logs the
warning, and re-renders — which re-fires the lookup. The dashboard
becomes unresponsive.

Root cause

Tracing through @xyflow/system's getEdgePosition (error008 site,
dist/esm/index.mjs:1380):

// xyflow/system source
const sourceHandle = getHandle$1(sourceHandleBounds?.source ?? [], params.sourceHandle);
// ...
if (!sourceHandle || !targetHandle) {
  params.onError?.('008', errorMessages['error008'](!sourceHandle ? 'source' : 'target', {
    id: params.id,
    sourceHandle: params.sourceHandle,
    targetHandle: params.targetHandle,
  }));
  return null;
}

getHandle$1 looks up a handle by id; when params.sourceHandle is the
string "null" (or coerces to "null" via template interpolation of
the JS null value), no handle matches and the error fires every
frame. The error message reports the failing id literally as "null",
which is exactly what the issue describes.

The dashboard's three React Flow views never explicitly set
sourceHandle / targetHandle. The bad value reaches React Flow when:

  • a graph JSON contains an edge with sourceHandle: "null" and that
    field somehow survives GraphEdgeSchema (which uses z.object's
    default strip behaviour — robust, but a future .passthrough() or
    hand-built React Flow edge could regress this);
  • React Flow's own edge state normalises a missing handle to literal
    null, which then gets template-interpolated into the same
    unresolvable "null" lookup.

Fix

Add a focused sanitizeFlowEdge / sanitizeFlowEdges helper at
src/utils/sanitizeFlowEdge.ts that strips sourceHandle /
targetHandle from a React Flow edge when the value is null,
undefined, "", "null", or "undefined". Stripping the field
entirely makes React Flow fall back to the node's default (first) handle
instead of looping on an unresolvable id.

Wire it into the boundary of every React Flow view in the dashboard:

  • GraphView.tsx — overview cluster edges + layer-detail composed
    edges (Stage 1 / inflated / portal edges + selection styling).
  • KnowledgeGraphView.tsx — knowledge-edge construction in the
    nodes/edges memo.
  • DomainGraphView.tsx — domain overview cross-domain + flow-step
    edges produced by ELK layout.

The helper returns the original edge / array reference when nothing
needs cleaning so memoised React Flow renders still see referential
equality and don't re-render unnecessarily.

Test plan

Unit test at
understand-anything-plugin/packages/dashboard/src/utils/__tests__/sanitizeFlowEdge.test.ts
covers:

  • isInvalidHandleValue flags null, undefined, "null",
    "undefined", "" as invalid and keeps real handle ids
    ("top", "0", numeric 1).
  • sanitizeFlowEdge strips a sourceHandle: "null" (matching the
    exact symptom of issue Dashboard freezes after selecting login result in search bar (React Flow edge source handle id: "null") #330) while preserving id, source,
    target, and unrelated fields (style, label, animated).
  • Same for literal null, targetHandle: "undefined", both
    invalid, and empty string.
  • Real handle ids (e.g. "right") round-trip by reference for memo
    stability.
  • sanitizeFlowEdges returns the same array reference when nothing
    needed cleaning, and a new array preserving clean references when
    any edge was mutated.

Reproduction sequence to verify the dashboard no longer freezes
(requires running the dashboard end-to-end, so calling out for human
sign-off):

  • pnpm install
  • pnpm --filter @understand-anything/core build
  • pnpm --filter @understand-anything/dashboard build
  • pnpm test
  • pnpm dev:dashboard against a project that produces the
    e-35-class error, search for login, click the first result,
    confirm the graph re-renders without the React Flow error008
    warning loop and without freezing.

🤖 Generated with Claude Code

… React Flow (Egonex-AI#330)

When a user clicks a search result whose target layer renders an edge
that points at a node with no matching handle id, React Flow logs

  [React Flow]: Couldn't create edge for source handle id: "null", edge id: e-35.

and the rendering loop hangs trying to re-resolve the missing handle
every frame.

Add `sanitizeFlowEdge` / `sanitizeFlowEdges` helpers that strip
`sourceHandle` / `targetHandle` when they hold `null`, `undefined`,
`""`, `"null"`, or `"undefined"` so React Flow's handle lookup falls
back to the node's default (first) handle. Apply it at the boundary of
the three React Flow views (`GraphView`, `KnowledgeGraphView`,
`DomainGraphView`) so neither stale graph JSON nor any future
edge-construction regression can hit the freeze.

Closes Egonex-AI#330

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dashboard freezes after selecting login result in search bar (React Flow edge source handle id: "null")

1 participant