Skip to content

Conversation

@icecrasher321
Copy link
Collaborator

Summary

Grid Size not being passed through to the autolayout func.

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 28, 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 28, 2026 4:05am

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 28, 2026

Greptile Overview

Greptile Summary

This PR fixes a bug where the user's grid size preference wasn't being passed through to the autolayout functionality, causing workflow nodes to be positioned without grid alignment even when the user had snap-to-grid enabled.

Changes:

  • Added useSnapToGridSize hook to use-auto-layout.ts to fetch the user's grid preference
  • Modified the hook to merge the gridSize into layout options before calling the standalone function
  • Added gridSize property to the AutoLayoutOptions interface in auto-layout-utils.ts
  • The gridSize is now correctly forwarded through the entire autolayout pipeline: hook → utils → API → core layout engine

Impact:
The fix ensures that when users have snap-to-grid enabled, the autolayout respects this setting and positions blocks on the grid, maintaining visual consistency with manual node placement.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The change is straightforward and well-contained. It adds a missing parameter to the autolayout pipeline with proper null/undefined handling. The hook correctly reads from the existing settings API, and the gridSize parameter is already validated by the API endpoint (0-50 range). No breaking changes or risky logic introduced.
  • No files require special attention

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/hooks/use-auto-layout.ts Added useSnapToGridSize hook to automatically pass user's grid preference to autolayout
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/utils/auto-layout-utils.ts Added gridSize field to AutoLayoutOptions interface and forwarded it to API

Sequence Diagram

sequenceDiagram
    participant Component as React Component
    participant Hook as useAutoLayout Hook
    participant Settings as useSnapToGridSize
    participant Utils as applyAutoLayoutStandalone
    participant API as /api/workflows/:id/autolayout
    participant Layout as applyAutoLayout (core)

    Component->>Hook: Call handleAutoLayout()
    Hook->>Settings: Get snapToGridSize value
    Settings-->>Hook: Return gridSize (0 or positive number)
    Hook->>Hook: Merge options with gridSize
    Note over Hook: gridSize = options.gridSize ?? (snapToGridSize > 0 ? snapToGridSize : undefined)
    Hook->>Utils: applyAutoLayoutStandalone(workflowId, optionsWithGrid)
    Utils->>Utils: Prepare layoutOptions with gridSize
    Utils->>API: POST with blocks, edges, gridSize
    API->>API: Validate gridSize (0-50)
    API->>Layout: applyAutoLayout(blocks, edges, options)
    Layout->>Layout: Apply grid-aligned positioning
    Layout-->>API: Return layouted blocks
    API-->>Utils: Return success with layouted blocks
    Utils->>Utils: Update workflow store
    Utils->>API: PUT /api/workflows/:id/state
    Utils-->>Hook: Return success
    Hook->>Component: Trigger fitViewToBounds animation
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.

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@icecrasher321 icecrasher321 merged commit 0d0209a into staging Jan 28, 2026
11 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/grid-size-passthrough branch January 28, 2026 07:40
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