diff --git a/internal/gui/assets/plugingrid.js b/internal/gui/assets/plugingrid.js index 10be6cedc..7fe937f50 100644 --- a/internal/gui/assets/plugingrid.js +++ b/internal/gui/assets/plugingrid.js @@ -3,10 +3,14 @@ // with all of them. The grid keeps the whole list's height in its padding // above and below what it shows, and the rows follow the scroll; a card // with focus is kept. plugins.js imports this when its page is first drawn, -// so it weighs nothing on the core; a list shorter than its VMIN is drawn -// whole there. -window.pmVirtualGrids = function (page, card) { +// so it weighs nothing on the core; a list shorter than VMIN is drawn +// whole there. body() is Discover's body, and draw() draws it again. +window.pmVirtualGrids = function (page, card, body, draw) { + const VMIN = 48; // the shortest list drawn in part const VMORE = 700; // px drawn past each edge of the view + // a long list drawn whole before this came is drawn again, once the + // caller holds what this returns + queueMicrotask(() => { if (body()?.querySelector(".pm-grid:not(.pm-virtual) > .pm-card:nth-child(" + VMIN + ")")) draw(); }); const vgrids = new Set(); let vrowH = 172, vcols = 3; // a row's height and the columns, as last measured function grid(g, list) { @@ -106,5 +110,5 @@ window.pmVirtualGrids = function (page, card) { const vsoon = () => { if (vgrids.size && !vframe) vframe = requestAnimationFrame(vnow); }; page.addEventListener("scroll", vsoon, { passive: true }); if (window.ResizeObserver) new ResizeObserver(vsoon).observe(page); - return { grid, now: vnow }; + return { grid, now: vnow, min: VMIN }; }; diff --git a/internal/gui/assets/plugins.js b/internal/gui/assets/plugins.js index b1ff6b8ce..0cd82d777 100644 --- a/internal/gui/assets/plugins.js +++ b/internal/gui/assets/plugins.js @@ -647,16 +647,14 @@ // a long list draws only the rows near the view (plugingrid.js); until // that has come, and for a short list, every card is drawn - const VMIN = 48; - let vg = null; - const vload = () => vload.p = vload.p || import("./plugingrid.js").then(() => { vg = pmVirtualGrids(page, card); if (body?.querySelector(".pm-grid:not(.pm-virtual) > .pm-card:nth-child(" + VMIN + ")")) drawBody(); }, () => {}); + let vg; + const vload = () => vload.p = vload.p || import("./plugingrid.js").then(() => vg = pmVirtualGrids(page, card, () => body, drawBody), () => {}); function cardGrid(list) { const g = el("div", "pm-grid"); - if (list.length >= VMIN && vg) return vg.grid(g, list); + if (list.length >= vg?.min) return vg.grid(g, list); for (const l of list) g.append(card(l)); return g; } - const vnow = () => vg?.now(); // Discover is one market (#owner, 11-09): every plugin, whoever wrote // it (magpie's community, another author on npm, a repository its @@ -1013,7 +1011,7 @@ replaceKeeping(page, [head(), body]); drawBody(); page.scrollTop = scroll; - vnow(); + vg?.now(); } function drawBody() { @@ -1048,7 +1046,7 @@ import("./registry.js").then(() => pmRegistry(regBox, mine, askNPM), statusTErr); } replaceKeeping(body, out); - vnow(); + vg?.now(); if (agentsFor && body.querySelector(".pm-agents")) { // after the view is put back where the reader was, as showing it // does; the section then is the one drawn last (npm's answers draw @@ -1081,7 +1079,7 @@ } out.push(box); replaceKeeping(body, out); - vnow(); + vg?.now(); } // what a plugin is to the reader, and how one is written, under the list diff --git a/internal/gui/core_budget_test.go b/internal/gui/core_budget_test.go index 9b65bdacb..8e34366dd 100644 --- a/internal/gui/core_budget_test.go +++ b/internal/gui/core_budget_test.go @@ -18,7 +18,7 @@ import ( // `git log -L` of this file. const ( appScriptBudget = 1_086_267 // app.js: 1,080,614 at 8016205e3, with the 5,653 of room it had - coreScriptBudget = 1_265_544 // every core script at 8016205e3, the old measure 682 over its cap there (#5918); +367 for the model test on a chosen account (tmr11235), no page left to move it to; +151 for the provider menu's "Only on this device" item and its four translations; +458 for Settings › About's Report a problem row and its translations; +113 for withScheme, the one rule every typed address goes through (eachg0 on X), cut to the shortest form that keeps it whole; +10 for the kept whole's tooltip (Musikrv77852 on X), the past-cycle line reused for it, no page left to move it to; +1,112 for Codex's Open button and its Open Codex with menu (Yink88564391 on X), packed to the shortest form, no page left to move them to; +1,112 for Codex's Open button and its Open Codex with menu (Yink88564391 on X), packed to the shortest form, no page left to move them to + coreScriptBudget = 1_265_712 // every core script at 8016205e3, the old measure 682 over its cap there (#5918); +367 for the model test on a chosen account (tmr11235), no page left to move it to; +151 for the provider menu's "Only on this device" item and its four translations; +458 for Settings › About's Report a problem row and its translations; +113 for withScheme, the one rule every typed address goes through (eachg0 on X), cut to the shortest form that keeps it whole; +10 for the kept whole's tooltip (Musikrv77852 on X), the past-cycle line reused for it, no page left to move it to; +1,112 for Codex's Open button and its Open Codex with menu (Yink88564391 on X), packed to the shortest form, no page left to move them to; +168 for Discover's long lists drawn in part (the owner, 11-13), after the rest of its hook moved into plugingrid.js, imported when Plugins first draws ) // codeBytes is how many bytes of b are code: its blank lines, its lines