I wrote a tiny React Flow experiment with just three nodes. If I drag a diamond to the right of a circle, should the pink line still leave the circle at the bottom? Why does changing to a polyline add a patch of black at a bend? When debugging the edge, I like to draw a small circle at each endpoint first. Once the circles line up, I inspect the route and only then turn on the animation.1
How does an edge find its component and Handle?
Take the demo’s edge from circular node 2 to diamond node 3. An edge stores source: '2' and target: '3'. It can also use sourceHandle: 'c' and targetHandle: 'a' to select the start and end ports. The node component’s <Handle> elements name and position those ports. The edge’s type is a key in the edgeTypes map that chooses the rendering component. The demo registered ordinary and animated components for its two initial edges, but onConnect explicitly assigns the ordinary type when creating a new edge. Newly drawn connections therefore lack the pink animation by default.1
How does Simple Floating Edge pick endpoints, and why would a line go to the origin?
Built-in types such as straight and smoothstep specify a line shape. The official Simple Floating Edges is a custom-edge example. “Floating” means the connection can switch to a more suitable side when a node moves. Choosing endpoints and drawing a route between them are two calculations. My two projects preserve implementations worth comparing.2
| Approach | How endpoints are chosen | What happens after a drag |
|---|---|---|
Demo’s SimpleFloatingEdge | Map a/b/c/d to top/right/bottom/left, then read coordinates from the measured Handle. The older center-difference logic remains in comments | The initial edge specifies c → a, so even after passing the other node it still leaves the bottom and enters the top |
PuppyAgent’s FloatingEdge | Compare horizontal and vertical distances between centers. If horizontal is greater, use the facing left/right sides. Otherwise use top/bottom. Swap the nodes to compute the other end | Dragging the target from the source’s right to directly below it changes the departure direction |
| Use the coordinates React Flow supplies | The custom edge reads sourceX/Y, targetX/Y, and each endpoint’s Position from props | Let the library locate the endpoints and change only the route or appearance. Useful for graphs with explicit ports |
Redrawn using the two projects’ side-selection rules. A and B have the same relative positions in both diagrams. The endpoint algorithm determines the sides where the arrow leaves and enters.13
The demo declares all four Handles as sources and sets ConnectionMode.Loose on the canvas. When copying those Handles, also check the connection mode. Strict mode requires explicitly distinguishing source and target.12
I saw two different symptoms. Once the logs showed sx, sy, tx, ty all at 0. The path I pasted was M0 0L0 20L0 20L0 -20L0 -20L0 0. That is valid SVG syntax, but it only doubles back around the origin. The demo returns [0, 0] when it can’t find a Handle. Today I’d first check the Handle ID referenced by the edge, its type, and the measurements. Delay drawing until the node’s internal state is updated if it hasn’t been measured. After dynamically adding, removing, or moving ports, call the function returned by useUpdateNodeInternals to ask React Flow to remeasure.45
Another time the edge was visible but offset to the right of the Handle. Local Handle coordinates start at the upper-left corner of its bounding box. An SVG path needs canvas coordinates. For the center of a right-hand Handle’s outer edge, add the node’s absolute x, the Handle’s x, and its width. For y, add the node’s absolute y, the Handle’s y, and half its height. PuppyAgent also corrects for its node border spacing. The demo had added 5 or 10 pixels in its direction branches and then another 5 to both endpoint x coordinates when calling the path function. Start by drawing circles at the calculated ends. If the circles miss, changing the corner radius is beside the point. With multiple ports on one side, find the Handle by ID. Taking the first match by direction can connect to the wrong port.13
Which layer should I change to alter the routing algorithm?
Once the endpoints line up, sourcePosition and targetPosition tell the path function which sides to leave and approach. The first item returned by getSmoothStepPath is the SVG path string. getBezierPath makes a curve. PuppyAgent’s FloatingEdge passes borderRadius: 50 for rounded polylines and reserves 10 pixels in the target direction for one arrowed edge type. Those settings control the corner shape and arrow landing position respectively.36
If both directions are known, you can write the router yourself. Here’s a teaching example adapted from the demo. It assumes a source’s right edge connects to a target’s left edge and the target is to the right. Put a vertical channel halfway between the x coordinates and draw horizontal, vertical, and horizontal segments with H and V. Passing (20, 40) and (180, 100) gives M 20 40 H 100 V 100 H 180. Move the target and the midpoint and route update together.6
function ChannelEdge({ id, sourceX, sourceY, targetX, targetY, markerEnd }) {
const midX = (sourceX + targetX) / 2
const path = `M ${sourceX} ${sourceY} H ${midX} V ${targetY} H ${targetX}`
return <BaseEdge id={id} path={path} markerEnd={markerEnd} />
}
Drag the target to the left of the source and this simplified algorithm’s first segment heads left, back through the source node. To support that layout, first leave a short exit along each endpoint’s outward normal, then pick turning points outside the nodes. To avoid a third node, the algorithm also needs obstacle bounds. A function that sees only the start and end cannot tell what’s between them.
Another detail sent me checking the coordinates for nothing. I pasted <path id="1-2" path="M…"> from the browser and asked why its dimensions were 0 × 0. React Flow’s BaseEdge accepts a path prop, but a native SVG <path> reads its geometry from d. Pass the same string as <BaseEdge path={edgePath} /> or <path d={edgePath} fill="none" stroke="currentColor" /> for the corresponding layer. When inspecting the DOM, verify a valid d before continuing to adjust coordinates.46
On December 30, 2024, I looked at the official Editable Edge example. It lets users drag control points on the edge to alter the route. If A → B crosses text on a card, for example, leave the end Handles in place and drag a middle bend beneath the text. To restore that bend after saving a workflow, save the control point positions in the edge data. Changing only the current SVG’s d lets the next render recalculate from the endpoints and restore the old route.7
How can the line route around a third node between the endpoints?
On December 30, 2024, I searched for reactflow self edge and opened issue #1014 on connecting a node back to itself. From the discussion I opened the npm page for @tisoap/react-flow-smart-edge. A self-loop needs a route back to its own node. The package author was describing avoiding other nodes along a path. tisoap’s wording was “a custom edge that never intersects with other nodes”. For example, with A and B side by side, drag C between them and A → B should go around C’s bounds. Whether it also avoids crossing another edge D → E depends on whether existing edges are constraints for the router.8
This answered my question about custom drawing. The package docs already separated two steps in 2023. generatePath finds a sequence of traversable grid points, and drawEdge draws them as an SVG path. nodePadding leaves clearance and gridRatio sets the cell size. Finer cells represent narrower passages but increase the number of cells to search. Published implementations included A* with and without diagonal moves and jump point search without diagonals. To change which side of C the route takes, change pathfinding. Rounding a corner changes the appearance of the same route.9
Both the demo’s animated branch and PuppyAgent’s FloatingEdge retained an implementation that selects two endpoints and calls getSmoothStepPath. Smart Edge was a separate obstacle-avoidance option I found.13
Why does a black patch appear where the pink progress line bends?
On January 5 I changed my request from pink flashing to “i want pink solid line filling the existing solid line from 0% to 100%”. Later I reported that the animation worked but a black area appeared between the polyline and its endpoints at bends. This is an instructive SVG detail: when filling an open path, SVG computes the interior as if the end and start were connected. A straight line has almost no area, but several bends can enclose a large patch. The progress line only needs a stroke. Explicitly set fill="none" on both lines.1011
The historical commit names the animated path 2-3-filling. Its CSS decreased stroke-dashoffset from 1000 to 0 over two seconds and repeated. A second transparent path of the same shape with width 20 made the thin line easier to click. That version kept the animation line and transparent hit area. To keep the unfinished portion visibly gray, draw a separate visible base line. The following three-layer version is adapted to that requirement.111
<g>
<path d={d} fill="none" stroke="#aaa" strokeWidth={3} />
<path d={d} fill="none" stroke="#f57dbd" strokeWidth={3}
pathLength={1} strokeDasharray="1 1" className="edge-progress"
pointerEvents="none" />
<path d={d} fill="none" stroke="transparent" strokeWidth={20}
pointerEvents="stroke" />
</g>
.edge-progress { animation: fill-edge 2s linear infinite; }
@keyframes fill-edge {
from { stroke-dashoffset: 1; }
to { stroke-dashoffset: 0; }
}
All three layers share the same d, so they stay aligned through bends. pathLength={1} normalizes stroke distance, and edges of different lengths can cover the entire path with an offset going from 1 to 0. A two-second loop suits “running”. To show an actual task at 60% completion, remove the loop and use application progress to control the offset directly, for example 1 - 0.6.11
In this demo, dragging the diamond changes the whole polyline, and the pink stroke has to follow the new route from circle to diamond. A different symptom, where the line connects correctly but a configuration menu can’t read the target node, sends me to inspect which edges the canvas stored. I wrote up that repair in Why the configuration menu didn’t update after dragging a connection.
References
Footnotes
-
CaiBorui. (2025, January 2–5). reactflowtest/vite-project [独立本地 Git 仓库]。提交
91bafaf保存自定义浮动边,5be1d44增加菱形节点,分支feat-animated-loading-effect-edge的929d243保存动画。主要文件为src/App.jsx、src/customEdges/SimpleFloatingEdge.jsx、SimpleFloatingEdgeAnimated.jsx和src/xy-theme.css。文章日期取浮动边首次提交日,后续案例按实际日期叙述。2026 年 11 月 18 日用本地依赖重新构建动画分支,并在 Chrome 中核对了两种边的 SVG 路径和透明命中区。 ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 -
xyflow. (n.d.). Simple floating edges;Floating edges. React Flow. 按节点相对位置选 Handle;计算与节点轮廓交点的版本。 本地 Firefox 记录中,2025 年 1 月 1 日打开过 StackBlitz 示例的 SimpleFloatingEdge.jsx 和 utils.js,1 月 2 日先后访问了 Custom Edges、getSmoothStepPath 和 useInternalNode。 ↩ ↩2
-
PuppyAgent contributors. (2025, February 21). PuppyFlow [历史代码快照,提交
697caa0c]. GitHub. 端点算法;已连接边的路径与箭头。 ↩ ↩2 ↩3 ↩4 -
CaiBorui. (2025, January 2). Fixing Zustand Provider Error in React Flow [与 Cursor 的未公开开发对话]。零坐标日志、端点偏移及原生 SVG 元素见消息 11–23。 ↩ ↩2
-
xyflow. (n.d.). useUpdateNodeInternals. React Flow. 动态更新 Handle 的示例. ↩
-
xyflow. (n.d.). Custom edges. React Flow. BaseEdge、路径生成函数与自定义 SVG 路径. ↩ ↩2 ↩3
-
xyflow. (n.d.). Editable edge [Pro 示例公开说明]. React Flow. 拖动控制点修改路径。Gorzo, P., & Thompson, H. (2024, April 11). We finally made an editable edge Pro example. React Flow. ↩
-
tisoap. (n.d.). Comment on “Circular Connection (Loop back) to same element?” [GitHub issue #1014,评论正文首段]. GitHub. 原讨论、作者介绍避障包的评论;npm 包。Firefox 本地访问记录(北京时间):2024 年 12 月 30 日 15:32 搜索自环,15:33 访问 issue,15:34 从 issue 进入 npm 页面。 ↩
-
tisoap. (2023, September 14). React Flow Smart Edge [README 历史快照,
cb92677]. GitHub.generatePath的寻路选项;drawEdge的绘制选项。 ↩ -
CaiBorui. (2025, January 5). Animated Pink Edge Creation [与 Cursor 的未公开开发对话,会话
c025f179-ea04-4f76-8dd2-4147e85908be]。引文为第 4 次用户发言,拐弯出现黑色填充见第 7 次用户发言。 ↩ -
MDN contributors. (n.d.). fill;pathLength. MDN Web Docs. 开放图形的填充;路径长度及描边距离。 ↩ ↩2 ↩3