✨ @xyflow/react - React Flow v12 next #3764
Replies: 32 comments 41 replies
-
Incredible work as always and I am very excited to try these features out 🌻 |
Beta Was this translation helpful? Give feedback.
-
Amazing update guys! Can't wait to try it out 🚀 |
Beta Was this translation helpful? Give feedback.
-
Very nice! v12 seems to work perfectly for me. small nitpick, why is project now called screenToFlowPosition when you actually need to pass clientX, clientY? |
Beta Was this translation helpful? Give feedback.
-
Amazing!!! |
Beta Was this translation helpful? Give feedback.
-
Do we know when v12 is likely to be available on a stable release? |
Beta Was this translation helpful? Give feedback.
-
I had just started using react-flow and the update was pretty painless! My only issue is that the |
Beta Was this translation helpful? Give feedback.
-
Looking forward to this next release! I'm really interested in the computing flows features, but the example doesn't appear to be working, at least for me. Thanks for the great library! |
Beta Was this translation helpful? Give feedback.
-
I also noticed that when I drag from a handle, lots of stuff gets selected, including a chunk of the background and inputs in the node components. This didn't happen when using v11. |
Beta Was this translation helpful? Give feedback.
-
Really looking forward to this release, great work! 🚀 |
Beta Was this translation helpful? Give feedback.
-
It seems v12 doesn't support I got
Is there a neater way to update nodes with nested object as |
Beta Was this translation helpful? Give feedback.
-
in V11: import type { HandleProps } from "reactflow"; in V12: import type { HandleProps } from "@xyflow/react"; // "@xyflow/react" has no exported member 'HandleProps' |
Beta Was this translation helpful? Give feedback.
-
I can't get the |
Beta Was this translation helpful? Give feedback.
-
I am rendering data from backend , so the initial position of x and y is 0. In the UI node will be one after the other meaning one node i can see , rest are behind the first node. So i used onNodeDrag , so that when a node is dragged its x and y position will change, but it is creating a copy object on each drag.Is there any props that i can use for dragging the node , on drag i want to update the node x and y position |
Beta Was this translation helpful? Give feedback.
-
Hello guys, I was trying to test the computing flow feature. While doing so, I noticed that the edges do weird things. I don't know if this is something in V12 or also in earlier versions. Also, It could very well be something I am doing wrong. My React knowledge is lacking to say the least. Here is a branch, checkout and move the nodes around a bit. |
Beta Was this translation helpful? Give feedback.
-
Great new additions! |
Beta Was this translation helpful? Give feedback.
-
We are still not 100% sure how to handle measured node dimensions. This is an alternative approach #4054 - Feedback is highly appreciated! |
Beta Was this translation helpful? Give feedback.
-
Hi all, In order to celebrate the new typings on nodes, I managed to put toghether a few lines of generic that help with custom compoents. I hope someone else may find this usefull:
this defiens the actual node type and the data you expect from it
This one is used to define the custom node React components
example:
used to define the types of all nodes.
examples:
|
Beta Was this translation helpful? Give feedback.
-
Hi, it seems like the |
Beta Was this translation helpful? Give feedback.
-
I don't know which api should I use to delete a node ? Are there any differences between them ? const reactFlow = useReactFlow<Node, Edge>();
reactFlow.setNodes(nodes => nodes.filter(node => node.id !== id)); const reactFlow = useReactFlow<Node, Edge>();
reactFlow.deleteElements({ nodes: [{ id }] }); |
Beta Was this translation helpful? Give feedback.
-
It seems like snapToGrid is default true, which breaks some behavior vs. v11. Should be noted in the upgrade notes, or default to false. |
Beta Was this translation helpful? Give feedback.
-
can you export the import React from "react";
import type { NodeProps, Node } from "@xyflow/react";
const MyNode: React.FC<NodeProps<Node>> = props => {
const { onNodeDragEnd } = props;
……
}
export default MyNode; |
Beta Was this translation helpful? Give feedback.
-
When will React Flow v12 be released in the official version, and whether the example on the official website will be updated synchronously after the release, and there will be projects using reactflow in early April, looking forward to v12 |
Beta Was this translation helpful? Give feedback.
-
Interactive minimap doesn't work with touchscreen ( |
Beta Was this translation helpful? Give feedback.
-
I just went through the SSG/SSR example, and the rendered output is fully static and I'm not able to perform any action on the output (move across the viewport, drag the nodes, etc). Is the component not getting hydrated on the client? Am I missing something? Any help is appreciated. I'm attaching a video for reference. I added a new node (through the code) and set its position such that it is rendered out of the react flow viewport, however, I'm not able to view that node by dragging the canvas/background. Moreover, the nodes within the viewport are also not draggable. When I tried zooming in, I could not zoom in on the canvas, instead, the browser tab zoomed in. react-flow.mp4 |
Beta Was this translation helpful? Give feedback.
-
any plans of stable version this month? |
Beta Was this translation helpful? Give feedback.
-
setNodes(nodes=>{}), the callback nodes has not computed attr(useNodes has), i guess you guys forgot this. |
Beta Was this translation helpful? Give feedback.
-
It seems like the types for For the |
Beta Was this translation helpful? Give feedback.
-
I'm trying to use
Using nextjs 13 + zustand + liveblocks |
Beta Was this translation helpful? Give feedback.
-
Sweeet. Any chance we'll see a solid js port soon? |
Beta Was this translation helpful? Give feedback.
-
I've run through the Helper Lines example code and migrated it to v12, but in this version it's missing the lines for the right and bottom sides of all nodes. I've added other calculations for centers too but they never seem to trigger. Works great in v11. Happy to supply a basic repo with this happening.
Below happens: Untitled.mov |
Beta Was this translation helpful? Give feedback.
-
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 (you can find the migration guide below) so we can adjust the API or redefine new features before launching stable v12. 🚀 The big topics for this version are:
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 and we are now using TSDoc for a better developer experience in your IDE.
Installation
From now on you can find the package in the xyflow organization:
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:
width
(orinitialWidth
),height
(orinitialHeight
) andhandles
for the nodes. This makes it possible to render a flow on the server and hydrate on the client: example codewidth
andheight
were set by the library as soon as the nodes got measured. This still happens, but we are now usingmeasured.width
andmeasured.height
to store this information (computed
which is nowmeasured
). ThepositionAbsolute
attribute doesn't get exposed to the user nodes anymore. In the previous versions there was always a lot of confusion aboutwidth
andheight
. 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
andheight
are optional attributes that can be used to define dimensions and the measured dimensions are stored inmeasured
.useHandleConnections
anduseNodesData
and the newupdateNode
andupdateNodeData
functions (both are part ofuseReactFlow
) can be used to manage the data flow between your nodes: example codecolorMode
prop (”light”, “dark” or “system”): example codeMore 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 TSDoc for a better DX. 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
andonViewportChange
.ViewportPortal
component: This makes it possible to render elements in the viewport without the need to implement a custom node.useInternalNode()
/getInternalNode
helper for advanced usage to receive position absolute or handle bounds for example.onDelete
handler: We added a combined handler foronDeleteNodes
andonDeleteEdges
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.patternClassName
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
andStraightEdge
componentssourceHandle
andtargetHandle
attributes when those attributes are set. (We used to passsourceHandle: null
andtargetHandle: null
)nodeDragThreshold
is 1 by default instead of 0Internal changes
These changes are not really user-facing, but it could be important for folks who are working with the React Flow store:
nodeInternals
tonodeLookup
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.Node
) and internal nodes (typeInternalNode
). The internal node stores some more inforamtion like position absolute, handle bounds and a calculated z-index.connectionNodeId
,connectionHandleId
,connectionHandleType
from the store and addedconnectionStartHandle.nodeId
,connectionStartHandle.handleId
, …data-id
to edgesonNodeDragStart
,onNodeDrag
andonNodeDragStop
also get called when user drags a selection (in addition toonSelectionDragStart
,onSelectionDrag
,onSelectionDragStop
)Migrate from 11 to 12
Before you can try out the new features, you need to do some minor updates:
reactflow
to@xyflow/react
and the main component is no longer a default, but a named import:import ReactFlow from 'reactflow';
import { ReactFlow } from '@xyflow/react';
- don't forget to update the style import too!node.measured
. Besides the new name, this is the biggest change.node.width
,node.height
,node.positionAbsolute
node.measured.width
,node.measured.height
(node.computed
in. a previous alpha version) -node.width
/node.height
can now be used for SSGnode.parentNode
is now callednode.parentId
posX
/posY
is now calledpositionAbsoluteX
/positionAbsoluteY
getNodesBounds(nodes: Node[], nodeOrigin)
getNodesBounds(nodes: Node[], { nodeOrigin })
NodeData
generic. 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.type
attribute.applyNodeChange<NodeData, NodeType>
type MyNodeType = Node<{ value: number }, ‘number’> | Node<{ value: string }, ‘text’>; applyNodeChange<MyNodeType>
useNodes
,useNodesState
,useEdgesState
,applyNodeChange
,onInit
,applyEdgeChanges
,MiniMapProps
useStore
for example, you need to rename it tonodeLookup
:const nodeInternals = useStore(s => s.nodeInternals);
const nodeLookup = useStore(s => s.nodeLookup);
getTransformForBounds
(new name:getViewportForBounds
),getRectOfNodes
(new name:getNodesBounds
)project
(new name:screenToFlowPosition
)getMarkerEndId
Beta Was this translation helpful? Give feedback.
All reactions