gui: a page wheeled right after a click scrolls on macOS 13's WebKit too (issennknight on Discord)

issennknight (macOS, trackpad): every page scrolled again, but a saved
profile opened on the Agents page and then scrolled through often stayed
where it was. macOS 13's WebKit scrolls a view under wheels it never
dispatches, so the view guard puts each such scroll back and takes three
put back the same way within a second as the reader's run (30d3001a0).
That rule skipped every put-back while a click held what it clicked, and
a click holds for 4s: a profile opened and wheeled through at once was put
back on every scroll and the page stood still ("sometimes" = within 4s of
a click). A wheel the page hears was fine.

Now a held view's put-back is the hold's only when the page was redrawn
since the hold last held it (the view's height, or where the first held
parts sit, moved from what hold() left in h.lay). A scroll with the page
laid out as the hold left it counts as at rest, so the reader's run is
given back a click before it too. One scroll by code after a click is
still put back: view-wheel-unheard's last case now checks that (its old
per-frame code scroll is a run, given back by design).

Other inner scrollers checked: the panel's Profiles popover (overflow
auto, overscroll-behavior contain) is outside any .view and the guard;
the provider editor's .mchips keeps contain except under 640px tall, an
earlier deliberate call, left alone.

Tests:
- New view-wheel-after-click.test.cjs: wheels (unheard and heard) over
  the long profile's details right after the click, to the foot, past it
  and back up; the short one's too; nothing but the view scrolls. en, zh,
  zh-TW, ja, de at 420 and 1000 wide, Chromium and WebKit. Red on
  origin/main's assets (MAGPIE_AFTER_CLICK_ASSETS) in 20 of 24 subtests,
  "ten wheels of 30px right after the click scroll the page: from 153 to
  153"; the heard cases pass there. Green with the change.
- Before the rebase, 59 GUI files the change can reach (every scroll/wheel/view-/click/
  hold/held/keep/profile/unroll/jump/stay/still file, old-webkit,
  text-size, sidebar*, last-page, routing-days-fit, routing-failed-open,
  update-auto, i18n-keys, gui-de/ja/zh-tw), both engines, at
  --test-concurrency=4 on a box at load 130-160: 810 of 816 pass. Reds,
  each red alone on origin/main 865df2472 too: menu-input-scroll (#3402),
  old-webkit Safari 15.0 (#3403), quota-holds WebKit (#3777, new);
  routing-scroll-end 440x620 "stage's columns 3 !== 2" under load, 22/22
  alone on both (#3778, new). The whole GUI suite was not run: other
  sessions' GUI suites held the machine.
- go test -tags nogui ./internal/gui ok before the rebase.

At the pushed head (rebased on ca9b5048e, which touched app.js): the budget
tests ok (app.js 1,314,407 bytes of 1,321,319, not raised), and
view-wheel-after-click, view-wheel-unheard and click-scroll pass 54/54 in
both engines. The 59-file run above was at the base de54b4ff9.

Broken by hand: putting back the old gate (any put-back under a hold
skipped) turns the new test red as above. Removing the new redraw gate
(h = false) is not caught by a test: in both engines a redraw under a
click is held by heldSizes before the guard hears a scroll (logged: no
put-back during a 30-frame shrink at the foot), and the synthetic
redraw fixtures I tried passed with the hold removed too, so none is
shipped.

Not tried: real macOS 13 / WebKit 16.6 and a real trackpad; the unheard
wheel is a capture listener stopping the wheel event.
This commit is contained in:
yetone
2026-10-27 00:54:18 +08:00
parent ca9b5048e3
commit a6d7e02c77
4 changed files with 173 additions and 10 deletions
+1 -1
View File
@@ -375,7 +375,7 @@ covers it in both engines, every language and a narrow window.
- Settings' Search APIs add row has a base URL field under the key for every API (#1580): the vendor's own address is its placeholder, picking an API already added fills in its saved URL so a new key alone keeps it, and Add with no key changes only the URL. See [a search API's base URL](gateway-routing.md#a-search-apis-base-url), [`renderSearch`](../../internal/gui/assets/app.js) and `search-api.test.cjs`.
- 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, with no click holding, 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`), 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 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`), 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`.
- 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`).
- There are no native `<select>` elements and no colored left-border stripes. State is shown with a dot or a swatch.
- What the window shows can be selected and copied, its controls can't, as in a Mac app (Outvi V on Discord: nothing could be copied into a bug report). The page is `user-select: none`, and two `:where()` rules after `body` in `app.css` make text content selectable (paragraphs, `pre` and `code`, a detail's values, hints and notes, every error class, a conversation, a request's story on Routing) and keep every control unselectable with what is in it (buttons, labels, tabs, menus, the navigation, grips). Both have no specificity, so a view's own rule still decides, as a list being sorted does; a field stays selectable. See `user-select.test.cjs`.
+17 -6
View File
@@ -23014,11 +23014,12 @@ function keyboardFocus(e) {
// macOS 13's WebKit (16.6) may scroll a view under a wheel or a coast it never
// tells the page of: every scroll was put back, the page shook and only the
// bar's drag moved it (issenn). Three put back the same way in a second, no
// click holding, are the reader's: given back, and so is each one after
// that goes on the same way within a second. Code scrolls once; not a run.
// redraw under a click's hold (h) moving them, are the reader's: given back,
// and so is each one after that goes on the same way within a second. Code
// scrolls once; not a run.
let putBack = [], run = null; // { v, by: px put back, at, h: held }, the last second's
function puttingBack(v, from) {
const by = from - v.scrollTop, at = performance.now(), d = Math.sign(by), h = held?.v === v;
function puttingBack(v, from, h) {
const by = from - v.scrollTop, at = performance.now(), d = Math.sign(by);
putBack = putBack.filter((p) => at - p.at < 1000);
if (Math.abs(by) < 1) return;
putBack.push({ v, by, at, h });
@@ -23233,13 +23234,17 @@ function standIn(h) {
if (s && s !== c[0] && s.tagName === c[0].tagName && s.classList[0] === c[0].classList[0] && atRest(s)) { c[0] = s; return c; }
}
}
// where the held parts are in the page, and how tall it is: what the hold
// left (h.lay), and a redraw changes, a scroll not
const laid = (h) => [h.v.scrollHeight, ...h.chain.slice(0, 3).map(([n]) => n.isConnected ? onScreen(n, h.v) + h.v.scrollTop : NaN)];
const redrawn = (h) => !h.lay || laid(h).some((x, i) => !(Math.abs(x - h.lay[i]) < 1.5));
function hold(h) {
// held by what can be seen: an empty part (a row's value with nothing in it
// yet) has no height, so "moved by less than half its height" below never
// held, and Add to PATH on Settings' About slid the view 11px off its top
// once the page was a little taller than the window (#2296)
const a = h.chain.find(([n]) => atRest(n) && n.offsetHeight) || h.chain.find(([n]) => atRest(n)) || (h.chain.some(([n]) => n.isConnected) ? null : standIn(h));
if (!a) return;
if (!a) { h.lay = laid(h); return; }
const v = h.v, d = onScreen(a[0], v) - a[1];
if (Math.abs(d) >= 1) {
let want = v.scrollTop + d;
@@ -23270,6 +23275,7 @@ function hold(h) {
}
fitRoom(v);
readerLeaves(v);
h.lay = laid(h);
}
let holding = false; // one frame loop, whatever the clicks
// A window made wider or narrower lays the whole page out again, the sidebar
@@ -23351,9 +23357,14 @@ for (const v of document.querySelectorAll(".view")) {
if (panning?.v === v) readerScrolls(250);
if (performance.now() < purposeUntil || barDrag === v) { fitRoom(v); readerLeaves(v); scrolledFrom.set(v, document.activeElement); return; }
const from = v.scrollTop;
// a click's hold takes what a redraw moved; a scroll with the page laid
// out as the hold left it is put back as at rest, so the reader's run
// is theirs a click before it too (issennknight: a profile opened, then
// wheeled through, held still for 4s)
const h = held?.v === v && redrawn(held);
if (held?.v === v) hold(held);
else backToReader(v);
puttingBack(v, from);
puttingBack(v, from, h);
}, { passive: true });
}
@@ -0,0 +1,151 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// issennknight on Discord (macOS, trackpad): every page scrolled again, but a
// saved profile opened on the Agents page and then scrolled through often
// stayed where it was. macOS 13's WebKit scrolls a view under a wheel it never
// tells the page of, and the view guard takes a run of such scrolls as the
// reader's only with no click holding: a click holds what it clicked for up
// to 4s, and every scroll in that time was put back. Here the wheel goes
// over the profile just opened, right after the click, heard and unheard:
// the page must follow it down, to its foot and back up, with details longer
// than the window and shorter, and nothing but the view scrolls.
// Chromium and WebKit, a narrow and a wide window, every language.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const assets = process.env.MAGPIE_AFTER_CLICK_ASSETS || path.resolve(__dirname, "../assets");
const LANGS = ["en", "zh", "zh-TW", "ja", "de"];
const AGENTS = Array.from({ length: 10 }, (_, i) => ({
id: "a" + i, name: "Agent " + i, path: "/t/a" + i + ".json", icon: "generic", wired: true,
fields: [{ key: "model", label: "model", value: "m", options: [{ value: "m", label: "M", ref: "a/m" }] }],
}));
const group = (i) => ({ id: "g" + i, name: "Agent " + i, fields: [{ key: "model", label: "model", value: "magpie/x/m" + i }, { key: "effort", label: "effort", value: "high" }] });
// "long" holds more than a window shows, "short" a few lines
const PROFILES = [
...Array.from({ length: 4 }, (_, i) => ({ name: "p" + i, summary: "", agents: [] })),
{ name: "long", summary: "", agents: Array.from({ length: 16 }, (_, i) => group(i)) },
{ name: "short", summary: "", agents: [group(0)] },
];
function server(lang) {
return async (route) => {
const url = new URL(route.request().url());
const json = (data) => route.fulfill({ json: data });
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (url.pathname === "/api/state") return json({ agents: AGENTS, profiles: PROFILES, settings: { lang, theme: "light", guideHidden: true } });
if (url.pathname === "/api/providers") return json({ providers: [], gateway: { running: true, window: true } });
if (url.pathname === "/api/window/fit") return route.fulfill({ status: 204 });
if (url.pathname.startsWith("/api/")) return json({});
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
await route.fulfill({ body: await fs.readFile(file), contentType });
};
}
// the view at rest: its scrollTop the same across a few looks
async function rested(p, view, ms = 3000) {
let last = NaN, same = 0;
const until = Date.now() + ms;
while (Date.now() < until) {
const t = await view.evaluate((v) => v.scrollTop);
same = t === last ? same + 1 : 0;
if (same >= 3) return t;
last = t;
await p.waitForTimeout(50);
}
return last;
}
const wheels = async (p, n, dy) => { for (let i = 0; i < n; i++) { await p.mouse.wheel(0, dy); await p.waitForTimeout(16); } };
// what scrolled besides the view: the document, and any part of the page
const others = (p) => p.evaluate(() => [document.scrollingElement, ...document.querySelectorAll("#view-agents *")]
.filter((n) => n.scrollTop > 0).map((n) => n.id || n.className));
// the chip's name: ↻ and × are at its other end
const clickChip = async (p, name) => {
const b = await p.locator("#profiles .chip", { hasText: new RegExp("^" + name) }).boundingBox();
await p.mouse.click(b.x + 12, b.y + b.height / 2);
};
const DEAF = `addEventListener("wheel", (e) => e.stopImmediatePropagation(), { capture: true, passive: true });`;
const RUNS = [];
for (const lang of LANGS) for (const width of [420, 1000]) RUNS.push({ lang, width, deaf: true });
RUNS.push({ lang: "en", width: 420, deaf: false }, { lang: "zh", width: 1000, deaf: false });
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": a wheel right after a click scrolls the view", { timeout: 600000 }, async (t) => {
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
const browser = await (engine === "webkit" ? webkit : chromium).launch();
t.after(() => browser.close());
for (const { lang, width, deaf } of RUNS) {
await t.test(`${lang}, ${width}px, ${deaf ? "a wheel the page never hears" : "a wheel heard"}`, async () => {
const ctx = await browser.newContext({ viewport: { width, height: 600 }, reducedMotion: "reduce" });
const p = await ctx.newPage();
p.setDefaultTimeout(8000);
const errors = [];
p.on("pageerror", (e) => { if (!/^ResizeObserver loop/.test(e.message)) errors.push(e.message); });
if (deaf) await p.addInitScript(DEAF);
await p.route("**/*", server(lang));
const view = p.locator("#view-agents");
await p.goto("http://magpie.test/?view=agents");
await p.locator("#view-agents .ag-lead").first().waitFor();
await p.locator("#profiles .chip").first().waitFor();
await rested(p, view);
const r = await view.boundingBox();
const max = () => view.evaluate((v) => v.scrollHeight - v.clientHeight);
// down to the profiles at the page's foot, as the reader would
await p.mouse.move(r.x + r.width / 2, r.y + r.height / 2);
await wheels(p, 40, 40);
const foot = await rested(p, view);
assert(foot >= (await max()) - 1 && foot > 100, `the wheel takes the page to its foot: ${foot} of ${await max()}`);
// the long profile opened, and wheeled through at once: the page
// follows, the pointer over the chip and then the details
await clickChip(p, "long");
await p.locator(".prof-detail").waitFor();
const tall = await max();
assert(tall > foot + 300, `the long profile's details run past the window: ${foot} → ${tall}`);
await wheels(p, 10, 30);
const down = await rested(p, view);
assert(down >= foot + 250, `ten wheels of 30px right after the click scroll the page: from ${foot} to ${down}`);
// and on to its foot, where the wheel has nothing further to take
await wheels(p, 40, 40);
const end = await rested(p, view);
assert(end >= tall - 1, `the wheel reaches the details' end: ${end} of ${tall}`);
await wheels(p, 5, 40);
assert.equal(await rested(p, view), end, "past its end the page stays at its foot");
await wheels(p, 10, -30);
const up = await rested(p, view);
assert(up <= end - 250, `and back up: from ${end} to ${up}`);
assert.deepEqual(await others(p), [], "nothing but the view scrolls");
// the short one, opened at the foot once the long one is closed: the
// details fit in the window, and the page still goes up and down
// under the wheel
await p.keyboard.press("Escape");
await p.locator(".prof-detail").waitFor({ state: "detached" });
await p.waitForTimeout(1100);
await wheels(p, 20, 40);
await rested(p, view);
const b = await p.locator("#profiles .chip", { hasText: /^short/ }).boundingBox();
assert(b && b.y > r.y && b.y + b.height < r.y + r.height, "the short profile's chip is in sight");
await clickChip(p, "short");
await p.locator(".prof-detail").waitFor();
const at = await rested(p, view);
const fits = await p.locator(".prof-detail").evaluate((d) => d.offsetHeight);
assert(fits < r.height / 2, `the short profile's details fit in the window: ${fits}`);
await wheels(p, 10, -30);
const higher = await rested(p, view);
assert(at > 100 && higher <= Math.max(0, at - 250), `ten wheels up right after the click scroll the page: from ${at} to ${higher}`);
await wheels(p, 10, 30);
assert(await rested(p, view) >= Math.min(higher + 250, (await max()) - 1), "and down again");
assert.deepEqual(await others(p), [], "nothing but the view scrolls");
assert.deepEqual(errors, []);
await ctx.close();
});
}
});
}
@@ -102,8 +102,9 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await p.waitForTimeout(300);
assert.equal(await rested(p, view), up, "a scroll by code at rest is put back");
// a click holds what it clicked: scrolls by code each frame after it
// are no reader's, and are put back
// a click holds what it clicked: a scroll by code after it is no
// reader's, and is put back. (A run of scrolls with nothing redrawn
// is the reader's, a click before it or not: view-wheel-after-click.)
const [x, y] = await p.evaluate(([x, y]) => {
const row = window.__clicked = document.elementFromPoint(x, y)?.closest(".row.agent");
const b = row?.getBoundingClientRect();
@@ -113,7 +114,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
const rowTop = () => p.evaluate(() => window.__clicked.getBoundingClientRect().top);
await p.mouse.click(x, y);
const at = await rowTop();
await view.evaluate((v) => new Promise((done) => { let n = 0; const step = () => { if (n++ > 30) return done(); v.scrollTop += 4; requestAnimationFrame(step); }; requestAnimationFrame(step); }));
await view.evaluate((v) => { v.scrollTop += 120; });
await rested(p, view);
const after = await rowTop();
assert(Math.abs(after - at) <= 12, `the row clicked stays: at ${at} after the click, ${after} once at rest`);