New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The useDropNode hook has an invalid lifecycle #2615
Comments
It should also be noted that errors from the backend are not considered while retrieving the compatibility data. They should be displayed as usual |
Even better, as suggested by @gcoutable the retrieval of the compatibility data could be done in the |
gcoutable
added a commit
that referenced
this issue
Nov 22, 2023
Bug: #2615 Signed-off-by: Guillaume Coutable <guillaume.coutable@obeo.fr>
39 tasks
gcoutable
added a commit
that referenced
this issue
Nov 22, 2023
Bug: #2615 Signed-off-by: Guillaume Coutable <guillaume.coutable@obeo.fr>
sbegaudeau
pushed a commit
that referenced
this issue
Nov 22, 2023
Bug: #2615 Signed-off-by: Guillaume Coutable <guillaume.coutable@obeo.fr>
sbegaudeau
pushed a commit
that referenced
this issue
Nov 22, 2023
Bug: #2615 Signed-off-by: Guillaume Coutable <guillaume.coutable@obeo.fr>
sbegaudeau
pushed a commit
that referenced
this issue
Nov 22, 2023
Bug: #2615 Signed-off-by: Guillaume Coutable <guillaume.coutable@obeo.fr>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Issue
The useDropNode hook is responsible for several pieces of behavior related to dragging and dropping nodes. As a result of this complexity, it has many responsibilities which do not work properly.
onNodeDragStart
used by theDiagramRenderer
to know which node is being draggeddropFeedbackStyleProvider
used by the various nodes to know how the style of the various nodes should be impacteduseQuery
to retrieve compatibility informationAs a result of all those responsibilities, this hook is used at several location in the code such as:
DiagramRenderer
ImageNode
ListNode
RectangularNode
EllipseNode
By the way, it seems a bit odd that it is not used in
IconLabelNode
...With the multiplication of those responsibilities, the hook has now three ways to store pieces of informations with
setDropData
,setDraggedNode
andsetDropNodeCompatibilityData
. The lifecycle of those individual pieces of state is invalid and creating bugs.The multiplication of
useState
/useContext
to store things here and there is creating very subtle issues.Dragged node
If we were to inline the code of this hook to understand its impact a bit better, we have at least five locations in the code which are each storing what they think is the currently dragged node. So in memory, for a diagram displaying "n" nodes, we will have this information stored in "n+1" location and "n" of those will have the wrong information since only the instance of this hook used by the
DiagramRenderer
will be properly updated.Compatibility query
We will also have "n+1" location trying to perform calls to
useQuery
to retrieve the compatibility data, "n" of those are useless since the query depends only the editing context id and the representation id.Solution
The hook
useDropNode
should be separated in smaller hooks with a proper lifecycle. The hookuseDropNode
should only be used by theDiagramRenderer
and it should provide the following API:useState<GQLDropNodeCompatibilityEntry[]>([])
, it's not necessaryDropNodeContext
and auseState<Node<NodeData> | null>(null)
, thedraggedNode
state should probably be removed since it's not necessaryA second hook, which would not perform any GraphQL query nor store any state named
useDropNodeStyle(nodeId: string)
should be introduced with the following API:This hook should only request the relevant data from the
DropNodeContext
The text was updated successfully, but these errors were encountered: