-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add WebGL addon to web termal #36763
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Orca Security Scan Summary
Status | Check | Issues by priority | |
---|---|---|---|
Passed | Infrastructure as Code | 0 0 0 0 | View in Orca |
Failed | Vulnerabilities | 3 1 0 0 | View in Orca |
Passed | Secrets | 0 0 0 0 | View in Orca |
@@ -78,6 +80,12 @@ export default class TtyTerminal { | |||
|
|||
this.term.loadAddon(this._fitAddon); | |||
this.term.loadAddon(this._webLinksAddon); | |||
// handle context loss and load webgl addon | |||
this._webglAddon.onContextLoss(() => { | |||
this._webglAddon.dispose(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think we need to also call this in the destory()
func.
i'm not sure i understand what the onContextLoss
does, but shouldn't we try to re-instantiate it after disposing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we need it in destroy()
for sure. thank you!
onContextLoss
is essentially when the browser loses access to the GPU when rendering (if you do some weird driver updates or some kind of switch between GPUs). it's rare. However, the addon itself runs a timeout internally to automatically reinstantiate after a couple seconds and keeps trying.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs say:
An easy, but suboptimal way, to handle this is to..
Is there a more optimal way to handle this scenario?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need a fallback to canvas renderer? Do we need any sort of feature detection in case webgl is not available?
We dont need to, it falls back to the dom renderer by default. Also, the "suboptimal" way I believe is them talking about just disposing and falling back to dom rendering. I checked out vscode and they basically do webgl -> canvas -> dom. I can do the same here
the |
// wont start looking for the context again until the OS has given the browser the context again. | ||
// When the initial context lost event is fired, the webgl addon consumes the event | ||
// and waits for a bit to see if it can get the context back. If it fails repeatedly, it | ||
// will propegate the context loss event itself in which case we fall back to context. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// will propegate the context loss event itself in which case we fall back to context. | |
// will propagate the context loss event itself in which case we fall back to canvas. |
@@ -77,7 +81,28 @@ export default class TtyTerminal { | |||
}); | |||
|
|||
this.term.loadAddon(this._fitAddon); | |||
this.term.loadAddon(this._webLinksAddon); | |||
// this.term.loadAddon(this._webLinksAddon); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No more link support? 😕
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh my goodness thank you for catching this
@@ -98,6 +123,21 @@ export default class TtyTerminal { | |||
window.addEventListener('resize', this._debouncedResize); | |||
} | |||
|
|||
fallbackToCanvas() { | |||
console.log('WebGL context lost. Falling back to canvas'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we use our logger instead of console here?
} catch (err) { | ||
this.fallbackToCanvas(); | ||
} | ||
this.term.loadAddon(this._webglAddon); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we doing this twice?
try { | ||
// try to create a new WebglAddon. If webgl is not supported, this | ||
// constructor will throw an error and fallback to canvas. We also fallback | ||
// to canvas is the webgl context is lost after a timeout. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// to canvas is the webgl context is lost after a timeout. | |
// to canvas if the webgl context is lost after a timeout. |
logger.info('WebGL context lost. Falling back to canvas'); | ||
this._webglAddon.dispose(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems safer since it's initially undefined
logger.info('WebGL context lost. Falling back to canvas'); | |
this._webglAddon.dispose(); | |
logger.info('WebGL context lost. Falling back to canvas'); | |
this._webglAddon?.dispose(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
absolutely right. ty
This will add the
xterm-webgl-addon
to the web ui (not Connect) to help properly display underscores (and perhaps other characters that we haven't discovered).Tested on Ubuntu 24
Without addon (there should be an underscore between "testing" and "thing")
With addon
changelog: The web terminal now properly displays underscores on Linux