usage: a swipe across the Requests table is never written back by its scrollbar's echo (Pluviophile)
Pluviophile on Discord (a phone, magpie's web page and the installed PWA): swiping the Usage › Requests table left or right trembles and sticks (左右滑动震颤, 粘滞卡顿). The cause: the table (#ledWrap) and the scrollbar kept at the window's foot (#ledHScroll, #799) followed each other both ways, each scroll handler copying its scrollLeft to the other when they differed. The scroll a copy sets off is told a frame later in WebKit, and on a phone the finger (the UI side's own scrolling) has moved the table on by then, so the bar's echo saw bar != table and wrote the table back to where it was a frame ago, every other frame of a swipe. Now each copy records the value it set (ledFollow), and that box's next scroll at that value is its echo and is passed on to nobody (ledFollowed). A scroll of the reader's on either box still moves the other, in both directions; ledHScroll's own copy at a redraw goes through ledFollow too. Measured with Playwright at an iPhone 13 profile (390x664, touch, dpr 3), the table moved 2.5px every 7ms off the frame, as a phone's own scrolling moves it, 60 frames: - WebKit before: 44 writes of the table by the page, the table stood still in 29 of 59 frames (5,5,15,15,22,22,...). - WebKit after: 0 writes, 0 frames standing still. - Chromium before and after: 0 writes, 0 still; a real touch gesture (CDP Input.synthesizeScrollGesture, touch) also showed none. The report is WebKit's (iOS), which Chromium doesn't reproduce. New test, internal/gui/tests/ledger-swipe.test.cjs: the table swiped off the frame is never written back nor stands still, and the bar follows; the bar dragged off the frame is never written back, and the table follows. en and zh, Chromium and WebKit, iPhone 13 profile. Broken by hand: page.js at its base (d8501848a) turns the new test red in WebKit, en and zh (the table written back, values in pairs); green in Chromium, which never had it. Run at the pushed head, on mote, through mote-run: - at f5c709ddc (this commit rebased on origin/main3f1f1882a): node --check page.js; ledger-swipe, ledger-hscroll, ledger-hscroll-foot, usage-ledger-fit, usage-ledger-detail, phone-web, usage-phone-head: 55 of 55 pass, Chromium and WebKit. - before the rebase (based8501848a): the 33 ledger-*, usage-ledger-*, phone-*, mobile-web, usage-phone-head, plugin-page* and i18n-keys files, 527 of 547 pass. The 20 reds (mobile-web "magpie web on phones", phone-connect-menu 420 "the address clicked from the page's top", usage-ledger "newest live route needs no return-to-live button") fail the same 20 with page.js atd8501848aand are filed: #3952, #5013, #4706, #4707, #3104, #4078, #5048. Not tried: a real phone (iOS Safari, an iOS PWA, Android Chrome); the model is WebKit on macOS with the table moved between frames. Desktop is covered by ledger-hscroll (600px, bar moves the table and the table the bar, both engines), which passes unchanged.
This commit is contained in:
@@ -1962,6 +1962,24 @@ function ledHeatShow(cell) {
|
||||
tip.style.left = left + "px";
|
||||
tip.style.top = top + "px";
|
||||
}
|
||||
// Each follows the other, and the scroll a follow sets off is its own echo,
|
||||
// never a move to pass back: WebKit tells it a frame later, and on a phone
|
||||
// the finger has moved the table on by then, so the bar's echo wrote the
|
||||
// table back a frame, every other frame of a swipe (Pluviophile on
|
||||
// Discord: 左右滑动震颤, 粘滞卡顿)
|
||||
const ledEcho = new WeakMap();
|
||||
function ledFollow(to, from) {
|
||||
const was = to.scrollLeft;
|
||||
if (was === from.scrollLeft) return;
|
||||
to.scrollLeft = from.scrollLeft;
|
||||
// one held where it was (no room yet) tells no scroll
|
||||
if (to.scrollLeft !== was) ledEcho.set(to, to.scrollLeft);
|
||||
}
|
||||
function ledFollowed(e, other) {
|
||||
const box = e.currentTarget, echo = ledEcho.get(box);
|
||||
ledEcho.delete(box);
|
||||
if (box.scrollLeft !== echo) ledFollow(other(), box);
|
||||
}
|
||||
// the table's scrollbar, kept in view at the window's foot (#799): as wide
|
||||
// as the table can go sideways, and moving it as the table moves it
|
||||
function ledHScroll() {
|
||||
@@ -1970,7 +1988,7 @@ function ledHScroll() {
|
||||
bar.hidden = !over;
|
||||
if (!over) return;
|
||||
bar.firstElementChild.style.width = wrap.scrollWidth - wrap.clientWidth + bar.clientWidth + "px";
|
||||
bar.scrollLeft = wrap.scrollLeft;
|
||||
ledFollow(bar, wrap);
|
||||
// a sticky box keeps clear of its scroller's padding, so at bottom 0 it
|
||||
// stood the view's bottom padding above the window's foot, the table
|
||||
// showing through the strip under it: it goes down over that padding
|
||||
@@ -1978,8 +1996,8 @@ function ledHScroll() {
|
||||
const pad = view ? parseFloat(getComputedStyle(view).paddingBottom) || 0 : 0;
|
||||
bar.style.bottom = -pad + "px";
|
||||
}
|
||||
$("#ledWrap").addEventListener("scroll", () => { const bar = $("#ledHScroll"); if (bar.scrollLeft !== $("#ledWrap").scrollLeft) bar.scrollLeft = $("#ledWrap").scrollLeft; }, { passive: true });
|
||||
$("#ledHScroll").addEventListener("scroll", () => { const wrap = $("#ledWrap"); if (wrap.scrollLeft !== $("#ledHScroll").scrollLeft) wrap.scrollLeft = $("#ledHScroll").scrollLeft; }, { passive: true });
|
||||
$("#ledWrap").addEventListener("scroll", (e) => ledFollowed(e, () => $("#ledHScroll")), { passive: true });
|
||||
$("#ledHScroll").addEventListener("scroll", (e) => ledFollowed(e, () => $("#ledWrap")), { passive: true });
|
||||
// a window that changes size redraws the chart at its new width
|
||||
// a new width fits the table again, on the next frame, and so do the
|
||||
// details' width (--ledw) and the scrollbar: each changes the table's or the
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// A swipe across the Requests table on a phone (Pluviophile on Discord: 左右
|
||||
// 滑动震颤, 粘滞卡顿). The table and the scrollbar kept at the window's foot
|
||||
// (#799) follow each other, and the scroll a follow sets off is told a frame
|
||||
// later in WebKit; a phone's finger has moved the table on by then, so the
|
||||
// bar's echo wrote the table back where it was, every other frame. Here the
|
||||
// table is moved between frames, as a phone's own scrolling moves it, and
|
||||
// the page never writes it back; the same for the bar dragged. English and
|
||||
// Chinese, Chromium and WebKit at a phone's size; no backend, the API is faked.
|
||||
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, devices } = require("playwright");
|
||||
|
||||
const assets = path.resolve(process.env.MAGPIE_LEDGER_ASSETS || path.join(__dirname, "../assets"));
|
||||
const now = Date.now();
|
||||
const ROWS = Array.from({ length: 40 }, (_, i) => ({
|
||||
route_id: 500 + i, t: new Date(now - (i + 1) * 60e3).toISOString(), agent: "trae", agentName: "Trae CN", icon: "generic",
|
||||
provider: "deepseek", providerName: "DeepSeek Harness", req: "group/auto-deepseek-v4-1-flash", model: "deepseek-v4-1-flash", served: "deepseek-v4-1-flash",
|
||||
in: 1200 + i, out: 80, ms: 2400, ttft_ms: 600, status: [200, 400, 499][i % 3], rid: "req_" + i, ep: "/v1/chat/completions", cost: 0.001, priced: true,
|
||||
}));
|
||||
|
||||
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: [], profiles: [], settings: { lang, theme: "light" }, fx: { rate: 7.2, at: new Date().toISOString() } });
|
||||
if (url.pathname === "/api/usage/requests") return json({ period: url.searchParams.get("period"), rows: ROWS, offset: 0, total: ROWS.length, calls: ROWS.length, errors: 0, input: 1, output: 1, cost: 0.04, unpriced: 0, agents: [{ id: "trae", name: "Trae CN", icon: "generic" }] });
|
||||
if (url.pathname === "/api/usage/quotas") return json([]);
|
||||
if (url.pathname === "/api/usage") return json({ calls: 40, errors: 0, input: 1, output: 1, reasoning: 0, unpriced: 0, cost: 0.04, bucket: "day", series: [], agents: [], models: [], path: "" });
|
||||
if (url.pathname === "/api/sessions") return json({ sessions: [], dirs: [] });
|
||||
if (url.pathname === "/api/sessions/stats") return json({ from: "", to: "", days: [], agents: {} });
|
||||
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
|
||||
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 });
|
||||
};
|
||||
}
|
||||
|
||||
// every write the page makes to either box's scrollLeft is counted; the
|
||||
// test's own moves go past the count, as a phone's scrolling does
|
||||
function count() {
|
||||
const d = Object.getOwnPropertyDescriptor(Element.prototype, "scrollLeft");
|
||||
window.__writes = { ledWrap: 0, ledHScroll: 0 };
|
||||
Object.defineProperty(Element.prototype, "scrollLeft", {
|
||||
configurable: true,
|
||||
get() { return d.get.call(this); },
|
||||
set(v) { if (this.id in window.__writes) window.__writes[this.id]++; d.set.call(this, v); },
|
||||
});
|
||||
// moves one box 2.5px every 7ms, off the frame, for 60 frames, and says
|
||||
// where it stood each frame and how often the page wrote either box
|
||||
window.__swipe = (id) => new Promise((done) => {
|
||||
const box = document.getElementById(id), seen = [];
|
||||
let x = 0;
|
||||
d.set.call(box, 0);
|
||||
const at = () => d.get.call(box);
|
||||
requestAnimationFrame(() => {
|
||||
window.__writes.ledWrap = window.__writes.ledHScroll = 0;
|
||||
const move = setInterval(() => { x += 2.5; d.set.call(box, x); }, 7);
|
||||
const frame = () => {
|
||||
seen.push(at());
|
||||
if (seen.length < 60) return requestAnimationFrame(frame);
|
||||
clearInterval(move);
|
||||
done({ seen, writes: { ...window.__writes } });
|
||||
};
|
||||
requestAnimationFrame(frame);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
test(engine + ": a swipe across the Requests table on a phone", async (t) => {
|
||||
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const phone = { ...devices["iPhone 13"] };
|
||||
delete phone.defaultBrowserType;
|
||||
for (const lang of ["en", "zh"]) {
|
||||
await t.test(lang, async () => {
|
||||
const ctx = await browser.newContext({ ...phone, reducedMotion: "reduce" });
|
||||
t.after(() => ctx.close());
|
||||
const p = await ctx.newPage();
|
||||
p.setDefaultTimeout(5000);
|
||||
p.setDefaultNavigationTimeout(60000);
|
||||
const errors = [];
|
||||
p.on("pageerror", (e) => errors.push(e.message));
|
||||
await p.addInitScript(count);
|
||||
await p.route("**/*", server(lang));
|
||||
await p.goto("http://magpie.test/?view=usage");
|
||||
await p.waitForSelector("#view-usage", { state: "visible" });
|
||||
await p.locator(":is(#usageTab .opt, .nav-s):visible").nth(1).click();
|
||||
await p.locator("#ledWrap .led tbody tr").first().waitFor();
|
||||
await p.waitForTimeout(300);
|
||||
assert(await p.locator("#ledWrap").evaluate((e) => e.scrollWidth > e.clientWidth + 100), "the table is wider than the phone");
|
||||
assert.equal(await p.locator("#ledHScroll").isHidden(), false, "the scrollbar is kept at the foot");
|
||||
|
||||
// the table swiped: it is never written back, and never stands still
|
||||
// a frame while the finger moves it; the bar follows it
|
||||
const table = await p.evaluate(() => window.__swipe("ledWrap"));
|
||||
const stood = table.seen.filter((x, i) => i && x <= table.seen[i - 1]).length;
|
||||
assert.equal(table.writes.ledWrap, 0, "the page wrote the swiped table back: " + JSON.stringify(table));
|
||||
assert.equal(stood, 0, "the table stood still or went back under the finger: " + JSON.stringify(table.seen));
|
||||
await p.waitForTimeout(100);
|
||||
const [w, b] = await p.evaluate(() => [document.getElementById("ledWrap").scrollLeft, document.getElementById("ledHScroll").scrollLeft]);
|
||||
assert(w > 100 && w === b, "the bar followed the table: " + JSON.stringify({ w, b }));
|
||||
|
||||
// the bar dragged: it is never written back, and the table follows it
|
||||
const bar = await p.evaluate(() => window.__swipe("ledHScroll"));
|
||||
assert.equal(bar.writes.ledHScroll, 0, "the page wrote the dragged bar back: " + JSON.stringify(bar));
|
||||
await p.waitForTimeout(100);
|
||||
const [w2, b2] = await p.evaluate(() => [document.getElementById("ledWrap").scrollLeft, document.getElementById("ledHScroll").scrollLeft]);
|
||||
assert(b2 > 100 && w2 === b2, "the table followed the bar: " + JSON.stringify({ w2, b2 }));
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user