Browse Source
Replace broad state.nodes subscriptions in EditableEdge and ReferenceEdge with narrow Zustand selectors that return primitives, eliminating ~50 unnecessary edge re-renders per node interaction. Share gradient defs across all edges via SharedEdgeGradients (10 gradients vs 50+ per-edge defs). Replace SVG blur(6px) filter with layered semi-transparent strokes for loading glow, avoiding expensive filter evaluation on Windows. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>handoff-20260429-1057
7 changed files with 134 additions and 114 deletions
@ -0,0 +1,52 @@ |
|||
"use client"; |
|||
|
|||
// Shared SVG gradient definitions for all edge types.
|
|||
// Rendered once inside the React Flow SVG layer to avoid duplicating
|
|||
// <defs>/<linearGradient> in every edge component.
|
|||
|
|||
const EDGE_COLORS: Record<string, string> = { |
|||
image: "#0d9668", |
|||
prompt: "#2563eb", |
|||
default: "#64748b", |
|||
pause: "#ea580c", |
|||
reference: "#52525b", |
|||
}; |
|||
|
|||
const SELECTION_STATES = ["active", "dimmed"] as const; |
|||
|
|||
function gradientStops(color: string, active: boolean) { |
|||
return ( |
|||
<> |
|||
<stop offset="0%" stopColor={color} stopOpacity={active ? 1 : 0.25} /> |
|||
<stop offset="50%" stopColor={color} stopOpacity={active ? 0.55 : 0.1} /> |
|||
<stop offset="100%" stopColor={color} stopOpacity={active ? 1 : 0.25} /> |
|||
</> |
|||
); |
|||
} |
|||
|
|||
export function getSharedGradientId(colorKey: string, selectionKey: "active" | "dimmed") { |
|||
return `edge-grad-${colorKey}-${selectionKey}`; |
|||
} |
|||
|
|||
export function SharedEdgeGradients() { |
|||
return ( |
|||
<svg style={{ position: "absolute", width: 0, height: 0 }}> |
|||
<defs> |
|||
{Object.entries(EDGE_COLORS).flatMap(([colorKey, color]) => |
|||
SELECTION_STATES.map((sel) => ( |
|||
<linearGradient |
|||
key={`${colorKey}-${sel}`} |
|||
id={getSharedGradientId(colorKey, sel)} |
|||
x1="0%" |
|||
y1="0%" |
|||
x2="100%" |
|||
y2="0%" |
|||
> |
|||
{gradientStops(color, sel === "active")} |
|||
</linearGradient> |
|||
)) |
|||
)} |
|||
</defs> |
|||
</svg> |
|||
); |
|||
} |
|||
@ -1,2 +1,3 @@ |
|||
export { EditableEdge } from "./EditableEdge"; |
|||
export { ReferenceEdge } from "./ReferenceEdge"; |
|||
export { SharedEdgeGradients } from "./SharedEdgeGradients"; |
|||
|
|||
Loading…
Reference in new issue