Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • Fix terminal collapsed state not persisting across page refresh
  • Skip auto-open trigger for hydrated console entries on initial load
  • Reset entry tracking when switching workflows

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 27, 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 27, 2026 7:29pm

Request Review

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 27, 2026

Greptile Overview

Greptile Summary

Prevents terminal from auto-opening on page refresh by tracking initialization state and skipping the first sync after console hydration.

Changes

  • Added hasInitializedEntriesRef to track whether the component has processed the initial hydrated entries
  • Skip auto-open trigger when console first hydrates to prevent expanding terminal for persisted entries
  • Reset initialization state when switching workflows to ensure auto-open works correctly per workflow
  • Added activeWorkflowId and hasConsoleHydrated to effect dependencies for proper reactivity

How it Works

The fix uses a flag pattern to distinguish between:

  1. Initial hydration: When persisted console entries are restored from storage (should NOT auto-open)
  2. New entries: When workflow execution adds fresh entries (should auto-open if openOnRun is enabled)

The hasInitializedEntriesRef is reset when switching workflows, ensuring each workflow's first real execution can trigger auto-open.

Confidence Score: 5/5

  • This PR is safe to merge with no issues found
  • The implementation correctly solves the bug using a clean flag pattern that distinguishes between hydrated and new entries. The logic is well-commented, follows React best practices, and properly manages effect dependencies.
  • No files require special attention

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/terminal/terminal.tsx Added hasInitializedEntriesRef to skip auto-open on hydrated entries and reset tracking on workflow switch

Sequence Diagram

sequenceDiagram
    participant User
    participant Browser
    participant Terminal
    participant Store
    participant Effect

    Note over Browser,Store: Page Refresh / Initial Load
    Browser->>Store: Rehydrate terminal state
    Store-->>Browser: terminalHeight, console entries
    Browser->>Terminal: Mount component
    Terminal->>Effect: Run auto-open effect
    
    alt Console not yet hydrated
        Effect->>Effect: hasConsoleHydrated = false
        Effect->>Effect: Exit early
    end
    
    alt First run after hydration
        Effect->>Effect: hasInitializedEntriesRef = false
        Effect->>Effect: Set hasInitializedEntriesRef = true
        Effect->>Effect: Store current length
        Effect->>Effect: Skip auto-open (prevent opening on hydrated entries)
    end

    Note over User,Effect: New Workflow Run
    User->>Terminal: Execute workflow
    Terminal->>Store: Add console entry
    Store->>Terminal: New entry added
    Terminal->>Effect: allWorkflowEntries.length increased
    
    alt openOnRun enabled & terminal collapsed
        Effect->>Terminal: expandToLastHeight()
        Terminal->>Store: setTerminalHeight(lastExpandedHeight)
        Store->>Browser: Update CSS variable
        Browser->>User: Terminal expands
    end

    Note over User,Effect: Switch Workflows
    User->>Terminal: Navigate to different workflow
    Terminal->>Effect: activeWorkflowId changed
    Effect->>Effect: Reset hasInitializedEntriesRef = false
    Effect->>Effect: Re-initialize for new workflow
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

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.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

@waleedlatif1
Copy link
Collaborator Author

@greptile

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 416c082 into staging Jan 27, 2026
12 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/terminal branch January 27, 2026 19:38
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