From 4e4bb4e390ce7c2fd7368c8112fffe6bac5729e2 Mon Sep 17 00:00:00 2001 From: howdeploy Date: Tue, 27 Oct 2026 00:46:06 +0300 Subject: [PATCH 1/3] Fix terminal zoom limits and renderer text overlap --- .../src/features/terminal/TerminalCard.tsx | 26 +++---- .../workspace/useCanvasWheelNavigation.ts | 11 +-- tests/canvas-zoom-limits.test.mjs | 69 +++++++++++++++++++ tests/terminal-renderer-transition.test.mjs | 31 ++++++--- 4 files changed, 110 insertions(+), 27 deletions(-) create mode 100644 tests/canvas-zoom-limits.test.mjs diff --git a/src/renderer/src/features/terminal/TerminalCard.tsx b/src/renderer/src/features/terminal/TerminalCard.tsx index 780a3a821..243c2fe87 100644 --- a/src/renderer/src/features/terminal/TerminalCard.tsx +++ b/src/renderer/src/features/terminal/TerminalCard.tsx @@ -309,10 +309,11 @@ function TerminalCardView({ const fitRef = useRef<(() => void) | null>(null); const rendererTransitionRef = useRef<{ snapshot: HTMLElement; + screen: HTMLElement; + visibility: string; frame: number | null; render: { dispose(): void } | null; fallback: number | null; - animation: Animation | null; visibilityCleanup: (() => void) | null; } | null>(null); const restoreRendererTransition = (): void => { @@ -323,8 +324,8 @@ function TerminalCardView({ if (transition.fallback !== null) window.clearTimeout(transition.fallback); transition.visibilityCleanup?.(); transition.render?.dispose(); - transition.animation?.cancel(); transition.snapshot.remove(); + transition.screen.style.visibility = transition.visibility; }; const beginRendererTransition = (terminal: Terminal): HTMLElement | null => { restoreRendererTransition(); @@ -359,16 +360,19 @@ function TerminalCardView({ return null; } element.append(snapshot); + const visibility = screen.style.visibility; + screen.style.visibility = "hidden"; const onVisibilityChange = (): void => { if (document.hidden) restoreRendererTransition(); }; document.addEventListener("visibilitychange", onVisibilityChange); rendererTransitionRef.current = { snapshot, + screen, + visibility, frame: null, render: null, fallback: window.setTimeout(restoreRendererTransition, 250), - animation: null, visibilityCleanup: () => document.removeEventListener("visibilitychange", onVisibilityChange) }; return snapshot; @@ -376,26 +380,18 @@ function TerminalCardView({ const revealRendererTransition = (terminal: Terminal, snapshot: HTMLElement): void => { const transition = rendererTransitionRef.current; if (!transition || transition.snapshot !== snapshot) return; - const fadeAfterPaint = (): void => { + const removeAfterPaint = (): void => { if (rendererTransitionRef.current !== transition) return; transition.frame = null; - if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) { - restoreRendererTransition(); - return; - } - transition.animation = snapshot.animate([{ opacity: 1 }, { opacity: 0 }], { - duration: 180, easing: "ease-out", fill: "forwards" - }); - transition.animation.onfinish = () => { - if (rendererTransitionRef.current === transition) restoreRendererTransition(); - }; + // Different renderer cell grids must never be blended into double text. + restoreRendererTransition(); }; const ready = (): void => { if (rendererTransitionRef.current !== transition || transition.frame !== null) return; transition.render?.dispose(); transition.render = null; transition.frame = requestAnimationFrame(() => { - transition.frame = requestAnimationFrame(fadeAfterPaint); + transition.frame = requestAnimationFrame(removeAfterPaint); }); }; transition.render = terminal.onRender(ready); diff --git a/src/renderer/src/features/workspace/useCanvasWheelNavigation.ts b/src/renderer/src/features/workspace/useCanvasWheelNavigation.ts index 51fbfb449..6e1561eb1 100644 --- a/src/renderer/src/features/workspace/useCanvasWheelNavigation.ts +++ b/src/renderer/src/features/workspace/useCanvasWheelNavigation.ts @@ -67,9 +67,11 @@ export function useCanvasWheelNavigation({ const [panGesture] = useState(() => createGestureSettle(setWheelPanning)); const zoomAt = useCallback((clientX: number, clientY: number, nextZoom: number): void => { + const camera = cameraRef.current; + // At a zoom limit, avoid re-rasterizing the scene or introducing sub-pixel camera drift. + if (nextZoom === camera.zoom) return; const bounds = viewport.current?.getBoundingClientRect(); if (!bounds) return; - const camera = cameraRef.current; const localX = clientX - bounds.left; const localY = clientY - bounds.top; const worldX = (localX - camera.x) / camera.zoom; @@ -124,9 +126,8 @@ export function useCanvasWheelNavigation({ return; } flushPan(); - markZoomGesture(); zoomAccumulator.push({ clientX: event.clientX, clientY: event.clientY, factor: intent.factor }); - }, [flushPan, markZoomGesture, panAccumulator, panGesture, zoomAccumulator]); + }, [flushPan, panAccumulator, panGesture, zoomAccumulator]); useEffect(() => () => { panAccumulator.dispose(); @@ -235,12 +236,14 @@ export function useCanvasWheelNavigation({ useEffect(() => window.canvasTTY.browser.onCanvasWheel(applyCanvasWheel), [applyCanvasWheel]); const zoomBy = useCallback((factor: number): void => { + const nextZoom = clamp(cameraRef.current.zoom * factor, 0.2, 1.35); + if (nextZoom === cameraRef.current.zoom) return; const bounds = viewport.current?.getBoundingClientRect(); if (!bounds) return; zoomAt( bounds.left + bounds.width / 2, bounds.top + bounds.height / 2, - clamp(cameraRef.current.zoom * factor, 0.2, 1.35) + nextZoom ); }, [cameraRef, viewport, zoomAt]); diff --git a/tests/canvas-zoom-limits.test.mjs b/tests/canvas-zoom-limits.test.mjs new file mode 100644 index 000000000..b2ea4f28c --- /dev/null +++ b/tests/canvas-zoom-limits.test.mjs @@ -0,0 +1,69 @@ +import assert from "node:assert/strict"; +import test from "node:test"; +import { importWithFakeReact } from "./helpers/fake-react.mjs"; + +async function fixture(t, zoom) { + const previous = { window: globalThis.window, requestAnimationFrame: globalThis.requestAnimationFrame, + cancelAnimationFrame: globalThis.cancelAnimationFrame }; + const frames = new Map(), timers = new Map(); + let id = 0, reads = 0; + const window = Object.assign(new EventTarget(), { + setTimeout: callback => { timers.set(++id, callback); return id; }, + clearTimeout: handle => timers.delete(handle), + canvasTTY: { + canvasNavigation: { armOwnerWheelSequence() {}, setPointerBindingState() {}, onOverrideState: () => () => {} }, + browser: { onCanvasWheel: () => () => {} } + } + }); + Object.assign(globalThis, { window, + requestAnimationFrame: callback => { frames.set(++id, callback); return id; }, + cancelAnimationFrame: handle => frames.delete(handle) }); + const hook = await importWithFakeReact("src/renderer/src/features/workspace/useCanvasWheelNavigation.ts", "useCanvasWheelNavigation"); + const cameraRef = { current: { x: -123.45, y: 67.89, zoom } }; + const commits = []; + const viewport = Object.assign(new EventTarget(), { + classList: { toggle() {} }, + getBoundingClientRect() { reads++; return {left:0,top:0,width:1000,height:800}; } + }); + const controller = hook.__render(hook.useCanvasWheelNavigation, { + viewport: {current: viewport}, cameraRef, widgetFocusRef: {current: {id: null}}, + settings: {useScrollWheelToZoom:true,zoomSensitivity:"normal",invertCanvasWheel:false,canvasWheelCaptureMode:"off"}, + commitCamera(next) { commits.push(next); cameraRef.current = next; } + }); + t.after(() => { hook.__unmount(); Object.assign(globalThis, previous); }); + return { controller, cameraRef, commits, timers, pending: hook.__pending, reads: () => reads, + frame() { for (const callback of [...frames.values()]) callback(); } }; +} + +for (const [name, zoom, factor, deltaY] of [["minimum",0.2,0.82,100],["maximum",1.35,1.22,-100]]) { + test(`40 button presses at the ${name} zoom do not move or re-rasterize the scene`, async t => { + const h = await fixture(t, zoom); + const before = h.cameraRef.current; + for (let i=0;i<40;i++) h.controller.zoomBy(factor); + assert.equal(h.cameraRef.current, before); + assert.equal(h.commits.length, 0); + assert.equal(h.reads(), 0); + assert.equal(h.timers.size, 0); + assert.equal(h.pending(), 0, "no zoom-gesture state change"); + }); + test(`40 wheel events at the ${name} zoom do not move or re-rasterize the scene`, async t => { + const h = await fixture(t, zoom); + for(let i=0;i<40;i++) h.controller.applyCanvasWheel({clientX:501,clientY:399,deltaX:0,deltaY,ctrlKey:false,metaKey:false}); + h.frame(); + assert.equal(h.commits.length, 0); + assert.equal(h.reads(), 0); + assert.equal(h.timers.size, 0); + assert.equal(h.pending(), 0, "no zoom-gesture state change"); + }); +} + +test("zoom still moves normally and keeps the centre anchored below a limit", async t => { + const h = await fixture(t, 0.92); + const before = h.cameraRef.current; + h.controller.zoomBy(1.22); + assert.equal(h.commits.length, 1); + const after = h.cameraRef.current; + assert.equal(after.zoom, before.zoom*1.22); + assert.ok(Math.abs((500-before.x)/before.zoom-(500-after.x)/after.zoom)<1e-9); + assert.ok(Math.abs((400-before.y)/before.zoom-(400-after.y)/after.zoom)<1e-9); +}); diff --git a/tests/terminal-renderer-transition.test.mjs b/tests/terminal-renderer-transition.test.mjs index 5e5ac178b..769645263 100644 --- a/tests/terminal-renderer-transition.test.mjs +++ b/tests/terminal-renderer-transition.test.mjs @@ -48,6 +48,7 @@ function fixture({ render = true, reducedMotion = false } = {}) { } }; const screen = { + style: { visibility: "inherit" }, offsetLeft: 0, offsetTop: 0, checkVisibility() { return true; }, @@ -89,22 +90,22 @@ function fixture({ render = true, reducedMotion = false } = {}) { const pending = [...frames.values()]; frames.clear(); for (const callback of pending) callback(); }; - return { snapshot, document, start, cancel, advance, frame, + return { snapshot, screen, document, start, cancel, advance, frame, pending: () => timers.size + frames.size + renders.size, counts: () => ({ timers: timers.size, frames: frames.size, renders: renders.size }) }; } -test("a visible transition fades only after the new render and two paint frames", () => { +test("the opaque snapshot is removed after the new render and two paint frames without blending text", () => { const h = fixture(); h.start(); + assert.equal(h.screen.style.visibility, "hidden", "the new renderer cannot show through a transparent snapshot"); assert.equal(h.snapshot.animation, null); h.frame(); assert.equal(h.snapshot.animation, null); h.frame(); - assert.ok(h.snapshot.animation); - assert.equal(h.snapshot.isConnected, true); - h.snapshot.animation.onfinish(); + assert.equal(h.snapshot.animation, null); assert.equal(h.snapshot.isConnected, false); + assert.equal(h.screen.style.visibility, "inherit"); assert.deepEqual(h.counts(), { timers: 0, frames: 0, renders: 0 }); }); @@ -115,6 +116,7 @@ for (const render of [false, true]) { assert.equal(h.snapshot.isConnected, true); h.advance(1); assert.equal(h.snapshot.isConnected, false); + assert.equal(h.screen.style.visibility, "inherit"); assert.deepEqual(h.counts(), { timers: 0, frames: 0, renders: 0 }); h.frame(); assert.equal(h.snapshot.animation, null); @@ -127,20 +129,33 @@ test("hiding the document removes the snapshot before any suspended frames or ti h.document.hidden = true; h.document.dispatchEvent(new Event("visibilitychange")); assert.equal(h.snapshot.isConnected, false); + assert.equal(h.screen.style.visibility, "inherit"); assert.deepEqual(h.counts(), { timers: 0, frames: 0, renders: 0 }); }); -test("teardown cancels a pending render, frames and an active fade", () => { - for (const phase of ["render", "frame", "fade"]) { +test("teardown cancels a pending render or frames and is harmless after paint", () => { + for (const phase of ["render", "frame", "paint"]) { const h = fixture({ render: phase !== "render" }); h.start(); - if (phase === "fade") { h.frame(); h.frame(); } + if (phase === "paint") { h.frame(); h.frame(); } h.cancel(); h.cancel(); assert.equal(h.snapshot.isConnected, false); + assert.equal(h.screen.style.visibility, "inherit"); assert.deepEqual(h.counts(), { timers: 0, frames: 0, renders: 0 }); if (h.snapshot.animation) assert.equal(h.snapshot.animation.canceled, true); h.advance(1_000); h.frame(); assert.equal(h.snapshot.isConnected, false); + assert.equal(h.screen.style.visibility, "inherit"); + } +}); + +test("40 renderer transitions leave no snapshots, animations or pending work", () => { + const h = fixture(); + for (let cycle = 0; cycle < 40; cycle++) { + h.start(); h.frame(); h.frame(); + assert.equal(h.snapshot.animation, null); + assert.equal(h.snapshot.isConnected, false); + assert.deepEqual(h.counts(), { timers: 0, frames: 0, renders: 0 }); } }); From edcd4b56b2b8456bb671462980de4e719b7b6e37 Mon Sep 17 00:00:00 2001 From: howdeploy Date: Tue, 27 Oct 2026 00:49:19 +0300 Subject: [PATCH 2/3] Prepare evaluation hotfix 1.8.3-hotfix.1 --- .github/workflows/release.yml | 2 +- CHANGELOG.md | 8 ++++++++ CHANGELOG.ru.md | 8 ++++++++ CHANGELOG.zh-CN.md | 8 ++++++++ package-lock.json | 4 ++-- package.json | 2 +- scripts/verify-release-artifacts.mjs | 6 +++--- tests/release-artifacts.test.mjs | 9 ++++++++- 8 files changed, 39 insertions(+), 8 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ca898bfa1..5844eb714 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -169,6 +169,6 @@ jobs: --generate-notes ) if [[ "${GITHUB_REF_NAME}" == *-* ]]; then - args+=(--prerelease) + args+=(--prerelease --latest=false) fi gh "${args[@]}" diff --git a/CHANGELOG.md b/CHANGELOG.md index 2aabbca0f..04e8a33fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ [English](CHANGELOG.md) · [Русский](CHANGELOG.ru.md) · [简体中文](CHANGELOG.zh-CN.md) +## 1.8.3.1 — evaluation hotfix + +Technical version: `1.8.3-hotfix.1`. This is a prerelease for manual evaluation. + +- Stop redundant scene work and camera drift when repeated zoom commands hit the 20% or 135% limit. +- Stop blending old and new terminal character grids during DOM/WebGL switches. Keep the new screen hidden behind the snapshot until it is ready, including transparent themes, and restore it on every cleanup path. +- The reported sustained 1 FPS and occasional crash were not reproduced in the bounded Linux probes; this release does not claim to resolve every performance issue. + ## 1.8.3 - Added canvas Auto-sort by task, status, project or grid, with scoped movement and undo (#163, @BIackFIame). diff --git a/CHANGELOG.ru.md b/CHANGELOG.ru.md index 63f99df81..82c2d6bc1 100644 --- a/CHANGELOG.ru.md +++ b/CHANGELOG.ru.md @@ -2,6 +2,14 @@ [English](CHANGELOG.md) · [Русский](CHANGELOG.ru.md) · [简体中文](CHANGELOG.zh-CN.md) +## 1.8.3.1 — оценочный хотфикс + +Техническая версия: `1.8.3-hotfix.1`. Предварительный выпуск для ручной проверки. + +- Убраны лишние обновления сцены и дрейф камеры при повторных командах зума на пределах 20% и 135%. +- Убрано смешивание старой и новой сетки символов при переключении DOM/WebGL. Новый экран скрыт за снимком до готовности, в том числе в прозрачных темах; видимость восстанавливается при любом завершении перехода. +- Устойчивые просадки до 1 FPS и редкие падения в ограниченных Linux-прогонах не воспроизведены; исправление всех проблем производительности не заявляется. + ## 1.8.3 - Автосортировка окон по задаче, состоянию, проекту или сетке с отменой перемещения: #163, @BIackFIame. diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md index d74f5ac09..7a058bd54 100644 --- a/CHANGELOG.zh-CN.md +++ b/CHANGELOG.zh-CN.md @@ -2,6 +2,14 @@ [English](CHANGELOG.md) · [Русский](CHANGELOG.ru.md) · [简体中文](CHANGELOG.zh-CN.md) +## 1.8.3.1 — 评估热修复 + +技术版本:`1.8.3-hotfix.1`。用于手动评估的预发布版本。 + +- 重复缩放命令达到 20% 或 135% 限制时,不再触发多余的场景更新或相机漂移。 +- DOM/WebGL 切换时不再混合新旧终端字符网格。新画面就绪前隐藏在快照后方,透明主题同样适用,并在所有清理路径恢复可见性。 +- 有限的 Linux 测试未复现持续 1 FPS 或偶发崩溃;本版本不宣称解决所有性能问题。 + ## 1.8.3 - 新增按任务、状态、项目或网格自动排列窗口,并可撤销移动(#163,@BIackFIame)。 diff --git a/package-lock.json b/package-lock.json index fa8a1283e..43d6f6cb8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "canvastty", - "version": "1.8.3", + "version": "1.8.3-hotfix.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "canvastty", - "version": "1.8.3", + "version": "1.8.3-hotfix.1", "hasInstallScript": true, "license": "MIT", "workspaces": [ diff --git a/package.json b/package.json index 8e92aab02..698f4db28 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "canvastty", - "version": "1.8.3", + "version": "1.8.3-hotfix.1", "private": true, "description": "A spatial desktop for local AI agents and real terminal sessions.", "desktopName": "CanvasTTY", diff --git a/scripts/verify-release-artifacts.mjs b/scripts/verify-release-artifacts.mjs index 10f3e19e4..89020366c 100644 --- a/scripts/verify-release-artifacts.mjs +++ b/scripts/verify-release-artifacts.mjs @@ -6,8 +6,8 @@ import YAML from "yaml"; const [tag, directory = "release-artifacts"] = process.argv.slice(2); const manifest = JSON.parse(await readFile(new URL("../package.json", import.meta.url), "utf8")); -if (!/^v\d+\.\d+\.\d+$/.test(tag ?? "") || tag.slice(1) !== manifest.version) { - throw new Error(`Release tag must equal package version v${manifest.version} and be stable`); +if (!/^v\d+\.\d+\.\d+(?:-hotfix\.\d+)?$/.test(tag ?? "") || tag.slice(1) !== manifest.version) { + throw new Error(`Release tag must equal package version v${manifest.version} and be stable or a hotfix prerelease`); } const names = await readdir(resolve(directory)); const version = manifest.version.replaceAll(".", "\\."); @@ -65,4 +65,4 @@ if (!appcast.includes(`${manifest.version}`) !appcast.includes("sparkle:edSignature=") || !appcast.includes("