Skip to content

Set viewport when nodes dimensions are ready #12730

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

Merged
merged 12 commits into from
Jun 19, 2025

Conversation

Devessier
Copy link
Contributor

@Devessier Devessier commented Jun 19, 2025

Sometimes, we try to set the viewport, but the nodes' dimensions have been reset. Trying to set the viewport when the nodes' dimensions are incorrect leads to an incorrect viewport.

This PR ensures we only try to set the viewport if the nodes' dimensions are valid. Otherwise, we wait for them to be computed to set the viewport automatically.

The handleNodesChanges function is called every time the nodes change, including when the dimensions have been computed.

Internally, Reactflow has a similar behavior to implement the fitView feature: https://github.com/xyflow/xyflow/blob/f9971a8fad54e9c2f33b71b4056b6d1ec6c33bd1/packages/react/src/store/index.ts#L111.

Example

This is more notable since I added optimistic rendering to workflow runs.

CleanShot.2025-06-19.at.16.50.41.mp4

Copy link
Contributor

github-actions bot commented Jun 19, 2025

🚀 Preview Environment Ready!

Your preview environment is available at: http://bore.pub:41562

This environment will automatically shut down when the PR is closed or after 5 hours.

@Devessier Devessier marked this pull request as ready for review June 19, 2025 15:58
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

Implements a more robust viewport calculation system for workflow diagrams by ensuring node dimensions are properly computed before setting the viewport position.

  • Added new workflowDiagramWaitingNodesDimensionsComponentState to track dimension computation status using Recoil state management
  • Modified WorkflowDiagramCanvasBase to prevent premature viewport calculations when node dimensions are reset or invalid
  • Leverages ComputeNodeDimensions utility to ensure accurate dimension measurements before bounds calculation
  • Integrates with optimistic rendering for workflow runs to maintain viewport stability
  • Improved viewport calculation to properly handle right drawer states and prevent incorrect positioning

2 files reviewed, no comments
Edit PR Review Bot Settings | Greptile

@Devessier Devessier merged commit 79e5ccf into main Jun 19, 2025
56 checks passed
@Devessier Devessier deleted the set-viewport-when-nodes-dimensions-are-ready branch June 19, 2025 16:47
ehconitin pushed a commit to ehconitin/twenty that referenced this pull request Jun 19, 2025
Sometimes, we try to set the viewport, but the nodes' dimensions have
been reset. Trying to set the viewport when the nodes' dimensions are
incorrect leads to an incorrect viewport.

This PR ensures we only try to set the viewport if the nodes' dimensions
are valid. Otherwise, we wait for them to be computed to set the
viewport automatically.

The `handleNodesChanges` function is called every time the nodes change,
including when the dimensions have been computed.

Internally, Reactflow has a similar behavior to implement the `fitView`
feature:
https://github.com/xyflow/xyflow/blob/f9971a8fad54e9c2f33b71b4056b6d1ec6c33bd1/packages/react/src/store/index.ts#L111.

## Example

This is more notable since I added optimistic rendering to workflow
runs.


https://github.com/user-attachments/assets/07232050-b808-4345-b82b-95acad72ab15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants