Skip to content

fix(embedded): block layout should not be dependent on viewport#3621

Merged
icecrasher321 merged 2 commits intostagingfrom
fix/viewport-dep-embedded
Mar 17, 2026
Merged

fix(embedded): block layout should not be dependent on viewport#3621
icecrasher321 merged 2 commits intostagingfrom
fix/viewport-dep-embedded

Conversation

@icecrasher321
Copy link
Collaborator

Summary

Block layout should not be dependent on embedded view sizing.

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Mar 17, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Mar 17, 2026 5:49am

Request Review

@cursor
Copy link

cursor bot commented Mar 17, 2026

PR Summary

Low Risk
Low risk UI behavior change limited to embedded workflows, but it affects viewport fitting/timing and could cause unexpected zoom/pan if edge cases slip through.

Overview
Fixes embedded workflow rendering so layout/viewport fitting is driven by the embed container size, not initial viewport timing.

Embedded mode now schedules fitView via requestAnimationFrame, re-runs it on container resizes (via ResizeObserver) and on structural block changes, and delays isCanvasReady until the first successful embedded fit. It also loosens embedded minZoom (0.35 → 0.1) and avoids running the normal onInit fit behavior when embedded is true.

Written by Cursor Bugbot for commit b188e6a. Configure here.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 17, 2026

Greptile Summary

This PR fixes an embedded workflow viewer bug where the initial fitView call happened in the ReactFlow onInit callback before the container had stable dimensions, causing the block layout to be incorrectly sized or positioned depending on the viewport at that moment.

Key changes:

  • The onInit handler now returns early for embedded mode, removing the viewport-dependent initial fitView call.
  • A new scheduleEmbeddedFit callback uses requestAnimationFrame (with debouncing via cancelAnimationFrame) to defer fitView until the container is confirmed to have non-zero dimensions.
  • A ResizeObserver on canvasContainerRef re-fits the view whenever the embedded container is resized, ensuring layout correctness across all container sizes.
  • hasCompletedInitialEmbeddedFitRef gates the single call to setIsCanvasReady(true), preventing the loading spinner from reappearing on subsequent re-fits.
  • minZoom for embedded fit view is lowered from 0.35 to 0.1 to allow more zoom-out range.

Issues found:

  • A second useEffect re-fires scheduleEmbeddedFit on every displayNodes change, including execution-state-only updates (node outputs, statuses). This means fitView is called on every node execution update, resetting any user panning/zooming in the embedded view during workflow runs.
  • setIsCanvasReady is missing from the useCallback dependency array of scheduleEmbeddedFit, which will likely trigger an exhaustive-deps lint warning.

Confidence Score: 3/5

  • Safe to merge for the core layout fix, but the displayNodes-triggered re-fit has a real UX impact during workflow execution in the embedded viewer.
  • The ResizeObserver approach correctly solves the viewport-dependency bug and the debouncing logic is sound. The main concern is the second useEffect re-fitting on every node data update (e.g. execution outputs), which would reset user panning/zooming while a workflow runs — a regression compared to the old behaviour where the view was only fit once on init.
  • apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx — specifically the second useEffect (lines 3813–3819) and the scheduleEmbeddedFit dependency array.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx Replaces the viewport-dependent onInit fitView for embedded mode with a ResizeObserver-backed scheduleEmbeddedFit callback; adds a second effect that re-fires fitView on every displayNodes change, which could reset user panning during workflow execution.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[ReactFlow onInit fires] --> B{embedded?}
    B -- yes --> C[return early — no fitView]
    B -- no --> D[requestAnimationFrame → fitView + setIsCanvasReady]

    E[isWorkflowReady becomes true] --> F[Effect 1: canvasContainerRef ready]
    F --> G[scheduleEmbeddedFit]
    F --> H[ResizeObserver.observe container]
    H -- container resized --> G

    I[displayNodes changes] --> J[Effect 2]
    J --> G

    G --> K[cancelAnimationFrame pending RAF]
    K --> L[requestAnimationFrame]
    L --> M{container rect valid?}
    M -- no --> N[return — spinner remains]
    M -- yes --> O{nodes.length > 0?}
    O -- yes --> P[fitView with duration:0]
    O -- no --> Q{initialFit done?}
    P --> Q
    Q -- no --> R[hasCompletedInitialEmbeddedFitRef = true\nsetIsCanvasReady true]
    Q -- yes --> S[done]
    R --> S
Loading

Last reviewed commit: 3162641

@icecrasher321
Copy link
Collaborator Author

bugbot run

@icecrasher321
Copy link
Collaborator Author

bugbot run

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

@icecrasher321 icecrasher321 merged commit e804ea3 into staging Mar 17, 2026
12 checks passed
@icecrasher321 icecrasher321 deleted the fix/viewport-dep-embedded branch March 17, 2026 06:19
Sg312 pushed a commit that referenced this pull request Mar 17, 2026
* fix(embedded): block layout should not be dependent on viewport

* address comments
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.

1 participant