Skip to content

fix(terminal): persist collapsed state across page refresh - #3023

Merged
waleedlatif1 merged 2 commits into
stagingfrom
fix/terminal
Jan 27, 2026
Merged

fix(terminal): persist collapsed state across page refresh#3023
waleedlatif1 merged 2 commits into
stagingfrom
fix/terminal

Conversation

@waleedlatif1

Copy link
Copy Markdown
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

vercelBot commented Jan 27, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
ProjectDeploymentReviewUpdated (UTC)
docsSkippedSkippedJan 27, 2026 7:29pm

Request Review

@greptile-apps

greptile-appsBot commented Jan 27, 2026

Copy link
Copy Markdown
Contributor

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

FilenameOverview
apps/sim/app/workspace/[workspaceId]/w/[workflowId]/components/terminal/terminal.tsxAdded 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

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown
Contributor

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

@cursorcursorBot left a comment

Copy link
Copy Markdown

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
Copy Markdown
CollaboratorAuthor

@greptile

@greptile-appsgreptile-appsBot left a comment

Copy link
Copy Markdown
Contributor

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 stagingJan 27, 2026
12 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/terminal branch January 27, 2026 19:38
royceP2 pushed a commit to arenadeveloper02/p2-sim that referenced this pull request Mar 3, 2026
…ai#3023)
* fix(terminal): persist collapsed state across page refresh
* fix(terminal): add activeWorkflowId to auto-open effect deps
Sign up for freeto 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

@waleedlatif1