library: a resize no longer works out every agent chip's style again (lexrus on X)
lexrus's Skills page (196 skills, By source, about 24 agent chips a row, dark) crawled while the window was resized. Each row's chip strip was a size container, and the chips' gap used cqw. Chromium invalidates every style with container units on each change of the viewport width (ViewportUnits), so every chip was recalculated on each resize step. Now handGap works the gap out in whole pixels from each row's content-box width, which a ResizeObserver on the .lib-row hands over, so there is no forced layout and no container query. The CSS clamps --lib-gap as before, and the gap is set only when it changes. While the window is resized, .lib-resizing (held 600ms after the last step) turns the chips' translate transitions off, which WebKit was paying to start on every step. Measured with a Playwright probe at the reporter's scale (259 rows, 6425 chips, every group open), 30 resize steps between 1200px and up, CDP Performance.getMetrics and tracing, on mote: - Chromium: resize wall 24.4-29.3s -> 2.7s; style recalc 18.2-22.1s -> 1.3s; layout 0.47-0.71s -> 0.17s; long tasks 53-65 (6.8-8.0s) -> 15 (1.7s). - WebKit: resize wall 25.9-31.6s -> 9.2s; average frame 235-277ms -> 48ms (hiding every chip gives 1.8s, the floor). - Scroll is unchanged (about 31ms frames in Chromium, 20ms in WebKit). content-visibility was tried and dropped: it made scroll worse. skill-name-many-agents.test.cjs now resizes 866px -> 560px and checks the strips match a fresh 560px render, and a guard fails if library.css uses container units again. Broken by hand (handGap run only once): 3 pass, 3 fail. Restored: green. Run on mote at this head (rebased on1b360f08c): - The 180 library GUI files, Chromium and WebKit, --test-concurrency=4: 1870/47 and 1872/45. Every red file run again alone on origin/main1b360f08cand on this head, both engines: the same reds on both, none new here (main 95/46 and 98/43, this head 99/43 and 99/43). They are filed: #5982 (update/using in strict recorders: skill-fold-all, skill-manual), #6667, #6751 (library-open-again), #3403/#6570 (old-webkit), #3952/#5013 (mobile-web, found-skill-pick-remove), #5859 (skill-where), #6687 (skill-group-shared), #4620 (market-have), #7097 (win-caption, text-size, search-mcp-library). - go test ./internal/gui/ ./internal/library/ (they read these assets): library ok; gui red once in TestLaneLimitRoutes, which read a running gateway's real volcengine lane (#5150); -count=3 of it alone is ok at this head and on origin/main. - Rebased on454f9d023, which changed client.js's MCP router row: at that head skill-name-many-agents, library-mcp-router-tools and i18n-keys pass 21/0 in Chromium and in WebKit, and go test ./internal/gui/ is ok. Not run before the push: the full Go suite (mote at load 34-50, mica's disk full); it runs after the tag. No Go file changed.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -285,6 +285,33 @@ magpie.plugin("library", (ctx) => {
|
||||
return url;
|
||||
}
|
||||
|
||||
// How far a row's chips close up (#936) follows the row's width: each goes
|
||||
// further under the one before so the hand stays in about half the row.
|
||||
// It is measured here, rounded to a whole pixel and set only when that
|
||||
// changes, not worked out in CSS from 48cqw: a value in container units
|
||||
// is worked out again for every chip on every change of the window's
|
||||
// width, and with 196 skills of 24 chips each a resize spent ~0.5s a step
|
||||
// on it (lexrus on X).
|
||||
const handSizes = new ResizeObserver((entries) => {
|
||||
for (const e of entries) {
|
||||
const row = e.target, box = row._hand;
|
||||
if (!row.isConnected || !box || box.parentElement !== row) { handSizes.unobserve(row); continue; }
|
||||
const w = e.contentBoxSize?.[0]?.inlineSize ?? e.contentRect.width;
|
||||
if (w > 0) handGap(box, w);
|
||||
}
|
||||
});
|
||||
function handGap(box, w) {
|
||||
const n = box._n || 1;
|
||||
// outside -19px to 3px the CSS clamps it the same, so nothing is set
|
||||
const gap = Math.min(3, Math.max(-19, Math.round((0.48 * w - 60 - n * 24) / Math.max(1, n - 1)))) + "px";
|
||||
if (box.style.getPropertyValue("--lib-gap") !== gap) box.style.setProperty("--lib-gap", gap);
|
||||
}
|
||||
function handRoom(row, box, n) {
|
||||
box._n = n;
|
||||
row._hand = box;
|
||||
handSizes.observe(row);
|
||||
}
|
||||
|
||||
// Agent chips for a server or a skill: each agent that could have it, lit
|
||||
// when it does. A chip whose agent couldn't be given it says why. One that
|
||||
// has it whatever is ticked (opts.always: a skill kept in ~/.agents/skills,
|
||||
@@ -306,7 +333,12 @@ magpie.plugin("library", (ctx) => {
|
||||
box.style.setProperty("--lib-agent-count", shown.length);
|
||||
// the row it is put in says so (.with-agents), for its name's room:
|
||||
// Safari before 15.4 has no :has(). Every caller appends it at once.
|
||||
queueMicrotask(() => box.parentElement?.classList.contains("lib-row") && box.parentElement.classList.add("with-agents"));
|
||||
queueMicrotask(() => {
|
||||
const row = box.parentElement;
|
||||
if (!row?.classList.contains("lib-row")) return;
|
||||
row.classList.add("with-agents");
|
||||
handRoom(row, box, shown.length);
|
||||
});
|
||||
for (const [i, g] of shown.entries()) {
|
||||
if (g.family) { box.append(profileChip(g, i, shown.length, all, on, onChange, opts)); continue; }
|
||||
const a = g.a;
|
||||
@@ -6638,7 +6670,16 @@ magpie.plugin("library", (ctx) => {
|
||||
clearTimeout(still);
|
||||
still = setTimeout(settled, 150);
|
||||
}, { passive: true });
|
||||
window.addEventListener("resize", queueLists);
|
||||
// and while the window is resized, the page says so (.lib-resizing): a
|
||||
// chip's slide is not run as the hand closes up, which in WebKit was
|
||||
// most of each step's time with thousands of chips (lexrus on X)
|
||||
let sizing = 0;
|
||||
window.addEventListener("resize", () => {
|
||||
queueLists();
|
||||
if (!sizing) page.classList.add("lib-resizing");
|
||||
clearTimeout(sizing);
|
||||
sizing = setTimeout(() => { sizing = 0; page.classList.remove("lib-resizing"); }, 600);
|
||||
});
|
||||
}
|
||||
|
||||
// The filling: one list's next few rows per idle moment, the lists in turn.
|
||||
|
||||
@@ -382,15 +382,16 @@ input.lib-setname:focus { border-color: var(--accent); box-shadow: 0 0 0 3px col
|
||||
(#936), so the hand stays in about half the row and the name beside it
|
||||
keeps its room: --lib-stack is how far a chip goes under the one before,
|
||||
-7px while they fit, --lib-fan the same fanned out, 3px while they fit.
|
||||
A WebKit without container units keeps -7px and 3px. */
|
||||
@supports (width: 1cqw) {
|
||||
.lib-row.with-agents { container-type: inline-size; }
|
||||
.lib-row > .lib-agents {
|
||||
--lib-n: var(--lib-agent-count, 1);
|
||||
--lib-gap: calc((48cqw - 60px - var(--lib-n) * 24px) / max(1, var(--lib-n) - 1));
|
||||
--lib-stack: clamp(-19px, var(--lib-gap), -7px);
|
||||
--lib-fan: clamp(var(--lib-stack), var(--lib-gap), 3px);
|
||||
}
|
||||
--lib-gap is the room each chip has, set in whole pixels from the row's
|
||||
width (handGap in client.js), never from container units here: those
|
||||
make every chip's style be worked out again on every change of the
|
||||
window's width. While the window is resized the chips don't slide
|
||||
(.lib-resizing, client.js): thousands of slides started at once took
|
||||
most of each step in WebKit. */
|
||||
.lib-resizing .lib-row > .lib-agents .lib-ag { transition: none; }
|
||||
.lib-row > .lib-agents {
|
||||
--lib-stack: clamp(-19px, var(--lib-gap, -7px), -7px);
|
||||
--lib-fan: clamp(var(--lib-stack), var(--lib-gap, 3px), 3px);
|
||||
}
|
||||
.lib-row > .lib-agents .lib-ag.on { border-color: var(--line); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
|
||||
.lib-row > .lib-agents .lib-ag.via { border-style: dashed; }
|
||||
|
||||
@@ -45,11 +45,21 @@ const SKILLS = [
|
||||
{ name: "notes", kind: "", source: "", description: "d", agents: ALL.slice(3) },
|
||||
];
|
||||
|
||||
// The hand's room is set in whole pixels from the row's width (handGap in
|
||||
// plugins/library/client.js), never in container units: a chip's style
|
||||
// in cqw is worked out again on every change of the window's width, and
|
||||
// at 196 skills of 24 agents a resize took ~0.5s a step (lexrus on X).
|
||||
test("the library's chips use no container units", async () => {
|
||||
const css = await fs.readFile(path.join(assets, "plugins/library/library.css"), "utf8");
|
||||
assert.equal(/[\d.](cqw|cqi|cqh|cqb|cqmin|cqmax)\b/.test(css.replace(/\/\*[\s\S]*?\*\//g, "")), false);
|
||||
});
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
test(engine + ": a skill keeps its name beside many agents", async (t) => {
|
||||
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: process.env.PLAYWRIGHT_CHANNEL || "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const resized = {};
|
||||
for (const lang of ["en", "zh"]) for (const width of [866, 560]) {
|
||||
await t.test(`${lang} ${width}px`, async () => {
|
||||
const state = {
|
||||
@@ -75,7 +85,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
// unfold every group, so its skills are drawn
|
||||
for (const h of await v.locator(".lib-grouphead:not(.open)").all()) await h.click();
|
||||
await v.locator(".lib-group .lib-row:not(.lib-grouphead) .name", { hasText: "notes" }).waitFor({ state: "attached" });
|
||||
const rows = await v.locator(".lib-group .lib-row").evaluateAll((rs) => rs.map((r) => {
|
||||
const measure = () => v.locator(".lib-group .lib-row").evaluateAll((rs) => rs.map((r) => {
|
||||
const n = r.querySelector(".name"), rb = r.getBoundingClientRect(), nb = n.getBoundingClientRect();
|
||||
const chips = r.querySelector(":scope > .lib-agents");
|
||||
const cb = chips && chips.getBoundingClientRect();
|
||||
@@ -83,9 +93,24 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
head: r.classList.contains("lib-grouphead"), text: n.textContent.trim(),
|
||||
nameW: nb.width, nameShown: nb.width >= Math.min(60, n.scrollWidth) && nb.left >= rb.left && nb.right <= rb.right + 0.5,
|
||||
chipsIn: !cb || (cb.left >= rb.left - 0.5 && cb.right <= rb.right + 0.5),
|
||||
hand: cb ? Math.round(cb.width) : 0,
|
||||
bg: getComputedStyle(r).backgroundColor, weight: getComputedStyle(n).fontWeight,
|
||||
};
|
||||
}));
|
||||
// the hand's room follows the window as it is resized (handGap), not
|
||||
// only the width it was drawn at
|
||||
if (width === 866) {
|
||||
await page.setViewportSize({ width: 560, height: 900 });
|
||||
await page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
|
||||
const narrower = await measure();
|
||||
for (const r of narrower) assert(r.chipsIn, `${r.text}: its agents run out of its row once the window is narrower`);
|
||||
resized[lang] = narrower.map((r) => [r.text, r.hand]);
|
||||
await page.setViewportSize({ width, height: 900 });
|
||||
await page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
|
||||
}
|
||||
const rows = await measure();
|
||||
// a hand resized to 560px closes up as one drawn at 560px does
|
||||
if (width === 560 && resized[lang]) assert.deepEqual(resized[lang], rows.map((r) => [r.text, r.hand]), "the hands drawn at 866px and narrowed to 560px");
|
||||
const skills = rows.filter((r) => !r.head), heads = rows.filter((r) => r.head);
|
||||
assert.deepEqual(heads.map((h) => h.text), ["mattpocock/skills", "obra/superpowers", lang === "zh" ? "本机" : "On this computer"]);
|
||||
assert.deepEqual(skills.map((s) => s.text).sort(), ["brainstorming", "notes", "tdd", "writing-plans"]);
|
||||
|
||||
Reference in New Issue
Block a user