Skip to content
@pyreon/flow
fundamentals · diagrams

Drag one node. Nothing else re-renders.

Node editors and diagrams on signals: nodes, edges, handles, pan and zoom, a minimap and seven layout algorithms, all built in. Each custom node mounts once and updates in place, and it beat React Flow 12 on all six operations we timed.

bun add @pyreon/flow
Documentation
vs React Flow 12
6 of 6 operations won500 nodes, 499 edges, one run
drag a node ×60
7.25× faster4.42 vs 32.05 ms
auto-layout
7 algorithms built inno dagre, no elkjs, code-split
iOS and Android
native SwiftUI and Compose hostexperimental
The Flow Editor from the Pyreon example app: a four-node workflow (Webhook trigger, Errors only filter, Enrich transform, PagerDuty notify) on a dotted canvas with zoom controls and a minimap, next to the same graph as editable JSON.The Flow Editor from the Pyreon example app: a four-node workflow (Webhook trigger, Errors only filter, Enrich transform, PagerDuty notify) on a dotted canvas with zoom controls and a minimap, next to the same graph as editable JSON.
  • 7.25× faster than React Flow 12 to drag a node through 60 moves in a 500-node graph (4.42 vs 32.05 ms).BENCHMARKS.md §2, Flow vs React Flow 12, final pass, one run, real Chromium, M3 Max
  • 5.39× faster to select a node (188 µs vs 1.01 ms).BENCHMARKS.md §2, Flow vs React Flow 12, one run
  • 0 extra runs of a custom node component when it is dragged, selected or given new data.packages/fundamentals/flow/src/tests/node-reactivity.test.ts ("custom node factory runs exactly once across …")

synthetic · author-run · M3 Max · record of 2026-11-05

Every result, including where we lose →
why teams pick it

For workflow builders, pipelines and whiteboards.

  1. Every node mounts once

    A custom node gets accessors (data(), selected(), dragging()), not values. Dragging one node runs zero updates on the nodes and edges it does not touch, and the tests count them.

  2. Layout in the box

    flow.layout() runs layered, force, stress, tree, radial, box or rect-packing layouts on each node's measured size. No dagre, no elkjs; the engine loads on first use.

  3. Connections without plumbing

    Drop a handle on a handle and the edge exists. isValidConnection vetoes, connectionRadius snaps a near miss, and edges attach to the measured handle dots.

  4. Editor chores, done

    Undo and redo (50 steps by default), copy and paste, sub-flows, keyboard access, and toJSON / fromJSON that treats loaded data as untrusted.

the difference

The state hooks go. The change handlers go.

React + React Flow 12

Two state hooks, two change handlers and a memoised connect callback, all to let the user drag and connect.

import { useCallback } from 'react'
import { Background, Controls, MiniMap, ReactFlow, addEdge, useEdgesState, useNodesState } from '@xyflow/react'
import type { Connection } from '@xyflow/react'
import '@xyflow/react/dist/style.css'

const initialNodes = [
  { id: '1', position: { x: 0, y: 0 }, data: { label: 'Start' } },
  { id: '2', position: { x: 200, y: 100 }, data: { label: 'End' } },
]
const initialEdges = [{ id: 'e1-2', source: '1', target: '2' }]

export function Diagram() {
  const [nodes, , onNodesChange] = useNodesState(initialNodes)
  const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges)
  const onConnect = useCallback((c: Connection) => setEdges((eds) => addEdge(c, eds)), [setEdges])

  return (
    <div style={{ height: 400 }}>
      <ReactFlow
        nodes={nodes}
        edges={edges}
        onNodesChange={onNodesChange}
        onEdgesChange={onEdgesChange}
        onConnect={onConnect}
        fitView
      >
        <Background />
        <Controls />
        <MiniMap />
      </ReactFlow>
    </div>
  )
}
with @pyreon/flow

The instance owns its nodes and edges as signals. Dragging, selecting and connecting update it directly.

import { Background, Controls, Flow, MiniMap, createFlow } from '@pyreon/flow'

const flow = createFlow({
  nodes: [
    { id: '1', position: { x: 0, y: 0 }, data: { label: 'Start' } },
    { id: '2', position: { x: 200, y: 100 }, data: { label: 'End' } },
  ],
  edges: [{ source: '1', target: '2' }],
  fitView: true,
})

// Dropping a connection adds the edge. Dragging moves the node. Nothing to wire.
export const Diagram = () => (
  <div style="height: 400px">
    <Flow instance={flow}>
      <Background />
      <Controls />
      <MiniMap />
    </Flow>
  </div>
)
coming from

Coming from React Flow?

Drag, connect, minimap: no handlers to write.

React Flow
import { useCallback } from 'react'
import { Background, Controls, MiniMap, ReactFlow, addEdge, useEdgesState, useNodesState } from '@xyflow/react'
import type { Connection } from '@xyflow/react'
import '@xyflow/react/dist/style.css'

const initialNodes = [
  { id: '1', position: { x: 0, y: 0 }, data: { label: 'Start' } },
  { id: '2', position: { x: 200, y: 100 }, data: { label: 'End' } },
]
const initialEdges = [{ id: 'e1-2', source: '1', target: '2' }]

export function Diagram() {
  const [nodes, , onNodesChange] = useNodesState(initialNodes)
  const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges)
  const onConnect = useCallback((c: Connection) => setEdges((eds) => addEdge(c, eds)), [setEdges])

  return (
    <div style={{ height: 400 }}>
      <ReactFlow
        nodes={nodes}
        edges={edges}
        onNodesChange={onNodesChange}
        onEdgesChange={onEdgesChange}
        onConnect={onConnect}
        fitView
      >
        <Background />
        <Controls />
        <MiniMap />
      </ReactFlow>
    </div>
  )
}
Pyreon

The component names are the ones you know (Background, Controls, MiniMap, Handle, NodeResizer). The difference is ownership: the flow instance holds nodes and edges as signals, so a drop on a handle adds the edge and fires onConnect for you to observe, not to implement.

import { Background, Controls, Flow, MiniMap, createFlow } from '@pyreon/flow'

const flow = createFlow({
  nodes: [
    { id: '1', position: { x: 0, y: 0 }, data: { label: 'Start' } },
    { id: '2', position: { x: 200, y: 100 }, data: { label: 'End' } },
  ],
  edges: [{ source: '1', target: '2' }],
  fitView: true,
})

// Dropping a connection adds the edge. Dragging moves the node. Nothing to wire.
export const Diagram = () => (
  <div style="height: 400px">
    <Flow instance={flow}>
      <Background />
      <Controls />
      <MiniMap />
    </Flow>
  </div>
)

Custom nodes without memo.

React Flow
import { memo } from 'react'
import { Handle, Position, ReactFlow, useNodesState, useReactFlow } from '@xyflow/react'
import type { Node, NodeProps } from '@xyflow/react'

type TaskNode = Node<{ label: string; status: 'todo' | 'done' }, 'task'>

// React Flow's docs recommend memo for custom nodes.
const TaskNodeView = memo(({ data, selected }: NodeProps<TaskNode>) => (
  <div className={selected ? 'task selected' : 'task'}>
    <Handle type="target" position={Position.Left} />
    {data.label}
    {data.status === 'done' ? ' (done)' : ''}
    <Handle type="source" position={Position.Right} />
  </div>
))

// Defined outside the component, or React Flow warns and remounts every node.
const nodeTypes = { task: TaskNodeView }

function FinishButton() {
  const { updateNodeData } = useReactFlow<TaskNode>()
  return <button onClick={() => updateNodeData('t1', { status: 'done' })}>Mark done</button>
}

export function Board() {
  const [nodes, , onNodesChange] = useNodesState<TaskNode>([
    { id: 't1', type: 'task', position: { x: 0, y: 0 }, data: { label: 'Write spec', status: 'todo' } },
  ])
  return (
    <ReactFlow nodes={nodes} onNodesChange={onNodesChange} nodeTypes={nodeTypes}>
      <FinishButton />
    </ReactFlow>
  )
}
Pyreon

A Pyreon node renderer runs once per node for the life of the graph. It reads props.data() and props.selected() where it renders them, so updateNode patches the text in place. No memo, and the nodeTypes map can live anywhere.

import { Flow, Handle, Position, useFlow } from '@pyreon/flow'
import type { NodeComponentProps } from '@pyreon/flow'

type Task = { label: string; status: 'todo' | 'done' }

// Runs once per node. The accessors keep it current on drag, select and updateNode.
const TaskNode = (props: NodeComponentProps<Task>) => (
  <div class={() => (props.selected() ? 'task selected' : 'task')}>
    <Handle type="target" position={Position.Left} />
    {() => props.data().label}
    {() => (props.data().status === 'done' ? ' (done)' : '')}
    <Handle type="source" position={Position.Right} />
  </div>
)

export const Board = () => {
  const flow = useFlow<Task>({
    nodes: [{ id: 't1', type: 'task', position: { x: 0, y: 0 }, data: { label: 'Write spec', status: 'todo' } }],
  })
  const finish = () => flow.updateNode('t1', { data: { label: 'Write spec', status: 'done' } })
  return (
    <>
      <button onClick={finish}>Mark done</button>
      <Flow instance={flow} nodeTypes={{ task: TaskNode }} />
    </>
  )
}

Auto-layout without a second library.

React Flow
import dagre from '@dagrejs/dagre'
import { ReactFlow, useEdgesState, useNodesState } from '@xyflow/react'
import type { Edge, Node } from '@xyflow/react'

// React Flow has no layout engine: the docs point you at dagre, elkjs or d3-hierarchy.
function layoutWithDagre(nodes: Node[], edges: Edge[]): Node[] {
  const g = new dagre.graphlib.Graph().setDefaultEdgeLabel(() => ({}))
  g.setGraph({ rankdir: 'LR', nodesep: 40, ranksep: 80 })
  for (const n of nodes) g.setNode(n.id, { width: n.measured?.width ?? 150, height: n.measured?.height ?? 40 })
  for (const e of edges) g.setEdge(e.source, e.target)
  dagre.layout(g)
  return nodes.map((n) => {
    const p = g.node(n.id)
    // dagre returns centres; React Flow positions are top-left corners.
    return { ...n, position: { x: p.x - p.width / 2, y: p.y - p.height / 2 } }
  })
}

export function Pipeline(props: { nodes: Node[]; edges: Edge[] }) {
  const [nodes, setNodes, onNodesChange] = useNodesState(props.nodes)
  const [edges, , onEdgesChange] = useEdgesState(props.edges)
  return (
    <>
      <button onClick={() => setNodes(layoutWithDagre(nodes, edges))}>Tidy up</button>
      <ReactFlow nodes={nodes} edges={edges} onNodesChange={onNodesChange} onEdgesChange={onEdgesChange} />
    </>
  )
}
Pyreon

React Flow leaves layout to dagre, elkjs or d3-hierarchy, and you convert between their coordinates and yours. flow.layout() reads the measured node sizes itself, animates the move, and loads its engine on the first call.

import { Flow, useFlow } from '@pyreon/flow'
import type { FlowEdge, FlowNode } from '@pyreon/flow'

export const Pipeline = (props: { nodes: FlowNode[]; edges: FlowEdge[] }) => {
  const flow = useFlow({ nodes: props.nodes, edges: props.edges })
  // Uses each node's measured size. The engine is built in and code-split.
  const tidy = () => flow.layout('layered', { direction: 'RIGHT', nodeSpacing: 40, layerSpacing: 80 })
  return (
    <>
      <button onClick={() => void tidy()}>Tidy up</button>
      <Flow instance={flow} />
    </>
  )
}
try it

Drag the nodes. Then auto-layout.

Drag any node and the edges follow. "Auto-layout" runs the built-in layered engine on the measured node sizes. The counter shows how many times a node component has re-run since mount.

node re-runs since mount: 0

Press Enter or Space to select the node. Use the arrow keys to move a selected node, hold Shift for larger steps. Delete removes the selection, Escape clears it.
Press Enter or Space to select the edge. Delete removes the selection.
100%
triggerWebhook
checkValidate
fetchEnrich
modelScore lead
writeCRM
notifySlack alert
storeArchive

Drag a node, or Tab to one and use the arrow keys (Shift for bigger steps). Drag the empty canvas to pan; the buttons in the corner zoom and fit.

benchmarks

Faster than React Flow 12 on all six operations.

Dragging a node is 7.25× faster because only that node and its edges update. Read the 210× pan-and-zoom row with care: on a viewport change Pyreon writes one CSS transform, while React Flow re-renders its node wrappers on every store write, so the gap measures that design difference more than raw speed. Neither arm synthesizes pointer events; both drive their public API and check the DOM on every iteration.

vs React Flow 12 · 500 nodes, 499 edges, real Chromium, M3 MaxPyreonrival · lower is better
  • drag one node ×60
    4.42 ms
    32.05 ms
    win7.25×
  • select node
    188 µs
    1.01 ms
    win5.39×
  • unmount
    2.12 ms
    8.19 ms
    win3.87×
  • add 50 nodes + 50 edges
    4.15 ms
    4.93 ms
    win1.19×
  • mount
    17.19 ms
    20.12 ms
    win1.17×
  • pan + zoom ×60
    97 µs
    20.48 ms
    win210× (one transform vs node-wrapper re-renders)
Apple M3 Max · record of 2026-11-05 · final pass, one run · author-run, syntheticFull method, every loss →
what's included

Everything a node editor needs.

  • createFlow and useFlow, generic over your node data; useFlow disposes with the component.
  • Custom node and edge renderers that read reactive accessors, so they mount once and patch in place.
  • Five path builders: bezier, smoothstep, step, straight and waypoint routes, with markers, labels and per-edge pathOptions.
  • Seven layouts: layered, force, stress, tree, radial, box and rect packing, animated and fed by measured node sizes.
  • Handles that measure themselves: edges attach to each dot's rendered centre; handle-less nodes get floating endpoints.
  • Canvas chrome: Background, Controls, MiniMap, Panel, NodeResizer, NodeToolbar and EdgeLabelRenderer.
  • History and clipboard: undo, redo, copySelected, paste, plus toJSON / fromJSON for saving.
  • Layout helpers: sub-flows, zIndex with raise on select, snap to grid and to other nodes, auto-pan at the edge.
  • Culling for big graphs: onlyRenderVisibleElements mounts only what is in view.
  • Theming: 25 --pyreon-flow-* CSS variables and colorMode light, dark or system.
recipes

Things to build with it.

A diagram that saves itself

Persist to localStorage, restore on load, and put undo and redo in a corner panel. fromJSON drops duplicate ids and dangling edges with a warning instead of crashing.

import { Background, Controls, Flow, Panel, useFlow } from '@pyreon/flow'

const KEY = 'my-diagram'

export const SavedDiagram = () => {
  // history off while restoring, so the first Undo cannot wipe the saved diagram
  const flow = useFlow({ nodes: [{ id: 'a', position: { x: 0, y: 0 }, data: { label: 'Idea' } }], autoHistory: false })
  const saved = localStorage.getItem(KEY)
  // fromJSON treats input as untrusted: duplicate ids and dangling edges are dropped with a warning.
  if (saved) flow.fromJSON(JSON.parse(saved))
  flow.config.autoHistory = true

  const save = () => localStorage.setItem(KEY, JSON.stringify(flow.toJSON()))
  return (
    <Flow instance={flow}>
      <Background />
      <Controls />
      <Panel position="top-right">
        <button onClick={save}>Save</button>
        <button onClick={() => flow.undo()}>Undo</button>
        <button onClick={() => flow.redo()}>Redo</button>
      </Panel>
    </Flow>
  )
}
A workflow builder with rules

Refuse self-loops and connections into a trigger, default every edge to an animated smoothstep, and cull off-screen nodes for big workflows.

import { Flow, MiniMap, createFlow } from '@pyreon/flow'
import type { Connection, FlowEdge, FlowInstance, FlowNode } from '@pyreon/flow'

type Step = { label: string; kind: 'trigger' | 'action' }

export function createWorkflow(nodes: FlowNode<Step>[], edges: FlowEdge[]) {
  const flow: FlowInstance<Step> = createFlow<Step>({
    nodes,
    edges,
    // A step cannot feed itself, and nothing may connect INTO a trigger.
    isValidConnection: (c: Connection) => c.source !== c.target && flow.nodeMap().get(c.target)?.data.kind !== 'trigger',
    defaultEdgeOptions: { type: 'smoothstep', animated: true },
    onlyRenderVisibleElements: true,
  })
  flow.onConnect((c) => console.log('connected', c.source, '->', c.target))
  return flow
}

export const Workflow = (props: { flow: FlowInstance<Step> }) => (
  <Flow instance={props.flow} ariaLabel="Workflow">
    <MiniMap />
  </Flow>
)
api

38 exports, plus a WebView entry.

Every export has a reference page with its signature, an example and the mistakes people make with it.

core · 4
  • createFlow
  • useFlow
  • computeLayout
  • flowStyles
components · 13
  • Flow
  • Background
  • Controls
  • MiniMap
  • Panel
  • Handle
  • NodeResizer
  • NodeToolbar
  • EdgeLabelRenderer
  • BaseEdge
  • EdgeText
  • ViewportPortal
  • FlowLayersContext
edge paths · 12
  • getBezierPath
  • getSmoothStepPath
  • getStepPath
  • getStraightPath
  • getWaypointPath
  • getEdgePath
  • getSmartHandlePositions
  • getFloatingEndpoints
  • getNodeIntersection
  • getHandlePosition
  • resolveHandleAnchor
  • getEffectiveDimensions
markers and constants · 9
  • resolveMarker
  • resolveEdgeMarkers
  • collectEdgeMarkers
  • markerId
  • DEFAULT_MARKER_END
  • MarkerType
  • Position
  • DEFAULT_NODE_WIDTH
  • DEFAULT_NODE_HEIGHT
@pyreon/flow/webview · 2
  • FlowWebView
  • buildFlowHostHtml
good to know

Good to know before you start.

Read node props as accessors

Write props.data().label, not props.data.label. data, selected and dragging are accessors: call them where you render, and updates reach the node.

Culling is opt-in

Every node mounts by default. For a large graph, set onlyRenderVisibleElements: true and only what is in view stays in the DOM.

Layout options depend on the algorithm

direction applies to layered and tree; layerSpacing and edgeRouting to layered only. The others ignore them, with a dev warning.

iOS and Android are experimental

The native host draws SwiftUI and Compose views. Renderers styled with a class or style, <ViewportPortal> and flowStyles stay on the web; <FlowWebView> hosts the browser renderer when you need it.

questions

What people ask first.

Why is pan and zoom 210× faster?

Because the two libraries do different work. On a viewport change Pyreon updates one CSS transform on the viewport element and creates no new elements (a test counts them). React Flow re-renders its node wrappers on every store write. Read it as a design difference (the record says the same of most of the drag gap), and look at select (5.39×) and unmount (3.87×) for a closer race.

Is this React Flow ported to Pyreon?

No. The vocabulary is close on purpose (Handle, MiniMap, NodeResizer, isValidConnection, onlyRenderVisibleElements), so the concepts carry over. Underneath, every node and edge has its own signals, and a node component never re-renders.

How large a graph can it take?

The benchmark graph is 500 nodes and 499 edges. A drag frame does a constant number of lookups whatever the graph size (a test compares 20 and 120 nodes). Past what fits on screen, turn on onlyRenderVisibleElements.

Does it run on iOS and Android?

Yes, experimentally. createFlow and <Flow> lower to a native SwiftUI or Compose host with the same instance API, all seven layouts, gestures and the minimap. It is a native view tree, not a WebView. Renderers that depend on CSS stay web-only, and the compiler names each one.

What does the layout engine depend on?

Nothing outside Pyreon. All seven algorithms are pure geometry in the package, split into their own chunk so the first layout() call loads them.

Your users draw the graph. You skip the re-renders.

bun add @pyreon/flow
Read the flow guide