fix: edge animation

This commit is contained in:
2026-03-12 20:45:40 +01:00
parent fb1df18256
commit 92fdba7eef
2 changed files with 7 additions and 16 deletions

View File

@@ -14,8 +14,8 @@ function setToStableKey(s: Set<string>): string {
export type EdgeLike = { source: string; target: string }
/** Minimum time (ms) the connection ant trail runs when a path update is in progress. */
const CONNECTION_PATH_UPDATE_MIN_MS = 1500
/** Short tail (ms) after last updating node ends so the path doesn't vanish instantly. */
const CONNECTION_PATH_UPDATE_TAIL_MS = 200
export type UseCanvasConnectionPathResult = {
connectionPathUpdatingNodeIds: string[]
@@ -41,7 +41,6 @@ export function useCanvasConnectionPath(edges: EdgeLike[]): UseCanvasConnectionP
const [connectionPathErrorNodeIds, setConnectionPathErrorNodeIds] = useState<string[]>([])
const pathUpdateNodeIdsRef = useRef<Set<string>>(new Set())
const pathUpdateStartTimeRef = useRef<number | null>(null)
const pathUpdateEndTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null)
const connectionPathPausedNodeIdsRef = useRef<string[]>([])
connectionPathPausedNodeIdsRef.current = connectionPathPausedNodeIds
@@ -61,7 +60,6 @@ export function useCanvasConnectionPath(edges: EdgeLike[]): UseCanvasConnectionP
const ref = pathUpdateNodeIdsRef.current
ref.add(nodeId)
if (ref.size === 1) {
pathUpdateStartTimeRef.current = Date.now()
if (pathUpdateEndTimeoutRef.current != null) {
clearTimeout(pathUpdateEndTimeoutRef.current)
pathUpdateEndTimeoutRef.current = null
@@ -77,17 +75,10 @@ export function useCanvasConnectionPath(edges: EdgeLike[]): UseCanvasConnectionP
setConnectionPathUpdatingNodeIds(Array.from(ref))
return
}
const startedAt = pathUpdateStartTimeRef.current ?? 0
const elapsed = Date.now() - startedAt
const remaining = Math.max(0, CONNECTION_PATH_UPDATE_MIN_MS - elapsed)
if (remaining === 0) {
clearPathUpdateSession()
} else {
pathUpdateEndTimeoutRef.current = setTimeout(() => {
pathUpdateEndTimeoutRef.current = null
clearPathUpdateSession()
}, remaining)
}
}, CONNECTION_PATH_UPDATE_TAIL_MS)
}, [clearPathUpdateSession])
const addConnectionPathTrigger = useCallback((nodeId: string) => {

View File

@@ -143,11 +143,11 @@ body {
fill: none;
stroke-dasharray: 8 6;
stroke-dashoffset: 0;
animation: edge-flow 1.2s linear infinite;
animation: edge-flow 0.5s linear infinite;
will-change: stroke-dashoffset;
transform: translateZ(0);
backface-visibility: hidden;
transition: stroke 0.4s ease-out;
transition: stroke 0.2s ease-out;
}
.react-flow__edge path.animated-edge-path.animated-edge-path--updating,