Last updated on
2024-07-09
React Flow 12 is finally out! With a new package name @xyflow/react!
width, height and handles for the nodes. This makes it possible to render a flow on the server and hydrate on the client: SSR guide
width and height were set by the library as soon as the nodes got measured. This still happens, but we are now using measured.width and measured.height to store this information. In the previous versions there was always a lot of confusion about width and height. It’s hard to understand, that you can’t use it for passing an actual width or height. It’s also not obvious that those attributes get added by the library. We think that the new implementation solves both of the problems: width and height are optional attributes that can be used to define dimensions and the measured dimensions are stored in measured.useHandleConnections and useNodesData and the new and functions can be used for managing the data flow between your nodes:
updateNodeupdateNodeDatacolorMode prop (”light”, “dark” or “system”): dark mode example
There is more! Besides the new main features, we added some minor things that were on our list for a long time. We also started to use TS docs for better docs. We already started to add some docs for some types and hooks which should improve the developer experience.
useConnection hook: With this hook you can access the ongoing connection. For example, you can use it for colorizing handles styling a custom connection line based on the current start / end handles.viewport: This is an advanced feature. Possible use cases are to animate the viewport or round the transform for lower res screens for example. This features brings two new props: viewport and onViewportChange.ViewportPortal component: This makes it possible to render elements in the viewport without the need to implement a custom node.onDelete handler: We added a combined handler for onDeleteNodes and onDeleteEdges to make it easier to react to deletions.onBeforeDelete handler: With this handler you can prevent/ manage deletions.isValidConnection prop: This makes it possible to implement one validation function for all connections. It also gets called for programmatically added edges.autoPanSpeed prop: For controlling the speed while auto panning.patternClassName prop to be able to style the background pattern by using a class name. This is useful if you want to style the background pattern with Tailwind for example.onMove callback gets triggered for library-invoked viewport updates (like fitView or zoom-in)deleteElements now returns deleted nodes and deleted edgesorigin attribute for nodesselectable attribute for edgesBezierEdge, StepEdge, SmoothStepEdge and StraightEdge componentssourceHandle and targetHandle attributes when those attributes are set. (We used to pass sourceHandle: null and targetHandle: null)nodeDragThreshold is 1 by default instead of 0selectable, deletable, draggable and parentId to NodeProps