gui: once the loading bird comes it lands before the page fills

The owner (10-30): a load that finished just as the bird came had it
appear over no skeleton and streak off, which read as a bug. The bird
still comes only after ~450ms of skeletons. Once it has come, a GET read
through api() (and routing's history fetch) that comes back before its
first landing waits for it: the skeletons stay, the bird drops and lands
(about 0.5s), then flies off as the content goes in. A read back later
isn't held. The hold lets go after 1.5s at most, for a hidden window that
draws no frames. If its bar goes during the drop anyway (a read not
through api()), the bird fades where it is instead of flying across the
content. Reduced motion and Loading bird off never hold anything, since
no bird comes.

Run on mote (macOS 27), at this tree on origin/main 81bdca1fe:
- skeleton-bird, tray-bird, plugin-readme-bird, both engines: 26 pass,
  0 fail, the new "a load done as the bird comes keeps its skeletons
  until the bird has landed once" included.
- Broken by hand: the new test on the old app.js fails in both engines
  ("the bird landed on a bar before the skeletons went").
- 22 GUI files around loading pages (modal-centred-late,
  plugin-github-wait, plugin-progressive, usage-focus-steady,
  usage-stale-answer, routing-js, routing-steady, routing-day-window,
  routing-time, usage-ledger, usage-refresh, library-loading,
  sessions-overview, plugin-market, providers-fetching, gateway-card,
  panel-usage, agent-models-loading, plugin-page, i18n-keys,
  reduce-motion, held-animations): 237 pass, 8 fail. The 8 are
  routing-steady (#3412) and usage-ledger's "newest live route needs no
  return-to-live button" (#3104, #4078), which fail the same at
  81bdca1fe without this change.
- go test -run Budget ./internal/gui/: ok, no raise. gofmt -l: clean.

Not run: the full GUI suite (another session's full suite was running on
mote; one per machine), Linux and Windows.
This commit is contained in:
yetone
2026-10-30 01:31:51 +08:00
parent 05a6087e1f
commit 8cbd0a9c91
3 changed files with 54 additions and 5 deletions
+26 -3
View File
@@ -126,6 +126,7 @@ async function api(path, body, heads, signal) {
body: body === undefined ? undefined : JSON.stringify(body),
signal,
});
if (body === undefined) await skelHold();
heads?.(res.headers);
if (had && res.ok && res.headers.get("X-Magpie-Same")) return had.data;
if (res.status === 204) return null;
@@ -8507,6 +8508,16 @@ function skelSeen() {
// left, and with the bird turned off neither runs (a 1-core server:
// Yayoi_no_yume on X).
let skelSince = 0, skelFlying = false, skelTick = 0;
// Once the bird has come it lands at least once (the owner, 10-30: a load
// done as it came had it streak off over no skeleton): a read back before
// then waits for it, and is let go as it leaves. At most 1.5s, for a frame
// a hidden window never draws.
let skelGate = null, skelWaiting = 0;
async function skelHold() {
if (!skelGate) return;
skelWaiting++;
try { await skelGate; } finally { skelWaiting--; }
}
const skelAdded = new MutationObserver((recs) => {
for (const r of recs) for (const n of r.addedNodes) if (n.nodeType === 1 && (n.matches(SKEL) || n.querySelector(SKEL))) return skelWatch();
});
@@ -8529,6 +8540,9 @@ function skelWatch() {
skelWatch();
async function skelBird() {
skelFlying = true;
let release;
const gate = skelGate = new Promise((ok) => { release = () => { if (skelGate === gate) skelGate = null; ok(); }; });
setTimeout(release, 1500);
const b = el("div", "sk-bird roam");
b.innerHTML = BIRD;
document.body.append(b);
@@ -8549,17 +8563,24 @@ async function skelBird() {
const after = seen.filter((t) => s.compareDocumentPosition(t) & Node.DOCUMENT_POSITION_FOLLOWING);
return after[0] || seen[0];
};
let s = next(null);
if (!s) return void (b.remove(), (skelFlying = false));
let s = next(null), quiet = false;
if (!s) return void (b.remove(), release(), (skelFlying = false));
try {
let at = spot(s);
put({ x: at.x - 24, y: at.y - 40, f: 1 });
b.animate([{ opacity: 0 }, { opacity: 1 }], 120);
await tween(300, (e, t) => put({ x: at.x - 24 + 24 * t, y: at.y - 40 + 40 * e, sx: 1 - .05 * t, sy: 1 + .08 * t }), easeIn);
// its bar gone before it landed: it fades where it is, never flying
// over what came instead
if (!s.isConnected) return void (quiet = true);
for (let hops = 0; hops < 400; hops++) {
// it lands: the bar dips under it and springs back
s.animate([{ transform: "none" }, { transform: "translateY(3px)", offset: .3 }, { transform: "translateY(-1.2px)", offset: .6 }, { transform: "translateY(.4px)", offset: .8 }, { transform: "none" }], { duration: 560, easing: "ease-out" });
await tween(130, (e) => put({ y: at.y + 3 * e, sx: 1 + .14 * e, sy: 1 - .18 * e }), easeOut);
await tween(90, (e) => put({ y: at.y + 3 * (1 - e), sx: 1.14 - .14 * e, sy: .82 + .18 * e }), easeIn);
// landed once: a read held for it means the load is done
if (!hops && skelWaiting) break;
if (!hops) release();
const to = birdOff() ? null : next(s);
if (!to) break;
const from = { x, y }, go = spot(to), h = 16 + Math.min(40, Math.hypot(go.x - from.x, go.y - from.y) * .15);
@@ -8572,10 +8593,12 @@ async function skelBird() {
s = to; at = { x, y };
}
} finally {
release();
// nothing left to stand on: it flies off, up and away
if (quiet) await b.animate([{ opacity: 1 }, { opacity: 0, transform: b.style.transform + " scale(.6)" }], { duration: 160, easing: "ease-in", fill: "forwards" }).finished;
b.dataset.flap = "";
const from = { x, y };
await tween(480, (e) => put({ x: from.x + (innerWidth + 60 - from.x) * e, y: from.y - (from.y + 80) * e, f: 1, r: -14, sx: 1, sy: 1 }), easeIn);
if (!quiet) await tween(480, (e) => put({ x: from.x + (innerWidth + 60 - from.x) * e, y: from.y - (from.y + 80) * e, f: 1, r: -14, sx: 1, sy: 1 }), easeIn);
b.remove();
skelFlying = false;
skelSince = 0;
@@ -3212,7 +3212,9 @@ function routingPage(part) {
};
async function loadDays(d) {
try {
const res = await (await fetch("/api/gateway/history?day=" + encodeURIComponent(d || ""))).json();
const got = await fetch("/api/gateway/history?day=" + encodeURIComponent(d || ""));
await window.skelHold?.();
const res = await got.json();
days = res.days || [];
noteAccounts(res.routes);
if (d && d === day) { past = (res.routes || []).map(whole); pastCut = !!res.cut; }
+25 -1
View File
@@ -2,7 +2,8 @@
// What is loading has magpie's bird on it (the owner, 10-26): skeletons
// still up after a moment, as on a slow page, get the bird, which hops from
// bar to bar, each bar dipping under it, and flies off once they are gone.
// A quick load never sees it, and with reduced motion no bird comes.
// A quick load never sees it, and with reduced motion no bird comes. Once
// it has come it lands once before the page fills (the owner, 10-30).
// Settings' Loading bird (Yayoi_no_yume on X, a 1-core server) turns it
// off: no bird comes and nothing looks for skeletons. With it on, the look
// every 250ms runs only while a skeleton is in the page.
@@ -98,6 +99,29 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.deepEqual(errors, []);
});
test(engine + ": a load done as the bird comes keeps its skeletons until the bird has landed once", async (t) => {
const browser = await launch();
t.after(() => browser.close());
let release;
const held = new Promise((r) => { release = r; });
const { page, errors } = await open(browser, false, () => held);
await page.locator("#view-plugins .pm-card.ghost").first().waitFor();
// how many bars had dipped under the bird when the last skeleton went
await page.evaluate(() => new MutationObserver((ms, o) => {
if (document.querySelector("#view-plugins .pm-card.ghost")) return;
seen.dipsAtGone = seen.dips; seen.goneAt = performance.now(); o.disconnect();
}).observe(document.body, { childList: true, subtree: true }));
await page.locator(".sk-bird.roam").waitFor({ state: "attached", timeout: 3000 });
const at = await page.evaluate(() => performance.now());
release();
await page.waitForFunction(() => seen.goneAt, null, { timeout: 3000 });
const { dipsAtGone, goneAt } = await page.evaluate(() => seen);
assert.ok(dipsAtGone > 0, "the bird landed on a bar before the skeletons went");
assert.ok(goneAt - at < 1500, `the load waited at most for one landing (${Math.round(goneAt - at)}ms)`);
await page.waitForFunction(() => !document.querySelector(".sk-bird"), null, { timeout: 2000 });
assert.deepEqual(errors, []);
});
test(engine + ": a quick load never sees the bird", async (t) => {
const browser = await launch();
t.after(() => browser.close());