fix(dashboard): drop null sourceHandle/targetHandle before passing to React Flow (#330)#401
Open
tirth8205 wants to merge 1 commit into
Open
Conversation
… 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #330. When a user searches for a node (e.g.
login) and clicksthe first result, the dashboard freezes with:
The freeze is caused by React Flow's
error008warning loop: everyframe, 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'sgetEdgePosition(error008site,dist/esm/index.mjs:1380):getHandle$1looks up a handle by id; whenparams.sourceHandleis thestring
"null"(or coerces to"null"via template interpolation ofthe JS
nullvalue), no handle matches and the error fires everyframe. 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:sourceHandle: "null"and thatfield somehow survives
GraphEdgeSchema(which usesz.object'sdefault strip behaviour — robust, but a future
.passthrough()orhand-built React Flow edge could regress this);
null, which then gets template-interpolated into the sameunresolvable
"null"lookup.Fix
Add a focused
sanitizeFlowEdge/sanitizeFlowEdgeshelper atsrc/utils/sanitizeFlowEdge.tsthat stripssourceHandle/targetHandlefrom a React Flow edge when the value isnull,undefined,"","null", or"undefined". Stripping the fieldentirely 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 composededges (Stage 1 / inflated / portal edges + selection styling).
KnowledgeGraphView.tsx— knowledge-edge construction in thenodes/edgesmemo.DomainGraphView.tsx— domain overview cross-domain + flow-stepedges 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.tscovers:
isInvalidHandleValueflagsnull,undefined,"null","undefined",""as invalid and keeps real handle ids(
"top","0", numeric1).sanitizeFlowEdgestrips asourceHandle: "null"(matching theexact 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).null,targetHandle: "undefined", bothinvalid, and empty string.
"right") round-trip by reference for memostability.
sanitizeFlowEdgesreturns the same array reference when nothingneeded 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 installpnpm --filter @understand-anything/core buildpnpm --filter @understand-anything/dashboard buildpnpm testpnpm dev:dashboardagainst a project that produces thee-35-class error, search forlogin, click the first result,confirm the graph re-renders without the React Flow
error008warning loop and without freezing.
🤖 Generated with Claude Code