fix(terminal): send initial size when WebSocket opens#9505
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
No issues found across 1 file
Architecture diagram
sequenceDiagram
participant User
participant Frontend as Terminal React Component
participant WS as WebSocket
participant FIT as fitAddon
participant Backend as Backend PTY Service
Note over User,Backend: Initialisation Race Condition
Frontend->>FIT: mount: fitAddon.fit()
FIT-->>Frontend: cols, rows (maybe 0x0)
Frontend->>WS: open() attempt
alt WS not yet OPEN (iframe/tunnel)
WS-->>Frontend: buffered / queued
Frontend->>WS: resize message (dropped)
WS-->>Backend: (nothing received)
Note over Backend: PTY stays at 0x0 winsize
else WS reaches OPEN state
WS-->>Frontend: readyState = OPEN
Frontend->>FIT: handleOpen: fitAddon.fit()
FIT-->>Frontend: current dimensions (cols>0, rows>0)
Frontend->>WS: send resize message
WS->>Backend: JSON {type:"resize", cols, rows}
Backend->>Backend: PTY winsize updated
Backend-->>User: Correct terminal layout
end
Note over User,Backend: Without fix, bash defaults to COLUMNS=80
Note over User,Backend: With fix, terminal correctly sized before user input
Contributor
There was a problem hiding this comment.
Pull request overview
Ensures the backend PTY receives correct initial terminal dimensions even when the initial fitAddon.fit() happens before the terminal WebSocket reaches OPEN, preventing the PTY from staying at an incorrect default size.
Changes:
- On WebSocket
open, triggers afitAddon.fit()and sends an explicit initialresizemessage with the current terminalcols/rows.
Contributor
Author
|
Addressed the redundant Skipping the test for now, very hard to mock this stuff out. |
The mount-time fitAddon.fit() can fire before the terminal WS reaches OPEN state (common in iframe + tunneled deployments), in which case the resize message is silently dropped and the PTY stays at its default 0x0 winsize. bash then falls back to COLUMNS=80, producing horizontal-scroll input lines and incorrect wrapping. Send the current dimensions from the open handler so the PTY is always sized before the user starts typing.
fitAddon.fit() may trigger onResize and schedule a debounced send for the same dimensions we just sent directly. Cancel the pending debounced call to avoid a redundant resize ~100ms later.
window?.__MARIMO_STATIC__ throws ReferenceError when the window identifier itself is undeclared (e.g. async work from RuntimeManager.init firing after jsdom teardown in tests) — optional chaining only handles null/undefined, not undeclared identifiers. Use a typeof guard so the function safely returns undefined in non-browser contexts. Fixes the Test FE unhandled-rejection failure on this PR.
7960cd0 to
daef387
Compare
Contributor
|
🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.23.6-dev36 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The mount-time fitAddon.fit() can fire before the terminal WS reaches
OPEN state (common in iframe + tunneled deployments), in which case the
resize message is silently dropped and the PTY stays at its default 0x0
winsize. bash then falls back to COLUMNS=80, producing horizontal-scroll
input lines and incorrect wrapping.
Send the current dimensions from the open handler so the PTY is always
sized before the user starts typing.