about: the Version row and the title bar hold still while the update's state comes in (#4057)

#4057 lists four jumps on Settings › About and the title bar. Each was
reproduced in Chromium and WebKit (update-row-steady.test.cjs) before
the fix:

1. Opened cold (no state read yet), the Version row drew with no line
   under its name, 48px, and grew to 60px when the read came in. The
   line is now kept, empty (a no-break space), until the answer.
2. Opened with a state read long ago, the row drew it first: "Up to
   date" and Check, then "0.1.x is downloaded" a moment later. A state
   is drawn early only when read in the last 30s (#3469's case, a row
   drawn again within Settings, still is); an older one may be old
   news, so the line waits empty for the answer.
3. The header's Update pill showing pushed the Settings search in the
   title bar beside the sidebar ~80px left in one frame, through the
   ResizeObserver that sets --tools-r. The pill now opens from nothing
   (max-width and padding from 0 in update-in), so the search slides
   over with it during the pill's .45s entrance instead. It still ends
   ~80px left: the pill needs the room, and holding it empty for a pill
   that is usually not there would take it from the title.
4. Not changed: a failed download's reason still wraps (sub.wraps).
   It is a new state, not a flicker, and the reason is shown in full on
   purpose: the network case says what to do (Click Check, or the
   release page), which a one-line cut would hide. A Check from there
   keeps the class until its answer, so the row doesn't shrink and grow
   on each try.

No new strings. app.js grows 26 bytes over origin/main 11cbf4de1,
which had filled its budget to the byte; it fits TestCoreScriptBudget
with renderUpdate's doc comment shortened and u.at set with ??= instead
of a guard. No budget raised.

Run on mote (macOS 27), at this tree:
- update-row-steady.test.cjs, both engines, en and zh: 14 of 14 pass.
- The same file over the old app.js/app.css: every case red in both
  engines. Cold: "the row is 60.28125px with its answer; 21 of 22
  frames drew it otherwise". Stale: '"Up to date", a minute old, was
  drawn in 21 of 22 frames'. Pill: "the search moved 79px in the pill's
  first frame" (zh 61px).
- go test -run Budget ./internal/gui: ok.
- go test -run Budget ./internal/gui at this head: ok. The update
  tests of the commit before (internal/gui, internal/update) at the
  rebased tree: ok.
- update-*, about-* and models-fold at this head, both engines: 318
  of 320. The two reds are models-fold webkit en/zh "the click
  scrolled" ('0 ebody holds:289'), red the same alone at origin/main
  11cbf4de1 (#4071).
- The whole GUI suite (953 files, both engines, --test-concurrency=4)
  at 1b01e7e4f, this change on 56d26f0bb, mote at load ~40: 13908 of
  14019, 111 reds in 29 files, none in a file this change touches.
  The 29 files rerun at concurrency 2 at that head and at origin/main
  11cbf4de1 gave 93 and 89 reds, in the same files. Each red file has
  its issue: gateway-key-models #4081, header-centre #3479, key-replace
  #3476, library-row-remove #3099, menu-input-scroll #3402, mobile-web
  #3952, rest-try-now #2564, routing-many-keys #4082, routing-row-swap
  #3799, routing-rule-drag #3789, routing-rule-remove #3094/#3096,
  routing-rules-line #3593, routing-steady #3412, routing-story-shrinks
  #3954, s3-sync #3413/#2448, search-first #3795, usage-agents-hide
  #3414, usage-ledger #1876, models-fold #4071, quota-count-wrap #3404,
  model-suffix-own #1671, signin-closes-sheet #2628,
  signin-paste-import #4035, key-import #4086, revoked-signin-account
  #4083, search-instead #4084, signin-paste-codex #4085. i18n-keys'
  red (#4053, since fixed on main) passes at the rebased tree, and
  quota-count-wrap passed there too.

Not tried: the real Linux app under WebKitGTK (the entrance animates
max-width, a layout change, no compositing); the whole GUI suite again
at the rebased head after the 23-byte trim (budget, update-*, about-*
were rerun there).
This commit is contained in:
yetone
2026-10-28 23:22:14 +08:00
parent 257eab646d
commit 89f3865efa
3 changed files with 186 additions and 11 deletions
+5 -2
View File
@@ -270,9 +270,12 @@ body.panel .seg { display: none; }
WebKit turns a whole svg on a layer snapped to the pixel grid, so off a
whole pixel its ring circles about a point a pixel or so off its centre */
.icon.spin svg > * { transform-box: view-box; transform-origin: 50% 50%; animation: spin .9s linear infinite; }
/* a newer magpie is ready: a quiet pill before the header's icons */
/* a newer magpie is ready: a quiet pill before the header's icons. It
opens from nothing, so the title bar's tools beside the sidebar (app.js
tools) slide over to make room, not jump 80px at once (#4057) */
.update {
align-self: center; display: inline-flex; align-items: center; gap: 4px;
max-width: 20em; overflow: hidden;
height: 22px; margin-right: 6px; padding: 0 9px 0 7px; border-radius: 999px;
font-size: 11.5px; font-weight: 560; letter-spacing: .005em; white-space: nowrap;
color: var(--accent); background: var(--accent-soft);
@@ -336,7 +339,7 @@ body.window .top.inrow .actions { margin-left: 0; }
body.web .top #nav button { flex: none; height: 40px; padding: 0 14px; font-size: 14px; }
body.web .top .actions { gap: 4px; }
}
@keyframes update-in { from { opacity: 0; transform: translateY(-3px) scale(.94); } }
@keyframes update-in { from { opacity: 0; max-width: 0; margin-right: 0; padding: 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
/* ---- the sidebar (app.js layoutNav) -------------------------------------- */
+7 -9
View File
@@ -4272,7 +4272,7 @@ function updatePath(p) {
async function renderUpdateBadge() {
const b = $("#update"), label = b.querySelector("span");
const u = await api(updatePath("update")).catch(() => null);
if (u) updateLast = u;
if (u) updateLast = u, u.at = Date.now();
// pulling: a click is downloading it again, and restarts once it's in
const pulling = !!u && !!b.dataset.pulling && ["checking", "downloading", "ready"].includes(u.state);
if (b.dataset.pulling && !pulling) {
@@ -22486,25 +22486,23 @@ function editRedactRule(r, n, row) {
}
// renderUpdate fills in the version row: whether a newer magpie is out.
// The app checks and downloads on its own, so usually the row just offers
// the restart; a check can also be asked for. That check leaves the button
// where it is, dimmed, and a second click does nothing. A read still out
// from before the answer is not drawn over it. A row drawn again draws the
// last state at once, but in a check (#3469), and reads while a check or a
// download is under way.
// A check asked for dims its button, ignores a second click, and isn't
// drawn over by an older read. A row drawn again draws a state read in the
// last 30s at once (#3469); an older one may be stale, so it waits (#4057).
let updateBusy = false, updateLast = null;
const updateSeq = new WeakMap(), seqOf = (r) => updateSeq.get(r) || 0;
async function renderUpdate(r, u) {
const seq = seqOf(r);
if (u == null) {
const early = !updateBusy && updateLast && !r.querySelector(".sub");
const bare = !r.querySelector(".sub"), early = bare && !updateBusy && Date.now() - updateLast?.at < 3e4;
if (early) renderUpdate(r, updateLast);
else if (bare) r.querySelector(".who").append(el("div", "sub", "\u00a0"));
u = await api(updatePath("update?fresh=1")).catch(() => null);
if (!u || !r.isConnected || seqOf(r) !== seq) return;
if (early) updateSeq.set(r, seq + 1); // stops timers
} else if (!r.isConnected) return;
updateLast = u;
updateLast = u, u.at ??= Date.now();
const who = r.querySelector(".who"), val = r.querySelector(".val");
const sub = who.querySelector(".sub") || who.appendChild(el("div", "sub"));
sub.title = "";
@@ -0,0 +1,174 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// Settings › About and the title bar hold still while the update's state
// comes in (#4057):
// - opened cold, with no state read yet, the Version row keeps the line
// under its name for the answer, rather than growing 12px when it lands;
// - opened with a state read a minute ago ("Up to date") while a check has
// since downloaded a newer version, that old state isn't drawn first and
// swapped for "0.1.401 is downloaded";
// - the header's Update pill showing opens from nothing, so the Settings
// search in the title bar beside the sidebar slides over with it rather
// than jumping 80px left in one frame.
// English and Chinese; no backend, the API is faked here.
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 { watchSettingsReads, settingsDrawn } = require("./reader.cjs");
const assets = path.resolve(__dirname, "../assets");
const words = {
en: { version: "Version", latest: "Up to date", ready: "0.1.401 is downloaded" },
zh: { version: "版本", latest: "已是最新", ready: "0.1.401 已下载" },
};
function server(lang, ctl) {
const settings = {
theme: "light", lang, tray: "panel", quotaLeft: false, currency: "usd", proxy: "", redact: false, redactWords: [],
version: "0.1.400", dir: "~/.config/magpie", gateway: "http://127.0.0.1:3425", proxyNow: "none", proxySource: "none",
visionModels: [], imageGenModels: [], workbuddyCheckins: [], lanURLs: [], fx: { rate: 7.2, at: new Date().toISOString(), stale: false },
};
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:false};` });
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: settings.fx });
if (url.pathname === "/api/settings") return json(settings);
if (url.pathname === "/api/update") {
if (ctl.hold) await ctl.hold;
return json(ctl.update || { state: "latest", current: "0.1.400" });
}
if (url.pathname === "/api/usage/quotas") return json([]);
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
if (url.pathname.startsWith("/api/")) return json({});
if (!/^\/[\w./-]*$/.test(url.pathname) || url.host !== "magpie.test") return route.fulfill({ status: 404, body: "" });
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)];
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
};
}
const ready = { state: "ready", current: "0.1.400", latest: "0.1.401" };
// every frame, the Version row's height and the line under its name
const watchRow = (version) => {
window.__rows = [];
const look = () => {
const r = [...document.querySelectorAll("#about .row.pref")].find((r) => r.querySelector(".name")?.textContent === version);
if (r && r.offsetParent && !r.dataset.left) window.__rows.push({ h: r.getBoundingClientRect().height, sub: r.querySelector(".who .sub")?.textContent ?? null });
if (!window.__stop) requestAnimationFrame(look);
};
look();
};
async function open(browser, lang, ctl, width, url) {
const errors = [];
const page = await (await browser.newContext({ viewport: { width, height: 700 } })).newPage();
page.setDefaultTimeout(5000);
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", server(lang, ctl));
await watchSettingsReads(page);
await page.addInitScript(`(${watchRow})(${JSON.stringify(words[lang].version)})`);
await page.goto(url);
return { page, errors };
}
const versionRow = (page, lang) => page.locator("#about .row.pref", { has: page.locator(".name", { hasText: words[lang].version }) }).first();
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": the Version row and the title bar hold still while the update's state comes in (#4057)", 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());
for (const lang of Object.keys(words)) {
const w = words[lang];
await t.test(lang + ": opened cold, the row keeps its line for the answer", async () => {
let release;
const ctl = { hold: new Promise((go) => (release = go)) };
const { page, errors } = await open(browser, lang, ctl, 900, "http://magpie.test/?view=settings&tab=about");
await settingsDrawn(page);
await page.waitForFunction(() => window.__rows.length > 20);
release();
const row = versionRow(page, lang);
await row.locator(".sub", { hasText: w.latest }).waitFor();
await page.evaluate(() => (window.__stop = true));
const tall = (await row.boundingBox()).height;
const rows = await page.evaluate(() => window.__rows.slice());
const off = rows.filter((s) => Math.abs(s.h - tall) > 0.5);
assert.deepEqual(off.slice(0, 3), [], `the row is ${tall}px with its answer; ${off.length} of ${rows.length} frames drew it otherwise`);
assert.deepEqual(errors, []);
await page.context().close();
});
await t.test(lang + ": a state read a minute ago isn't drawn before the answer", async () => {
const ctl = {};
const { page, errors } = await open(browser, lang, ctl, 900, "http://magpie.test/?view=settings&tab=about");
await settingsDrawn(page);
const row = versionRow(page, lang);
await row.locator(".sub", { hasText: w.latest }).waitFor();
const tall = (await row.boundingBox()).height;
await page.evaluate(() => show("agents"));
// a minute on, a check has downloaded 0.1.401; its read is held
let release;
ctl.hold = new Promise((go) => (release = go));
ctl.update = ready;
// the row left on screen is drawn again when Settings is: only the
// new row's frames count
await page.evaluate((version) => {
for (const r of document.querySelectorAll("#about .row.pref")) r.dataset.left = "1";
const now = Date.now;
Date.now = () => now() + 60e3;
window.__rows = [];
show("settings");
}, w.version);
await page.waitForFunction(() => window.__rows.length > 20);
release();
await row.locator(".sub", { hasText: w.ready }).waitFor();
await page.evaluate(() => (window.__stop = true));
const rows = await page.evaluate(() => window.__rows.slice());
const stale = rows.filter((s) => s.sub === w.latest);
assert.equal(stale.length, 0, `"${w.latest}", a minute old, was drawn in ${stale.length} of ${rows.length} frames before "${w.ready}"`);
const off = rows.filter((s) => Math.abs(s.h - tall) > 0.5);
assert.deepEqual(off.slice(0, 3), [], `the row is ${tall}px; ${off.length} of ${rows.length} frames drew it otherwise`);
assert.deepEqual(errors, []);
await page.context().close();
});
await t.test(lang + ": the Update pill opens from nothing, the search beside the sidebar sliding with it", async () => {
const ctl = {};
const { page, errors } = await open(browser, lang, ctl, 1200, "http://magpie.test/?view=settings&tab=about");
await settingsDrawn(page);
await versionRow(page, lang).locator(".sub", { hasText: w.latest }).waitFor();
assert.ok(await page.evaluate(() => document.body.classList.contains("side-nav")), "a sidebar at 1200px");
const frames = () => page.evaluate(() => new Promise((go) => requestAnimationFrame(() => requestAnimationFrame(() => requestAnimationFrame(go)))));
await frames();
const at = () => page.evaluate(() => $("#setQ").getBoundingClientRect().left);
const before = await at();
// the pill's opening is held at its first frame, as it is shown
ctl.update = ready;
await page.evaluate(() => {
const b = $("#update");
new MutationObserver(() => {
if (b.hidden) return;
window.__opening = b.getAnimations();
for (const a of window.__opening) { a.pause(); a.currentTime = 0; }
}).observe(b, { attributes: true, attributeFilter: ["hidden"] });
renderUpdateBadge();
});
await page.waitForFunction(() => !$("#update").hidden && window.__opening);
await frames();
const first = await at();
assert.ok(Math.abs(first - before) <= 1, `the search moved ${before - first}px in the pill's first frame`);
await page.evaluate(() => { for (const a of window.__opening) a.finish(); });
await frames();
const after = await at();
assert.ok(before - after > 30, `the pill took its room once open: the search at ${before}, then ${after}`);
assert.deepEqual(errors, []);
await page.context().close();
});
}
});
}