fix: terminal sized incorrectly on first load until window resize - #1561
Open
jolly-exe wants to merge 2 commits into
Open
fix: terminal sized incorrectly on first load until window resize#1561jolly-exe wants to merge 2 commits into
jolly-exe wants to merge 2 commits into
Conversation
added 2 commits
August 18, 2026 16:26
The initial fitAddon.fit() runs while xterm's dom renderer is active. The default rendererType preference (webgl) then loads asynchronously and measures cell size slightly differently, but nothing re-fits after the swap, so cols/rows stay pinned to the stale dom-renderer size. The terminal ends up smaller than its container until a window resize forces a fresh fit under the correct renderer. Fit once after all preferences (including renderer) are applied, replacing the narrower font-only refit.
The RefCallback type now allows returning an optional cleanup function (void | (() => void)), so the bare assignment expression no longer type-checks and blocks the production build. Wrap it to return void. Also regenerates src/html.h from the current frontend (includes the terminal resize fix).
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.
Problem
On first opening a ttyd session, the terminal doesn't fill its container —
there's dead space on the right/bottom edges — until the browser window is
resized, which silently corrects it.
Root cause
Xterm.open()callsfitAddon.fit()right afterterminal.open(), whilexterm's default
domrenderer is active. TheSET_PREFERENCESmessage thatfollows switches the renderer to the default
webgl, which measures cellsize slightly differently (e.g. 7px vs 7.8px cell width in one repro) — but
nothing re-fits after that renderer swap, so
cols/rowsstay pinned to thestale
dom-renderer measurement. Any subsequent window resize triggers afresh
fit()under the correct renderer, masking the bug.Fix
applyPreferences()now callsfitAddon.fit()once after all preferences(including
rendererType) are applied, replacing the narrowerfont-onlyrefit that missed the renderer case.
Also fixes an unrelated pre-existing build break: preact's
RefCallbacktype now allows an optional cleanup return (
void | (() => void)), so thebare assignment in
terminal/index.tsx's ref callback no longer type-checksagainst current
preactand blocksnpm run build. Wrapped it to returnvoid.src/html.his regenerated from the fixed frontend.Verification
Built the actual production bundle and the
ttydC binary, served it againsta mock of ttyd's WS handshake (
/token,/ws,SET_WINDOW_TITLE,SET_PREFERENCES) in headless Chromium at 1000×700:cols=125; dispatching a same-viewportresizeevent jumps it to
cols=135— reproduces the reported bug exactly.cols=135immediately; a same-viewport resize is ano-op (matches the previously resize-only-reachable state).
npx tsc --noEmitandnpm run buildboth pass cleanly.