From 5abc68173f622986baf2a46e4e8c656ec245152a Mon Sep 17 00:00:00 2001 From: ZacharyZcR Date: Sat, 14 Nov 2026 19:42:14 +0800 Subject: [PATCH] fix: stop a fitted remote display from resizing in a loop The display container scrolled at every zoom. Fitted to the container at 100%, a pixel of rounding made the display overflow, the scrollbar that appeared shrank the container, the display was refitted smaller, the scrollbar went away and the cycle started again. 75% and 125% were stable because the display stays clear of the edge or always overflows. The container now scrolls only when the display is zoomed in past the fit, which is when there is something to scroll to. Fixes #51 --- src/frontend/GuacamoleDisplay.tsx | 7 ++++- .../frontend/GuacamoleDisplay-resize.test.tsx | 27 ++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/frontend/GuacamoleDisplay.tsx b/src/frontend/GuacamoleDisplay.tsx index d535331..131b9a1 100644 --- a/src/frontend/GuacamoleDisplay.tsx +++ b/src/frontend/GuacamoleDisplay.tsx @@ -265,6 +265,11 @@ export const GuacamoleDisplay = forwardRef< displayRef.current.style.width = `${Math.floor(display.getWidth() * scale)}px`; displayRef.current.style.height = `${Math.floor(display.getHeight() * scale)}px`; } + // Only a zoomed in display needs scrolling. Fitted, a pixel of rounding + // shows a scrollbar, which shrinks the fit, which hides it: a loop. + if (containerRef.current) { + containerRef.current.style.overflow = zoom > 1 ? "auto" : "hidden"; + } onZoomChange?.(zoom); return zoom; }, @@ -1085,7 +1090,7 @@ export const GuacamoleDisplay = forwardRef< return (
{ diff --git a/tests/frontend/GuacamoleDisplay-resize.test.tsx b/tests/frontend/GuacamoleDisplay-resize.test.tsx index 5394407..99dd0ac 100644 --- a/tests/frontend/GuacamoleDisplay-resize.test.tsx +++ b/tests/frontend/GuacamoleDisplay-resize.test.tsx @@ -1,5 +1,6 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { act, cleanup, render } from "@testing-library/react"; +import { createRef } from "react"; // guacd's VNC client segfaults if it gets a display `size` while it is still // dialing the VNC server, so the resize observer must stay quiet until the @@ -87,7 +88,10 @@ vi.mock("@termix-ssh/plugin-sdk/ui", async (importOriginal) => ({ resolveConnectionOrigin: async () => "remote", })); -import { GuacamoleDisplay } from "../../src/frontend/GuacamoleDisplay"; +import { + GuacamoleDisplay, + type GuacamoleDisplayHandle, +} from "../../src/frontend/GuacamoleDisplay"; const RESIZE_DEBOUNCE_MS = 150; @@ -264,6 +268,27 @@ describe("RDP automatic resizing", () => { }); }); +describe("GuacamoleDisplay scrolling", () => { + it("scrolls only a zoomed in display, so a fitted one cannot loop", async () => { + const ref = createRef(); + const { container } = render( + , + ); + await vi.waitFor(() => expect(mocks.client).not.toBeNull()); + const box = container.firstElementChild as HTMLElement; + const overflow = () => getComputedStyle(box).overflow; + + act(() => void ref.current!.zoomIn()); + expect(overflow()).toBe("auto"); + act(() => void ref.current!.zoomOut()); + expect(overflow()).toBe("hidden"); + }); +}); + describe("GuacamoleDisplay paste modifiers", () => { function paste(element: HTMLElement) { const event = new Event("paste", { bubbles: true, cancelable: true });