Repository navigation
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 branch has not been deployed
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
When you first open a ttyd session the terminal doesn’t fill its container, leaving empty space along the right and bottom edges. The only way it corrects itself is if you resize the browser window.
Root cause
Xterm.open()callsfitAddon.fit()immediately afterterminal.open(), while the default DOM renderer is still active. Shortly after that theSET_PREFERENCESmessage switches the renderer to webgl. Webgl measures cell sizes a little differently than the DOM renderer, but nothing triggers another fit after the switch, so the terminal keeps the stale dimensions until a real window resize happens.Fix
applyPreferences()now callsfitAddon.fit()once after every preference has been applied, including the renderer type. This replaces the earlier font-only refit that never caught the renderer change.While fixing that I also cleaned up a pre-existing build break. Preact’s
RefCallbacktype now allows an optional cleanup return, so the bare assignment interminal/index.tsxno longer type-checks. I wrapped the callback so it returns void and regeneratedsrc/html.hfrom the updated frontend.Verification
I built the production bundle together with the ttyd binary and served it against a mock of the websocket handshake in headless Chromium at 1000x700. Before the change the terminal loaded at
cols=125and a same-viewport resize event pushed it tocols=135. After the change it loads atcols=135right away and the same resize does nothing. Bothtsc --noEmitandnpm run buildpass cleanly.