| name | react-flow-code-review |
| description | Reviews React Flow code for anti-patterns, performance issues, and best practices. Use when reviewing code that uses @xyflow/react, checking for common mistakes, or optimizing node-based UI implementations. |
React Flow Code Review
When reviewing React Flow code, complete the gates below in order. Each step has an objective pass condition before moving on.
Review gates (sequenced)
-
Locate flow code — Search the review scope for ReactFlow, ReactFlowProvider, useReactFlow, @xyflow/react, nodeTypes, and edgeTypes. Pass: a short list of file paths (or explicit “none in scope” after searching).
-
Provider boundary — For each useReactFlow() (and other hooks that require the provider), trace the component tree to an enclosing ReactFlowProvider, or record a concrete mismatch with file:line.
-
Stable types and memo surfaces — For each custom node or edge component, note whether it uses memo and typed props (NodeProps<...>, etc.). For each nodeTypes / edgeTypes value passed into <ReactFlow>, confirm a stable reference (module scope, or useMemo with deps you can point to) or flag unstable recreation with file:line.
-
Report with evidence — For each finding you will deliver, record file path and line number(s) (or a minimal quoted snippet). Pass: no critical or high-severity issue is stated without that citation.
-
Close the checklists — Use Performance Checklist and Common Mistakes; each item is satisfied, not applicable (with reason), or open with evidence. Pass: no item left silently ambiguous.
Critical Anti-Patterns
1. Defining nodeTypes/edgeTypes Inside Components
Problem: Causes all nodes to re-mount on every render.
function Flow() {
const nodeTypes = { custom: CustomNode };
return <ReactFlow nodeTypes={nodeTypes} />;
}
const nodeTypes = { custom: CustomNode };
function Flow() {
return <ReactFlow nodeTypes={nodeTypes} />;
}
function Flow() {
const nodeTypes = useMemo(() => ({ custom: CustomNode }), []);
return <ReactFlow nodeTypes={nodeTypes} />;
}
2. Missing memo() on Custom Nodes/Edges
Problem: Custom components re-render on every parent update.
function CustomNode({ data }: NodeProps) {
return <div>{data.label}</div>;
}
import { memo } from 'react';
const CustomNode = memo(function CustomNode({ data }: NodeProps) {
return <div>{data.label}</div>;
});
3. Inline Callbacks Without useCallback
Problem: Creates new function references, breaking memoization.
<ReactFlow
onNodesChange={(changes) => setNodes(applyNodeChanges(changes, nodes))}
/>
const onNodesChange = useCallback(
(changes) => setNodes((nds) => applyNodeChanges(changes, nds)),
[]
);
<ReactFlow onNodesChange={onNodesChange} />
4. Using useReactFlow Outside Provider
function App() {
const { getNodes } = useReactFlow();
return <ReactFlow ... />;
}
function FlowContent() {
const { getNodes } = useReactFlow();
return <ReactFlow ... />;
}
function App() {
return (
<ReactFlowProvider>
<FlowContent />
</ReactFlowProvider>
);
}
5. Storing Complex Objects in Node Data
Problem: Reference equality checks fail, causing unnecessary updates.
setNodes(nodes.map(n => ({
...n,
data: { ...n.data, config: { nested: 'value' } }
})));
const { updateNodeData } = useReactFlow();
updateNodeData(nodeId, { config: { nested: 'value' } });
Performance Checklist
Node Rendering
Edge Rendering
State Updates
Viewport
Common Mistakes
Missing Container Height
<ReactFlow nodes={nodes} edges={edges} />
<div style={{ width: '100%', height: '100vh' }}>
<ReactFlow nodes={nodes} edges={edges} />
</div>
Missing CSS Import
import '@xyflow/react/dist/style.css';
Forgetting nodrag on Interactive Elements
<button onClick={handleClick}>Click</button>
<button className="nodrag" onClick={handleClick}>Click</button>
Not Using Position Constants
<Handle type="source" position="right" />
import { Position } from '@xyflow/react';
<Handle type="source" position={Position.Right} />
Mutating Nodes/Edges Directly
nodes[0].position = { x: 100, y: 100 };
setNodes(nodes);
setNodes(nodes.map(n =>
n.id === '1' ? { ...n, position: { x: 100, y: 100 } } : n
));
TypeScript Issues
Missing Generic Types
const [nodes, setNodes] = useNodesState(initialNodes);
type MyNode = Node<{ value: number }, 'custom'>;
const [nodes, setNodes] = useNodesState<MyNode>(initialNodes);
Wrong Props Type
function CustomNode(props: any) { ... }
function CustomNode(props: NodeProps<MyNode>) { ... }
Review Questions
- Are all custom components memoized?
- Are nodeTypes/edgeTypes defined outside render?
- Are callbacks wrapped in useCallback?
- Is the container sized properly?
- Are styles imported?
- Is useReactFlow used inside a provider?
- Are interactive elements marked with nodrag?
- Are types used consistently throughout?