Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • Fixed zoom timing issue after copilot applies workflow edits
  • Changed from polling/retry approach to event-driven two-phase zoom
  • Phase 1: Records block IDs to zoom to when diff becomes ready
  • Phase 2: Performs zoom when displayNodes contains all expected blocks with valid dimensions
  • Fixed fallback dimensions in fitViewToBounds to match actual block sizes (250px instead of 200px)

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 Jan 26, 2026

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

1 Skipped Deployment
Project Deployment Review Updated (UTC)
docs Skipped Skipped Jan 26, 2026 9:46pm

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 26, 2026

Greptile Overview

Greptile Summary

Refactored the copilot zoom-to-changed-blocks feature from a polling/retry approach to an event-driven two-phase system. Phase 1 records the block IDs to zoom when the diff becomes ready, and Phase 2 waits for displayNodes to contain all expected blocks with valid dimensions before performing the zoom. Also updated fallback dimensions in fitViewToBounds to use BLOCK_DIMENSIONS constants (250px width instead of 200px) for accurate bounds calculation.

  • Replaced immediate zoom attempt with pending state tracking using pendingZoomBlockIdsRef
  • Added Phase 2 effect that triggers when displayNodes updates with valid node dimensions
  • Fixed fallback dimensions to match actual rendered block sizes (250px × 100px)
  • Improved reliability by ensuring nodes are fully rendered before zooming

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The refactoring improves reliability by properly waiting for nodes to have valid dimensions before zooming. The two-phase approach is well-structured, uses React patterns correctly, and includes proper cleanup. The fallback dimension fix aligns with actual block sizes, preventing miscalculations.
  • No files require special attention

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/workflow.tsx Refactored zoom logic from polling approach to event-driven two-phase system that waits for nodes to have valid dimensions before zooming
apps/sim/hooks/use-canvas-viewport.ts Updated fallback dimensions to use BLOCK_DIMENSIONS constants (250px width, 100px height) for accurate bounds calculation

Sequence Diagram

sequenceDiagram
    participant Copilot
    participant Phase1 Effect
    participant Ref as pendingZoomBlockIdsRef
    participant Phase2 Effect
    participant DisplayNodes
    participant Viewport

    Copilot->>Phase1 Effect: isDiffReady = true
    Note over Phase1 Effect: Triggered when diff becomes ready
    Phase1 Effect->>Phase1 Effect: Extract changedBlockIds from diffAnalysis
    alt Has changed blocks
        Phase1 Effect->>Ref: Store Set(changedBlockIds)
        Note over Ref: Pending zoom request recorded
    else No changed blocks
        Phase1 Effect->>Viewport: fitViewToBounds (all nodes)
    end
    
    Note over DisplayNodes: React updates displayNodes state
    DisplayNodes->>Phase2 Effect: displayNodes updated
    Phase2 Effect->>Ref: Read pendingBlockIds
    alt No pending zoom
        Phase2 Effect->>Phase2 Effect: Return early
    else Has pending zoom
        Phase2 Effect->>DisplayNodes: Filter for pending nodes
        Phase2 Effect->>Phase2 Effect: Check all nodes have valid dimensions
        alt All nodes ready
            Phase2 Effect->>Ref: Clear pending state (null)
            Phase2 Effect->>Viewport: requestAnimationFrame
            Viewport->>Viewport: fitViewToBounds(pendingNodes)
            Note over Viewport: Zoom to changed blocks
        else Nodes not ready yet
            Phase2 Effect->>Phase2 Effect: Wait for next displayNodes update
        end
    end
    
    alt Diff cleared/rejected
        Copilot->>Phase1 Effect: isDiffReady = false
        Phase1 Effect->>Ref: Clear pending state (null)
        Note over Ref: Cancel pending zoom
    end
Loading

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.

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1 waleedlatif1 merged commit ebf2852 into staging Jan 26, 2026
12 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/copilotzoom branch January 26, 2026 21:54
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.

2 participants