Skip to content
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

fix(Canvas): Fix CustomNode rerendering without controller #1922

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

lordrip
Copy link
Member

@lordrip lordrip commented Jan 17, 2025

Context

When performing D&D, the following occurs:

  1. The graph model gets reset
  2. A structural change in the VisualEntity
  3. The nodes rerenders
  4. There are failuers in the console due to nodes being rendered without having a controller, because it was removed during the node removal process

The first solution for this is to set an empty model to the visualization controller so it removes all nodes from the canvas, then due to the recreation of the visual entities, the canvas will be repopulated.

While this works in the browser, when running Kaoto through the Multiplying Architecture, it doesn't work, very likely because of the react versions mismatch (web: 18, MA: 17).

The second iteration of the solution is to schedule the entities recreation outside of react, by using requestAnimationFrame`, this way, the canvas will be cleared before recreating the visual entities.

Almost everything boils down to the fact that because the vizNodes are being recreated during the visualization, and since they are stored in the data property of the canvas nodes, the CustomNodes and CustomGroups are being rerendered, due to the use of observer from mobx.

A more future-proof solution would be to remove the vizNode objects from the data properties, so the rerendering process occurs without taking those into consideration.

fix: #1888

Copy link

codecov bot commented Jan 17, 2025

Codecov Report

Attention: Patch coverage is 55.17241% with 26 lines in your changes missing coverage. Please review.

Project coverage is 78.58%. Comparing base (933679b) to head (27406ca).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...omponents/Visualization/Custom/Node/CustomNode.tsx 45.45% 12 Missing ⚠️
...ponents/Visualization/Custom/Group/CustomGroup.tsx 50.00% 8 Missing ⚠️
.../ui/src/components/Visualization/Canvas/Canvas.tsx 57.14% 3 Missing ⚠️
...ponents/Visualization/Canvas/controller.service.ts 50.00% 1 Missing ⚠️
...Visualization/Custom/Group/CustomGroupExpanded.tsx 75.00% 1 Missing ⚠️
...ents/Visualization/Custom/Node/PlaceholderNode.tsx 85.71% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1922      +/-   ##
============================================
+ Coverage     78.51%   78.58%   +0.06%     
  Complexity      367      367              
============================================
  Files           469      468       -1     
  Lines         14816    14824       +8     
  Branches       2832     2835       +3     
============================================
+ Hits          11633    11649      +16     
+ Misses         3095     2904     -191     
- Partials         88      271     +183     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

When performing D&D, the following occurs:

1. The graph model gets reset
2. A structural change in the VisualEntity
3. The nodes rerenders
4. There are failuers in the console due to nodes being rerendered
   without having a controller, because it was removed during the node
removal process

The first solution for this is to set an empty model to the
visualization controller so it removes all nodes from the canvas, then
due to the recreation of the visual entities, the canvas will be
repopulated.

While this works in the browser, when running Kaoto through the
Multiplying Architecture, it doesn't work, very likely because of the
react versions mismatch (web: 18, MA: 17).

The second iteration of the solution is to schedule the entities
recreation outside of react, by using `requestAnimationFrame`, this way,
the canvas will be cleared before recreating the visual entities.

Almost everything boils down to the fact that because the vizNodes are
being recreated during the visualization, and since they are stored in
the data property of the canvas nodes, the CustomNodes and CustomGroups
are being rerendered, due to the use of `observer` from `mobx`.

A more future-proof solution would be to remove the `vizNode` objects
from the data properties, so the rerendering process occurs without
taking those into consideration.

fix: KaotoIO#1888
@lordrip lordrip force-pushed the fix/dnd-related-console-errors branch from cdb4548 to 2d39d36 Compare January 20, 2025 08:43
@lordrip lordrip changed the title Fix/dnd related console errors fix(Canvas): Fix CustomNode rerendering without controller Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid flickering of nodes in canvas after a successful DND
2 participants