Skip to content

fix: initialize terminal with correct size #10369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 24, 2023
Merged

Conversation

code-asher
Copy link
Member

@code-asher code-asher commented Oct 20, 2023

Currently we spawn the terminal at 80x80 (the default when no initial size is provided) and then resize shortly afterward.

It appears that screen sometimes ignores this resize, but at the same time it seems to remember it because trying to resize it again with that size does nothing.

The solution seems to be to start screen with the right size from the get-go. From my testing, this fixes #9806. It can be done by providing the size as query parameters on the web socket URL.

I also tweaked the fitAddon calls and fixed an issue with every message causing a resize (more info in the commit messages).

This does not fix any bugs (that I know of) but we only need to fit once
when the terminal is created, not every time we reconnect.  Granted,
currently we do not support reconnecting without refreshing anyway so it
does not really matter, but this just seems more correct.

Plus now we will not have to pass the fit addon around.
I think this will solve an issue where screen does does not correctly
handle an immediate resize.  It seems to ignore the resize, but even if
you send it again nothing changes, seemingly thinking it is already at
that size?
Decoding a JSON message does not touch omitted (or null) fields so once
a message with a resize comes in, every single message from that point
will cause a resize.

I am not sure if this is an actual problem in practice but at the very
least it seems unintentional.
@code-asher code-asher force-pushed the asher/init-terminal-size branch from 1ab2f22 to eb2afb6 Compare October 20, 2023 19:07
@code-asher code-asher requested review from a team and Parkreiner and removed request for a team October 20, 2023 19:56
Copy link
Member

@Parkreiner Parkreiner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look good. Just had a few questions

window.addEventListener("resize", listener);

// Terminal is correctly sized and is ready to be used.
setTerminal(terminal);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is moving the setTerminal call just for clarity? Just making sure – because of how/when React flushes state changes, moving the call in this case doesn't actually change anything

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup exactly, I just felt it flowed better but that is probably rather subjective.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest part of me also wanted to move it just because I do not necessarily trust what React does behind the scenes hahaha, this way I think the intent is clearer at least even if it is functionally identical.

// We have to fit twice here. It's unknown why, but the first fit will
// overflow slightly in some scenarios. Applying a second fit resolves this.
fitAddon.fit();
fitAddon.fit();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know much about xterm, but moving the calls does seem like a good change.

Just making sure for my own understanding – is the terminal expected to resize only when the browser/window viewport does?

Copy link
Member Author

@code-asher code-asher Oct 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, exactly. We set the size on page load, send the current size on connect, and we only need resize events on subsequent size changes of the viewport.

@code-asher code-asher merged commit 4af8446 into main Oct 24, 2023
@code-asher code-asher deleted the asher/init-terminal-size branch October 24, 2023 03:42
@github-actions github-actions bot locked and limited conversation to collaborators Oct 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Web terminal is unusable with nano/vim etc
2 participants