Repository navigation
Release a terminal's WebGL context on detach - #224
Merged
Merged
Conversation
Every viewed Claude terminal kept its WebglAddon until dispose, and onContextLoss reloaded at once. Past Chromium's ~16-context cap each reload force-lost another terminal's context, so losses rotated through the terminals and the one on screen blanked every ~15 s. Only attached terminals now hold a context: detach() releases the addon and attach() loads it again. A loss on a detached terminal waits for the next attach, and 3 losses within 60 s keep that terminal on xterm's DOM renderer so a loss can never loop. Fixes #206 Claude goes brr.. via Dash
WebglAddon.dispose() only drops its canvas, so a released context stayed counted toward Chromium's cap until GC. Grab the addon's context before dispose and call WEBGL_lose_context after it, once the addon's own context-lost listener is gone. Move the addon's load/release/loss handling into WebglLifecycle so it can be tested in node with a stub addon: release on detach, no reload while detached, a stale addon's loss ignored, reload on attach, fallback. Refs #206 Claude goes brr.. via Dash
Claude goes brr.. via Dash
Releasing the context on every detach rebuilt it on each switch back, with a possible flicker and a new texture atlas. A pool shared by all terminals now keeps the addon on the 8 most recently attached ones and releases the least recent detached holder past that. Detach alone keeps the addon; dispose releases it and leaves the pool. Deferred reload, stale-loss guard and the 3-in-60s DOM fallback are unchanged. Refs #206 Claude goes brr.. via Dash
"Terminals kept ready" in Settings > Appearance sets how many recent terminals keep their WebGL renderer: a 2-14 slider, default 8 (14 stays under Chromium's ~16 with room for the main pane and the attach modal). It applies at once; lowering it releases the least recent off-screen terminals right away. Adds a Slider primitive on @radix-ui/react-slider. Refs #206 Claude goes brr.. via Dash
Dragging 8 to 2 and back released six terminals on the way. The shown number now follows the drag from local state, and the setting is saved and applied only on Radix's onValueCommit. Refs #206 Claude goes brr.. via Dash
Drop the setter override and the one-use clampedInt codec; the inline codec parses with parseFloat so an empty stored value falls back to 8. Refs #206 Claude goes brr.. via Dash
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.
What was wrong
Every Claude terminal loaded a
WebglAddonon first attach and kept it until the session was disposed. Chromium allows about 16 active WebGL contexts per renderer and force-loses the oldest past that.onContextLossreloaded the addon at once, which pushed another terminal over the cap, so with 17+ viewed sessions the losses kept rotating and the terminal on screen blanked about every 15 s.What changed
Sliderprimitive inui/(shadcn's, on@radix-ui/react-slider).WEBGL_lose_contextafterdispose(), so the context is freed at once instead of at GC. Dispose releases too.WebglLifecycle.ts: a pure eviction pick, a recency pool shared by all terminals with a live limit, and a per-terminal lifecycle. All of it is tested in node with a stub addon; the setting's default and 2–14 clamping have store tests.Verification
pnpm type-check,pnpm lint(0 errors) andpnpm testpass.Too many active WebGL contextswarning in DevTools, and that a re-shown terminal draws correctly with its scroll position kept. Also check the slider in Settings.Fixes #206
🤖 Generated with Claude Code