So my edges are not rendering (nodes work just fine), here are the checks that I have made:
- there is not any issue with id's, they are strings and they match the nodes ids
- the custom nodes work fine
- there is no issue with fitview (edges do not show even if I disable it)
- style to edges doesn't change anything
- my global.css has no impact
- the div containing the ReactFlow component is not a problem
here is the code for my graph:
const nodeTypes = {
problemNode: ProblemNode,
};
export default function PlanGraph(plan: Plan | undefined) {
const nodes: Node[] = [];
const edges: Edge[] = [];
let centerY = window.innerWidth / 2 - 800;
const centerX = window.innerWidth / 2 - 300;
plan?.problems.forEach((problem) => {
nodes.push({
id: problem[1].id.toString(),
type: "problemNode",
position: { x: centerX, y: centerY },
data: {
number: problem[1].id,
name: problem[1].name,
acceptanceRate: problem[1].acceptanceRate,
difficulty: problem[1].difficulty,
},
});
centerY += 125;
});
for (let i = 0; i < plan!.problems.length - 1; i++) {
const current = plan!.problems[i][1];
const next = plan!.problems[i + 1][1];
edges.push({
id: `${current.id}-${next.id}`,
source: current.id.toString(),
target: next.id.toString(),
style: { stroke: "#10B981", strokeWidth: 2, width: 12 },
});
}
return (
<ReactFlow
nodes={nodes}
edges={edges}
nodeTypes={nodeTypes}
fitView
></ReactFlow>
);
}
globals.css:
@import "tailwindcss";
@theme {
--color-white: #eeeeee;
--color-darkgrey: #222831;
--color-lightgrey: #3f444c;
--color-lightgreen: #76abae;
--color-orange: #ffa116;
}
customNode:
export default function ProblemNode({
data: { number, name, acceptanceRate, difficulty },
}: NodeProps<{
number: number;
name: string;
acceptanceRate: number;
difficulty: number;
}>) {
let borderColorClass: string;
switch (difficulty) {
case 0:
borderColorClass = "border-green-500";
break;
case 1:
borderColorClass = "border-orange-500";
break;
case 2:
borderColorClass = "border-red-500";
break;
default:
borderColorClass = "border-gray-500";
}
return (
<div
className={`bg-lightgrey border-2 ${borderColorClass} rounded-lg p-4 w-80`}
>
<p className="text-white font-semibold">
{number.toString() + ". " + name}
</p>
</div>
);
}
dependencies:
"dependencies": {
"next": "15.2.3",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-icons": "^5.5.0",
"reactflow": "^11.11.4"
},