13 KiB
@xyflow/react
12.0.0-next.15
Patch changes
- re-observe nodes when using
onlyRenderVisibleElements={true} - use correct positions for intersection helpers
- fix minimap interaction for touch devices
- pass user nodes to
onSelectionChangeinstead of internal ones to work with Redux - call
onEndin XYResizer thanks @tonyf - cleanup
getPositionWithOriginusage - use
setAttributesflag for dimension change whenwidth/heightshould be set
12.0.0-next.14
Patch changes
- fix hidden nodes
- use
direction=ltrfor outer wrapper to support rtl sites - allow pinch zoom even if
preventScrolling=false - export node and edge change related types
- only trigger dimensions updates when changes detected
12.0.0-next.13
⚠️ Breaking changes
- rename
node.parentNodetonode.parentId - rename node.computed to node.measured
- remove positionAbsolute from
node.computed
Minor Changes
- new helpers:
useInternalNodehook,getInternalNodefunction
Patch changes
- remove
internalsSymbol(now called internals and only available for internal nodes) - handle parentExpand on library side instead of applyChanges
- new type
InternalNode
12.0.0-next.12
Patch changes
- fix useNodesData: handle invalid node id thanks @saswatax
- fix forwardRef: use custom fixForwardRef function
- refactor intersection helpers to use passed node value
12.0.0-next.11
Patch changes
- fix
refprop forReactFlowandHandlecomponent - unify
EdgeandNodetype handling - fix safari: prevent selection of viewport
- fix
useNodesDatahook to prevent re-renderings - fix edges: allow start at 0,0
12.0.0-next.10
⚠️ Breaking changes
useNodesDatanot only returns data objects but also the type and the id of the node- status class names for Handle components are slightly different. It's now "connectingfrom" and "connectingto" instead of "connecting"
Patch changes
- better cursor defaults for the pane, nodes and edges
disableKeyboardA11ynow also disables Enter and Escape for selecting/deselecting nodes and edges- fix bug where users couldn't drag a node after toggle nodes
hiddenattribute - add
initialWidthandinitialHeightnode attributes for specifying initial dimensions for ssr - fix
NodeResizerwhen used in combination withnodeOrigin
12.0.0-next.9
Patch changes
- a better
NodeResizerthat works with subflows. Child nodes do not move when parent node gets resized and parent extent is taken into account - refactor
setNodesbatching - re-measure nodes when necessary
- don't trigger drag start / end when node is not draggable
12.0.0-next.8
Patch changes
- selection box is not interrupted by selectionKey being let go
- fix
OnNodeDragtype - do not use fallback handle if a specific id is being used
- fix
defaultEdgeOptionsmarkers not being applied - fix
getNodesBoundsand add second param for passing options - fix
expandParentfor child nodes
12.0.0-next.7
Minor changes
- add second option param to
screenToFlowPositionfor configuring ifsnapToGridshould be used
Patch changes
- pass
Node/Edgetypes to changes thanks @FelipeEmos - use position instead of positionAbsolute for
getNodesBounds - infer types for
getIncomers,getOutgoers,updateEdge,addEdgeandgetConnectedEdgesthanks @joeyballentine - refactor handles: prefix with flow id for handling nested flows
- add comments for types like
ReactFlowPropsorNodefor a better developer experience
12.0.0-next.6
Patch changes
- fix
deleteElements - refactor internal
applyChanges - batch
setNodesandsetEdgesfromuseReactFlow - add
aria-labelprop for<Controls />
12.0.0-next.5
Minor changes
- fix applyChanges: handle multi changes for one node, deletions and expandParent
- use
XYResizerfrom @xyflow/system - add unit tests for
applyNodeChangesandapplyEdgeChanges
12.0.0-next.4
Minor changes
- fix applyChanges: handle empty flows + addNodes/addEdges closes
- cleanup exports
12.0.0-next.3
Minor changes
- fix edges styles when using base.css
12.0.0-next.2
Minor changes
- fix connection line rendering
- fix multi handle
12.0.0-next.1
Minor changes
- fix edge rendering
12.0.0-next.0
React Flow v12 is coming soon! We worked hard over the past months and tried to make as few breaking changes as possible (there are some). We are in no rush to release v12, so we’d be happy to hear any early feedback so we can adjust the API or redefine new features before launching stable v12. 🚀 The big topics for this version are:
- Support for SSG/ SSR: you can now render flows on the server
- Reactive flows: new hooks and helper functions to simplify data flows
- Dark mode: a new base style and easy way to switch between built in color modes
Svelte Flow had a big impact on this release as well. While combing through each line of React Flow, we created framework agnostic helpers, found bugs, and made some under the hood improvements. All of these changes are baked into the v12 release as a welcome side-effect of that launch. 🙌🏻 We also improved the performance for larger flows with the help of Ivan.
Migrate from 11 to 12
Before you can try out the new features, you need to do some minor updates:
- A new npm package name: Our name changed from
reactflowto@xyflow/reactand the main component is no longer a default, but a named import:- v11:
import ReactFlow from 'reactflow'; - v12:
import { ReactFlow } from '@xyflow/react';
- v11:
- Node attribute “computed”: All computed node values are now stored in
node.computed- v11:
node.width,node.height,node.positionAbsolute - v12:
node.computed.width,node.computed.heightandnode.computed.positionAbsolute. (node.width/node.heightcan now be used for SSG)
- v11:
- Updating nodes: We are not supporting node updates with object mutations anymore. If you want to update a certain attribute, you need to create a new node.
- v11:
setNodes((nds) => nds.map((node) => { node.hidden = true; return node; }) ); - v12:
setNodes((nds) => nds.map((node) => ({ ...node, hidden: true, })) );
- v11:
- NodeProps:
posX/posYis now calledpositionAbsoluteX/positionAbsoluteY - Typescript only: We simplified types and fixed issues about functions where users could pass a
NodeDatageneric. The new way is to define your own node type for the whole app and then only use that one. The big advantage of this is, that you can have multiple node types with different data structures and always be able to distinguish by checking thenode.typeattribute.- v11:
applyNodeChange<NodeData, NodeType> - v12:
type MyNodeType = Node<{ value: number }, ‘number’> | Node<{ value: string }, ‘text’>; applyNodeChange<MyNodeType> - affected functions:
useNodes,useNodesState,useEdgesState,applyNodeChange,onInit,applyEdgeChanges,MiniMapProps
- v11:
- Removal of deprecated functions:
getTransformForBounds(new name:getViewportForBounds),getRectOfNodes(new name:getNodesBounds)project(new name:screenToFlowPosition)getMarkerEndId
Main features
Now that you successfully migrated to v12, you can use all the fancy features. As mentioned above, the biggest updates for v12 are:
- SSR / SSG: you can define
width,heightandhandlesfor the nodes. This makes it possible to render a flow on the server and hydrate on the client: codesandbox- Details: In v11,
widthandheightwere set by the library as soon as the nodes got measured. This still happens, but we are now usingcomputed.widthandcomputed.heightto store this information. ThepositionAbsoluteattribute also gets stored incomputed. In the previous versions there was always a lot of confusion aboutwidthandheight. 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:widthandheightare optional attributes that can be used to define dimensions and everything that is set by the library, is stored incomputed.
- Details: In v11,
- Reactive Flows: The new hooks
useHandleConnectionsanduseNodesDataand the newupdateNodeandupdateNodeDatafunctions can be used for managing the data flow between your nodes: codesandbox- Details: Working with reactive flows is super common. You update node A and want to react on those changes in the connected node B. Until now everyone had to come up with a custom solution. With this version we want to change this and give you performant helpers to handle this. If you are excited about this, you can check out this example:
- Dark mode and css variables: React Flow now comes with a built-in dark mode, that can be toggled by using the new
colorModeprop (”light”, “dark” or “system”): codesandbox- Details: With this version we want to make it easier to switch between dark and light modes and give you a better starting point for dark flows. If you pass colorMode=”dark”, we add the class name “dark” to the wrapper and use it to adjust the styling. To make the implementation for this new feature easier on our ends, we switched to CSS variables for most of the styles. These variables can also be used in user land to customize a flow.
More features and updates
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.
useConnectionhook: This hook makes it possible to handle an ongoing connection. For example, you can use it for colorizing handles.onDeletehandler: We added a combined handler foronDeleteNodesandonDeleteEdgesto make it easier to react to deletions.isValidConnectionprop: This makes it possible to implement one validation function for all connections. It also gets called for programatically added edges.- Controlled
viewport: This is definitely 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:viewportandonViewportChange. ViewportPortalcomponent: This makes it possible to render elements in the viewport without the need to implement a custom node.- Background component: add
patternClassNameto 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. onMovecallback gets triggered for library-invoked viewport updates (like fitView or zoom-in)deleteElementsnow returns deleted nodes and deleted edges- add
originattribute for nodes - add
selectableattribute for edges - Correct types for
BezierEdge,StepEdge,SmoothStepEdgeandStraightEdgecomponents - New edges created by the library only have
sourceHandleandtargetHandleattributes when those attributes are set. (We used to passsourceHandle: nullandtargetHandle: null) - Edges do not mount/unmount when their z-index change
Internal changes
These changes are not really user-facing, but it could be important for folks who are working with the React Flow store:
- The biggest internal change is that we created a new package @xyflow/system with framework agnostic helpers that can be used be React Flow and Svelte Flow
- XYDrag for handling dragging node(s) and selection
- XYPanZoom for controlling the viewport panning and zooming
- XYHandle for managing new connections
- We replaced the
nodeInternalsmap with anodesarray. We added a newnodeLookupmap that serves as a lookup, but we are not creating a new map object on any change so it’s really only useful as a lookup. - We removed
connectionNodeId,connectionHandleId,connectionHandleTypefrom the store and addedconnectionStartHandle.nodeId,connectionStartHandle.handleId, … - add
data-idto edges
With v12 the reactflow package was renamed to @xyflow/react - you can find the v11 source and the reactflow changelog on the v11 branch.