Skip to content

fix: reconnect terminal on non-modified key presses #9686

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 5 commits into from
Sep 18, 2023

Conversation

code-asher
Copy link
Member

Fixes #8547
Fixes #6732

Instead of bubbling.  I think maybe what happens here is that xterm is
capturing key presses and preventing the event from bubbling?  So
setting the listener on the capture phase instead works around this.
Probably would also work to dipsose the terminal.
I am not sure this actually causes any issues, but might as well.
@code-asher code-asher force-pushed the asher/web-terminal-any-key branch from 0eb56e6 to 85ffce8 Compare September 14, 2023 22:10
@code-asher code-asher requested review from a team and aslilac and removed request for a team September 14, 2023 22:41
Copy link
Member

@aslilac aslilac left a comment

Choose a reason for hiding this comment

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

I might be missing something, but it seems like this status isn't doing anything

if (isModifier(event)) {
modifierKeyState[event.key] = true;
} else if (!isModified()) {
setStatus("reloading");
Copy link
Member

Choose a reason for hiding this comment

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

kind of a nit: this call won't really do anything. window.location.reload() will block/kill the execution context before the event loop circles back to this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I thought the same thing, it could depend on the browser or something, but in Chromium I tested via a console.log statement and it will happily run multiple times until the reload "kicks in".

Copy link
Member Author

Choose a reason for hiding this comment

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

That said, running window.location.reload() multiple times is probably harmless.

Copy link
Member Author

@code-asher code-asher Sep 15, 2023

Choose a reason for hiding this comment

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

One more thing, setting the status here to reloading causes the overlay to display "Reloading...", so whatever window.location.reload() is doing, it appears to not quite be instant, or there is some other trick at play here.

Copy link
Member

Choose a reason for hiding this comment

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

wow, ok 😅 I thought I'd even played with this before and touching location instantly killed your code

Copy link
Member

@aslilac aslilac Sep 15, 2023

Choose a reason for hiding this comment

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

that said, it seems like this would benefit from being instant, rather than waiting for react to do an update cycle. maybe we should use useRef for this?

although I guess the ui uses this... maybe it needs to be both 🙃

Copy link
Member Author

@code-asher code-asher Sep 15, 2023

Choose a reason for hiding this comment

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

lol I know what you mean, I could have sworn I did and saw the same!

Copy link
Member Author

@code-asher code-asher Sep 15, 2023

Choose a reason for hiding this comment

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

Oh right, good point. Maybe it would be nice if the UI could update immediately as well since if the reload happens too fast they might never see the Reloading... text? Wonder if we can force an update or something.

Copy link
Member Author

Choose a reason for hiding this comment

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

I experimented a bit to see if I could get the keydown handler firing twice before React updates and the listener is removed but apparently I am not able to mash a key fast enough lol

I did find a bug though, if you ctrl+tab away then come back via click, the page still thinks ctrl is being pressed and nothing will reload until you press and release ctrl again. Not sure if this can be solved with keydown...too bad it is not like the deprecated keypress event that would tell you if modifier keys were being held down.

Copy link
Member Author

@code-asher code-asher Sep 15, 2023

Choose a reason for hiding this comment

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

Wait what no keydown does have that information. What am I even doing?? Will refactor. It does not cover all the keys listed in documentation as modifiers, but all the ones that really matter imo.

code-asher and others added 2 commits September 15, 2023 13:39
Co-authored-by: Kayla Washburn <mckayla@hey.com>
Instead of manually tracking modifiers with keydown/keyup, as this can
miss keys like in the case of ctrl+tab, leaving ctrl in a permanent "on"
state.

The other modifiers do not appear to be used in conjunction with other
keys, except possibly Fn?  So this should be more or less the same
functionality.
@code-asher code-asher force-pushed the asher/web-terminal-any-key branch from e86fdfb to 9cab143 Compare September 15, 2023 22:45
@code-asher code-asher requested a review from aslilac September 15, 2023 23:18
Copy link
Member

@aslilac aslilac left a comment

Choose a reason for hiding this comment

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

👍

@code-asher code-asher merged commit 17f9991 into main Sep 18, 2023
@code-asher code-asher deleted the asher/web-terminal-any-key branch September 18, 2023 15:24
@github-actions github-actions bot locked and limited conversation to collaborators Sep 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants