From 0ee31d4736a9bc0ec89dec98bc67cf9a785a61df Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 29 Oct 2026 03:22:22 +0800 Subject: [PATCH] gui: Routing and Usage keep the reader's place when wheeled as they open, heard late or never (issennknight) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit issennknight on Discord (macOS 13.7.8, v0.1.1902), after f92db4cdd: "路由 用量 页面 刚点开并滚动页面时会抖动复位". Two causes, both in the window's own scroll guard, which every page takes: 1. A load landing under the wheel (show()'s back on the page's first reads, loadProvidersNow's put-back after render) called backToReader with the place last heard of. The page hears of a scroll a frame or more late (WebKit scrolls off the main thread; a loaded Mac), so each load took the reader's last steps back and stopped their coast. backAfterLoad now keeps a view that has gone on the way the reader's own scrolls go (readerWay, set from each of theirs) as theirs, and puts back only a move against it (a redraw's clamp). 2. On macOS 13's WebKit (16.6) the page never hears the wheel. Every gesture's first scrolls were put back until three the same way made a run (puttingBack): a shake at the start of each gesture, a page just opened included. The first run given back is now remembered (localStorage magpie.unheardWheels, for the next start too); from then on a scroll at rest waits 120ms before it is put back (waitsBack), and a second the same way within 80ms, the page's height unchanged between them, is the reader's at once (code's two scrolls in a row, 100ms apart in view-wheel-unheard, are both put back). A lone scroll (a redraw's, code's) is still put back, 120ms later; one under a click's hold at once, as before. What the wait puts back is recorded as an at-once put-back is, so a wheel heard later than the wait (a loaded machine) still gives it back (givesBack). Not changed: the browser's scroll anchoring. It lowers scrollTop as data comes in above with what's on the screen still; the test tells that from a put-back (view up and what was under the pointer going down with it). Nothing between v0.1.1902 and 425a61322 touched this guard (68 commits; none in backToReader, readerScrolls, readerLeaves, puttingBack or overflow-anchor), and no view has smooth scrolling. Size budgets: app.js 1,313,704, the core 1,532,830 (main's plus 1,969), both the guard's own, with no room added. Tests: - New view-open-wheel.test.cjs: Usage and Routing, opened and opened again, the first data held until the wheel is going; the page told of each scroll 80ms late (late) or never (unheard, a capture listener stopping the wheel, learned on the Agents page first); every frame's place and every write moving a view up are recorded. en, zh, zh-TW, ja, de; 420 and 1000 wide; Chromium and WebKit. 162/162 on this tree (mote). - Broken by hand: on the base's assets (425a61322) 117/162 red: late Routing 31, late Usage 4 (210 to 180 under the wheel), unheard all 80 ("nothing put the view back up": 30, 30, 30 put back each gesture). With backAfterLoad but no waitsBack, the unheard half was 80/80 red the same way; with waitsBack but readerAt unset taken as no move, red too (found by logging each write's stack), fixed to 0 as backToReader reads it. - click-scroll.test.cjs: new subtest, a wheel heard 250ms late with the unheard wheels learned still scrolls the view. Red in both engines (Windows, 2 of 2 runs) with the wait's put-back not recorded, 24/24 green with it (3 of 3). Found from the whole suite's first run: under WSL's load, click-scroll's late-heard wheel subtest went red in webkit, which learned the unheard wheels from a run put back. - Also tried and dropped: .view { overflow-anchor: none }. It only silenced a scrollTop-only check; anchoring moves nothing on screen. - TestCoreScriptBudget ok (mote); gofmt -l clean. - After the rebase onto 2f5548371: TestCoreScriptBudget and the app.js budget ok (mote); view-open-wheel, view-wheel-unheard, click-scroll on mote under another session's suite (load 16 to 35): 192/192 once, and 1 of 80 unheard subtests red once (#4132: under load the driver's second wheel comes after waitsBack's 120ms). - Rebased onto c3462d5fe (main's GUI changes: context.js, i18n.js, the Codex auto-reset title; none in the scroll guard). app.js budget ok (mote). TestCoreScriptBudget is red by 670 bytes at c3462d5fe itself (1,531,531 > 1,530,861, #4133, taken by another session); this commit adds its own 1,969 to both, so the core stays 670 over, not more. The four scroll files on WSL: chromium all green; Linux WebKit red in click-scroll, view-wheel-unheard and view-wheel-after-click as at 2f5548371, and 7 of 80 view-open-wheel unheard subtests (a first gesture's put-backs before the run is learned, the #4132 class). On mote at load 81 (another session's full GUI suite) 14 of 113 red, mostly 5s click timeouts; not counted as a run. - Whole GUI suite at this tree, WSL magpie-desktop (mote had another session's suite): 14,519 tests, 14,263 pass, 256 red. Every red file is named on #4120 / #4121 (Linux reds at main) or was run alone at 2f5548371 and is red there the same: routing-rule-models, recent-calls-more, searcher-pick, usage-ledger-chart, list-sort (#4131), click-scroll's late-heard wheel, inner-scroll-contain, view-wheel-after-click and view-wheel-unheard in WebKit on Linux (base 9 to 10 red, this tree 4 to 9). Recorded on #4120. - Tried and dropped: a check in waitsBack's timer for a view gone on further untold. It took a code scroll whose event was still pending under load as the reader's (view-wheel-unheard webkit red on mote). Not tried: a real macOS 13 WebKit 16.6 (none here). The unheard case is an emulation (wheels stopped before the page), the same one view-wheel-unheard and view-wheel-after-redraw use. The first gesture of a fresh install on macOS 13 still shakes once, until the run is seen. --- docs/subsystems/gui-shell.md | 2 + internal/gui/assets/app.js | 39 +++- internal/gui/core_budget_test.go | 4 +- internal/gui/tests/click-scroll.test.cjs | 23 ++- internal/gui/tests/view-open-wheel.test.cjs | 190 ++++++++++++++++++++ 5 files changed, 252 insertions(+), 6 deletions(-) create mode 100644 internal/gui/tests/view-open-wheel.test.cjs diff --git a/docs/subsystems/gui-shell.md b/docs/subsystems/gui-shell.md index 73152789c..804c0e924 100644 --- a/docs/subsystems/gui-shell.md +++ b/docs/subsystems/gui-shell.md @@ -413,6 +413,8 @@ covers it in both engines, every language and a narrow window. - Every user-visible string has zh, zh-TW, ja and de translations with the same placeholders. `gui-zh-tw.test.cjs`, `gui-ja.test.cjs` and `gui-de.test.cjs` fail on a missing one; `gui-zh-tw.test.cjs` also fails on a zh-TW string with a Simplified character left in it. - A click never moves the page. Code scrolls a view only with the reader's event in hand (`scrollOnPurpose`); `click-scroll.test.cjs` guards this. A click is taken where the reader left the view: a scroll not theirs made just before it, whose scroll event the browser sends only at the next frame, after the click, is put back first (`backToReader` in the click guard, #1554). What was clicked is held where it was (`hold`); a view at its top when clicked stays at its top, and what comes in above the control moves it down instead (#2134, `update-auto.test.cjs`), as long as it moves less than half its own height and so stays under the pointer. When what the click does leaves the page shorter under it (a list emptied), the view keeps room at its foot for it to stay (`.view-room`), room that goes as the reader scrolls back. A control under what it unrolls (`data-unrolls`, "Show 7 more") goes down with what it opens: what's held is the part it is in, so the rows open downwards. Anything larger above it, as the stage a day picked on Routing brings in above the bar, is scrolled past, and the control stays where it was clicked (`routing-days-fit.test.cjs`, `routing-failed-open.test.cjs`). - A scroll not the reader's is put back, so every way the reader scrolls has to count as theirs: the wheel and a trackpad's coast after the lift (WebKit on the Mac plays the coast itself and the page hears its scrolls with no wheel for each, so the wheel starts the same chain a touch fling does, `flings`/`flingUntil`: each scroll keeps the next one the reader's till it rests, and a click ends it; issenn on Discord, `view-trackpad-coast.test.cjs`), a wheel or coast the page is never told of (macOS 13's WebKit, Safari 16.6's, scrolled a view under wheels it never dispatched, so every scroll was put back and only the bar's drag moved the page: three scrolls put back the same way within a second are taken as the reader's run and given back, and so is each one after it that goes on the same way within a second of the last, so a wheel turned slowly or on a loaded Mac loses no step; a scroll by code is one, not a run, and two at rest are still put back; issenn on Discord, `view-wheel-unheard.test.cjs`. Under a click's 4s hold the same holds: only a put-back that comes with the page redrawn since the hold last held (`redrawn`: the view's height or where the first held parts sit moved from `h.lay`) is the hold's and never counts toward a run, so a profile opened on the Agents page and wheeled through at once scrolls, issennknight on Discord, `view-wheel-after-click.test.cjs`. The parts `h.lay` measures are those still in the page that scroll with it: a part drawn again since (the Usage page's tabs, the agents' list under an agent opened or closed) is a redraw once, not at every scroll, and a sticky one (Settings' tabs at a narrow width) is left out, as it sits still while the page scrolls; `view-wheel-after-redraw.test.cjs`), a touch and its fling, the keys, a drag, the scrollbar's own drag (`barDrag`, #1089) and the middle button's autoscroll (`panning`, 多喝热水 on Discord). Chromium and WebView2 give the autoscroll a press of button 1 and then no event of the reader's while it scrolls; from that press the view follows it till Chromium ends it, on the next press (which reaches the page only as a pointerup), a key (a keyup), or the lift after the mouse moved while held. A field the guard brings back into view after putting a scroll back is one focused since the reader last scrolled that view, not one they scrolled away from (`scrolledFrom`): the middle press focuses the button under it. See `view-middle-autoscroll.test.cjs`. +- A load that lands puts the view back where the reader left it (`show`'s `back` on the page's first reads, the Providers pages' reload after `render`): what it drew may have pulled the view up, the browser clamping it to a page shorter for a moment. While the reader scrolls, the place last heard is late (the page hears of a scroll a frame or more after it, WebKit scrolling on its own thread), and putting it back took their last steps and stopped their coast each time a load landed under the wheel, so Routing and Usage, scrolled as they opened, shook and snapped back (issennknight on Discord, macOS 13). `backAfterLoad` keeps a view that has gone on the way the reader's own scrolls go (`readerWay`, set from each scroll of theirs) as theirs, and puts back only a move against it, which is a redraw's clamp. The browser's scroll anchoring stays on: as data comes in above, it lowers `scrollTop` with what's on the screen still, which the reader never sees, so the test tells a put-back (the view up, what was under the pointer going down with it) from that. +- Where the window's WebKit scrolls under wheels it never tells the page of (macOS 13's, 16.6), each gesture's first scrolls were put back until three the same way made a run (`puttingBack`), a shake at the start of every gesture, the first on a page just opened included. The first run given back is remembered (`deaf`, kept in localStorage as `magpie.unheardWheels` for the next start); from then on a scroll at rest waits 120ms before it is put back (`waitsBack`), and one more the same way within 80ms (a frame or a few; code's two scrolls in a row come further apart and are both put back, `view-wheel-unheard.test.cjs`), with the page's height the same (no redraw between them), makes it the reader's at once. A lone scroll (a redraw's, code's) is still put back, 120ms later; one under a click's hold is put back at once as before. See `view-open-wheel.test.cjs`, which starts the wheel before the first data, tells the page of each scroll 80ms late or never, and counts every write that moves the view up under the wheel. What the wait puts back is recorded as an at-once put-back is, so a wheel heard later than 120ms still gives it back (`givesBack`). - Typing never moves the page either. A textarea that grows with its text (the Library's `autosize` in plugins/library/client.js: a set's text, an agent's own text, a skill's description, a subagent's fields) is measured at height auto with what holds it kept at its height, so the page never goes short for a moment: a page gone short has its view's scroll clamped by the browser at every input, an input method's every composing step included, and the guard's putting it back pulled a textarea taller than the view to one of its edges (#2636, `library-ime-scroll.test.cjs`). - A box that scrolls inside a page keeps the wheel at its ends: wheeled past its top or foot, the page stays where it was (碳碳双键 on Discord, Requests' list on Usage). `holds` in app.js marks every box between the pointer and its `.view` that scrolls vertically and overflows (`.holds`), on `pointerover` and on each wheel, and app.css gives `.holds` `overscroll-behavior-y: contain` (the Mac's bounce stays, on the box). It is not one CSS rule for every box because Chromium (WebView2, magpie web) holds the wheel in a box told to contain even when it doesn't overflow, and in one that scrolls only sideways, so a short list or a wide table would stop the page. `.holds` is under `:where()`, so a rule that passes the wheel on still does (`.mchips` in a short window, #833). The page itself (`.view`) and the document chain as before. An engine with no `overscroll-behavior` (Safari 15, macOS 12's WebKit until Safari is updated; Safari 16+, WebKitGTK and Chromium have it) gets the same from `compat.js`: a wheel over a `.holds` box at its end in the wheel's direction is cancelled, so there the Mac's bounce at the box's end is lost. A guard in `inner-scroll-contain.test.cjs` builds every rule in every stylesheet under assets that scrolls a box vertically from its own selector, fills it and points at it, and fails naming the file and selector of one that doesn't hold the wheel (a rule that sets `overscroll-behavior` back to auto, or a box `holds` doesn't reach). See `inner-scroll-contain.test.cjs`. - There are no native `