From 36ab82d04b688b0fab0686f95ca1fabecbb96bfe Mon Sep 17 00:00:00 2001 From: David McKay Date: Mon, 23 Nov 2026 20:07:10 -0800 Subject: [PATCH] Sidebar: let go, the edge is where it was released, not easing the last pixels When the release reached the page before the last move had been drawn (a busy window, or a browser handing over a held-back move just ahead of the release), the last width was drawn together with the sidebar's 200ms ease coming back, so the sidebar eased the last few pixels after the pointer. That is the "width 288 -> 291" the WebKit job hit now and then in sidebar-zoom-drag. On release the rail now draws the released width at once (flushSync), lays the panel out at it while easing is still off, and only then turns easing back on, so there is nothing left to ease. A new case dispatches the last move and the release together, which failed every run before (308 drawn for 288) and passes now, in both engines. --- app/src/components/ui/sidebar.tsx | 13 ++++++ app/tests/sidebar-zoom-drag.test.tsx | 62 ++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/app/src/components/ui/sidebar.tsx b/app/src/components/ui/sidebar.tsx index f320380a89..9081224310 100644 --- a/app/src/components/ui/sidebar.tsx +++ b/app/src/components/ui/sidebar.tsx @@ -5,6 +5,7 @@ import { useRender } from "@base-ui/react/use-render"; import { IconLayoutSidebar } from "@tabler/icons-react"; import { cva, type VariantProps } from "class-variance-authority"; import * as React from "react"; +import * as ReactDOM from "react-dom"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Separator } from "@/components/ui/separator"; @@ -356,6 +357,7 @@ function SidebarRail({ className, ...props }: React.ComponentProps<"button">) { const { toggleSidebar, state, isMobile } = useSidebar(); const resize = React.useContext(SidebarResizeContext); const drag = React.useRef<{ + panel: HTMLElement; startX: number; startWidth: number; min: number; @@ -383,6 +385,7 @@ function SidebarRail({ className, ...props }: React.ComponentProps<"button">) { const startWidth = panel.getBoundingClientRect().width; const min = narrowest(panel); drag.current = { + panel, startX: event.clientX, startWidth, min, @@ -411,6 +414,16 @@ function SidebarRail({ className, ...props }: React.ComponentProps<"button">) { drag.current = null; if (!current?.moved || !resize) return; dragged.current = true; + /* + * Drawn at the released width before the sidebar eases again. The last move's width may not + * be drawn yet (a busy window, or a browser handing over a held-back move just ahead of the + * release), and drawn together with the easing coming back, the sidebar eased the last few + * pixels after the pointer instead of being where it was let go. Reading the panel's box makes + * the browser lay it out at that width now, while it does not ease, so turning the easing back + * on leaves nothing to ease. + */ + ReactDOM.flushSync(() => resize.setWidth(current.width)); + current.panel.getBoundingClientRect(); resize.setResizing(false); resize.commitWidth(current.width); }} diff --git a/app/tests/sidebar-zoom-drag.test.tsx b/app/tests/sidebar-zoom-drag.test.tsx index 83e12117e5..b134d8292f 100644 --- a/app/tests/sidebar-zoom-drag.test.tsx +++ b/app/tests/sidebar-zoom-drag.test.tsx @@ -343,6 +343,43 @@ async function drag(page: Page, by: number) { await page.mouse.up(); } +/** + * A drag whose last move and release reach the page together, before it has drawn that move: what + * a busy window does, and what a browser does when it holds a move back for the next frame and then + * hands it over just ahead of the release. Pressed and moved by hand most of the way; the last move + * and the release dispatched in one go; then the hand let go. + */ +async function dragReleasedWithLastMove(page: Page, by: number) { + const rail = page.locator('[data-slot="sidebar-rail"]'); + const box = await rail.boundingBox(); + if (!box) throw new Error("the sidebar's edge has no box"); + const x = box.x + box.width / 4; + const y = box.y + box.height / 2; + await page.mouse.move(x, y); + await page.mouse.down(); + await page.mouse.move(x + by / 2, y, { steps: 6 }); + await rail.evaluate( + (element, at) => { + for (const type of ["pointermove", "pointerup"]) + element.dispatchEvent( + new PointerEvent(type, { + bubbles: true, + cancelable: true, + composed: true, + pointerId: 1, + pointerType: "mouse", + isPrimary: true, + button: type === "pointerup" ? 0 : -1, + clientX: at.x, + clientY: at.y, + }), + ); + }, + { x: x + by, y }, + ); + await page.mouse.up(); +} + async function shot(page: Page, name: string) { if (!shots) return; mkdirSync(shots, { recursive: true }); @@ -431,6 +468,31 @@ describe.skipIf(!asked)("the sidebar's edge at any zoom", () => { } }, 120_000); + /* + * Let go, the sidebar is at the width it was let go at, there and then: it follows the pointer + * to the end rather than easing the last of the way after it. It used to ease when the release + * came before the last move was drawn, so now and then it was still a few pixels short. + */ + test(`${shape.name}: let go just after the last move, the sidebar is drawn at the released width at once`, async () => { + for (const [engine, browser] of engines) { + const page = await open(browser, shape, ZOOMED); + try { + for (const by of [-40, 30]) { + const before = (await measured(page)).width; + await dragReleasedWithLastMove(page, by); + expect({ engine, ...(await measured(page)) }).toEqual({ + engine, + width: before + by, + window: ZOOMED.width, + stored: String(before + by), + }); + } + } finally { + await page.close(); + } + } + }, 120_000); + /* * "It stops way too wide": at 100% on a large screen, a drag goes past the old floor down to the * new one, and the next page drawn starts at that width.