Skip to content

fallback to canvas renderer if webgl is not available, debug toggle for testing#3081

Merged
sawka merged 4 commits intomainfrom
sawka/webgl
Mar 18, 2026
Merged

fallback to canvas renderer if webgl is not available, debug toggle for testing#3081
sawka merged 4 commits intomainfrom
sawka/webgl

Conversation

@sawka
Copy link
Member

@sawka sawka commented Mar 18, 2026

No description provided.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3693b73a-8ac8-4219-b656-91c0d6e3e1a3

📥 Commits

Reviewing files that changed from the base of the PR and between dbd2e8d and f23ca8e.

📒 Files selected for processing (1)
  • frontend/app/view/term/termwrap.ts

Walkthrough

The changes add WebGL vs Canvas renderer selection and UI controls for the terminal. On the frontend, TermWrap exposes renderer state and lifecycle (setTermRenderer, getTermRenderer, isWebGlEnabled) and manages WebGL and Canvas addons and context-loss disposal; TermViewModel gains UI integration (getWebGlIconButton, getTermRenderer, isWebGlEnabled, toggleWebGl) to render a WebGL status/toggle button when the new debug:webglstatus setting is enabled. Type surfaces and schema are extended with the "debug:webglstatus" flag, a Go config constant and SettingsType field are added, and package.json adds the @xterm/addon-canvas dependency. Renderer selection falls back to Canvas when WebGL is unsupported or disabled.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive No pull request description was provided by the author. Add a meaningful description explaining the purpose, rationale, and testing considerations for the WebGL fallback and debug toggle feature.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: adding a WebGL to canvas fallback mechanism and a debug toggle for testing.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sawka/webgl
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 18, 2026

Deploying waveterm with  Cloudflare Pages  Cloudflare Pages

Latest commit: f23ca8e
Status: ✅  Deploy successful!
Preview URL: https://f72c83d5.waveterm.pages.dev
Branch Preview URL: https://sawka-webgl.waveterm.pages.dev

View logs

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
frontend/app/view/term/termwrap.ts (1)

49-60: ⚠️ Potential issue | 🔴 Critical

Probe WebGL2, not WebGL1.

detectWebGLSupport() probes getContext("webgl"), but @xterm/addon-webgl v5.5.0 explicitly requires WebGL2 (getContext("webgl2")). On browsers that expose WebGL1 but not WebGL2, the detection passes and line 188 selects the WebGL renderer, causing the addon to throw "WebGL2 not supported" with no fallback to canvas.

Fix
 function detectWebGLSupport(): boolean {
     try {
         const canvas = document.createElement("canvas");
-        const ctx = canvas.getContext("webgl");
+        const ctx = canvas.getContext("webgl2");
         return !!ctx;
     } catch (e) {
         return false;
     }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/app/view/term/termwrap.ts` around lines 49 - 60, The WebGL detection
currently checks for WebGL1 which causes `@xterm/addon-webgl` v5.5.0 to fail;
update detectWebGLSupport() to request a "webgl2" context (e.g.,
canvas.getContext("webgl2")) and return true only if that succeeds, leaving the
try/catch behavior intact; ensure the exported WebGLSupported constant remains
tied to this updated detectWebGLSupport() so the code that chooses the renderer
(which reads WebGLSupported) will not select the WebGL addon on browsers that
only support WebGL1.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@frontend/app/view/term/termwrap.ts`:
- Around line 49-60: The WebGL detection currently checks for WebGL1 which
causes `@xterm/addon-webgl` v5.5.0 to fail; update detectWebGLSupport() to request
a "webgl2" context (e.g., canvas.getContext("webgl2")) and return true only if
that succeeds, leaving the try/catch behavior intact; ensure the exported
WebGLSupported constant remains tied to this updated detectWebGLSupport() so the
code that chooses the renderer (which reads WebGLSupported) will not select the
WebGL addon on browsers that only support WebGL1.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 0d315c97-251b-4e21-9764-675cc9a06f4a

📥 Commits

Reviewing files that changed from the base of the PR and between 134b388 and dbd2e8d.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (7)
  • frontend/app/view/term/term-model.ts
  • frontend/app/view/term/termwrap.ts
  • frontend/types/gotypes.d.ts
  • package.json
  • pkg/wconfig/metaconsts.go
  • pkg/wconfig/settingsconfig.go
  • schema/settings.json

Copy link
Contributor

@kilo-code-bot kilo-code-bot bot left a comment

Choose a reason for hiding this comment

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

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Overview

This PR implements a WebGL to Canvas fallback mechanism for the terminal renderer, along with a debug toggle for testing purposes. The implementation is well-structured and handles edge cases properly.

Changes Reviewed

  1. termwrap.ts: WebGL detection now correctly checks for WebGL2 context (as required by @xterm/addon-webgl), with proper fallback to Canvas renderer. Added setTermRenderer, getTermRenderer, and isWebGlEnabled methods for runtime switching.

  2. term-model.ts: Added WebGL toggle button functionality accessible via the debug:webglstatus config setting. The button properly reflects WebGL state and allows runtime switching.

  3. Configuration: Added debug:webglstatus setting to enable the WebGL status button in the terminal header for testing.

  4. Dependencies: Added @xterm/addon-canvas as a new dependency.

Key Implementation Details Verified

  • WebGL context loss is handled by automatically falling back to Canvas
  • Toggle logic correctly switches between WebGL and Canvas renderers
  • Debug toggle is properly gated behind the debug:webglstatus setting
  • Atom state management for WebGL enabled status is properly initialized
Files Reviewed (7 files)
  • frontend/app/view/term/term-model.ts
  • frontend/app/view/term/termwrap.ts
  • frontend/types/gotypes.d.ts
  • package.json
  • pkg/wconfig/metaconsts.go
  • pkg/wconfig/settingsconfig.go
  • schema/settings.json

@sawka sawka merged commit c126306 into main Mar 18, 2026
8 checks passed
@sawka sawka deleted the sawka/webgl branch March 18, 2026 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant