plugins: a README read once shows at once when its page opens again

The owner (10-30): closing a plugin's page and opening it again played
the loading bird over a README already read, and memory for them must
stay bounded, and a README changed since must not stay old.

detail() keeps each page read in a Map, the last 20 opened only: a new
read goes to the end and the oldest is dropped past 20. Opening a page
that is there draws its README and date at once, with no loader and no
bird, and reads the page again behind it; a README that changed takes
the old one's place, and a failed read keeps the one shown. A page never
read still loads under the bird, waiting for its three landings.

The core's scripts grow 677 bytes; coreScriptBudget is raised to the
exact size, 1,537,034, with no room added.

Run (mote, at 55299ee30 + this change):
- node --check plugins.js.
- node --test plugin-readme-bird, skeleton-bird, plugin-page,
  plugin-market, plugin-progressive, plugin-github-wait, plugin-local,
  plugin-release, tray-bird: 82 pass, 0 fail, chromium and webkit,
  the new test "a README read once shows at once when its page opens
  again, and a newer one takes its place" among them.
- go test -run Budget ./internal/gui/: ok. gofmt -l: clean.

Broken by hand:
- main's plugins.js under the new test: red in both engines (the
  reopened page shows the bird and no README).
- without the line that puts a changed README in: red, waiting for
  the newer README's "Paragraph 4.".

Not run: the full GUI suite and go test ./... (this touches plugins.js'
detail() and one test file only); the 20-page cap has no test of its
own, it is read from the code.
This commit is contained in:
yetone
2026-10-30 04:17:35 +08:00
parent 55299ee304
commit 1027db4081
3 changed files with 49 additions and 9 deletions
+18 -4
View File
@@ -1615,6 +1615,12 @@
return box;
}
// a README read once shows at once when its page opens again, birdless,
// and is read again quietly (the owner, 10-30). The last 20 opened only,
// a Map in the order they were: the oldest goes first
const pages = new Map();
const keep = (k, p) => { pages.delete(k); pages.set(k, p); if (pages.size > 20) pages.delete(pages.keys().next().value); };
// the plugin's page: what it is, what npm says of it, and its README
async function detail(l) {
// a folder plugin: what it is comes from the folder, not from npm; a
@@ -1679,7 +1685,13 @@
}
if (l.replaces) main.append(el("p", "pm-note", t("magpie's own sign-in to this subscription is deprecated: this plugin takes its place, and accounts signed in there move to it.")));
const readme = el("div", "pm-readme");
readme.append(bounceLoader());
const had = pages.get(l.package);
const day = (p) => {
const at = l.github && !entryOf(l.package) ? l.github.pushed : p.updated;
upd.textContent = at && !at.startsWith("0001") ? new Date(at).toLocaleDateString(intlLang(), { year: "numeric", month: "short", day: "numeric" }) : "—";
};
if (had) day(had);
readme.append(had ? markdown(had.readme || t("No README")) : bounceLoader());
main.append(readme);
ed.append(main);
const bar = el("div", "bar");
@@ -1715,10 +1727,12 @@
};
try {
const p = await api("plugins/page?name=" + encodeURIComponent(l.package));
const at = l.github && !entryOf(l.package) ? l.github.pushed : p.updated;
upd.textContent = at && !at.startsWith("0001") ? new Date(at).toLocaleDateString(intlLang(), { year: "numeric", month: "short", day: "numeric" }) : "—";
fill(markdown(p.readme || t("No README")));
keep(l.package, p);
day(p);
if (!had) fill(markdown(p.readme || t("No README")));
else if (p.readme !== had.readme) readme.replaceChildren(markdown(p.readme || t("No README")));
} catch (e) {
if (had) return;
upd.textContent = "—";
fill(el("p", "pm-note", t(l.github && isGit(l.package) && !entryOf(l.package) ? "GitHub didn't answer: {error}" : local ? "Couldn't read the folder's README: {error}" : "npm didn't answer: {error}", { error: e.message })));
}
File diff suppressed because one or more lines are too long
+30 -4
View File
@@ -5,7 +5,9 @@
// on three lines, however soon the README came (the owner, 10-30). With
// reduced motion the lines stay straight and the bird sits still on the
// first. With Settings' Loading bird off the lines stay straight and no
// bird comes.
// bird comes. A README read once shows at once when its page opens again,
// with no bird, and is read again behind it: a README changed since takes
// its place (the owner, 10-30).
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const path = require("node:path");
@@ -55,8 +57,10 @@ async function open(browser, reduced, noBird) {
page.setDefaultTimeout(5000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
let release;
const next = new Promise((r) => { release = r; });
// each read of the page waits for the next release
let release, next;
const pend = () => { next = new Promise((r) => { release = r; }); };
pend();
await page.route("**/*", server(() => next, noBird));
await page.goto("http://magpie.test/?view=plugins");
await page.locator("#view-plugins .pm-find input").fill("copilot");
@@ -65,7 +69,7 @@ async function open(browser, reduced, noBird) {
await page.waitForLoadState("networkidle");
await card.locator(".pm-sum").click();
await page.locator("#modal .pm-bounce").waitFor();
return { page, errors, release };
return { page, errors, release: (v) => release(v), pend };
}
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
@@ -145,6 +149,28 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.deepEqual(errors, []);
});
test(engine + ": a README read once shows at once when its page opens again, and a newer one takes its place", async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const { page, errors, release, pend } = await open(browser, false);
release({ readme: readme(3), updated: "2026-09-01T00:00:00Z" });
await page.locator("#modal .pm-md p", { hasText: "Paragraph 2." }).waitFor();
await page.waitForFunction(() => !document.querySelector("#modal .pm-bounce"), null, { timeout: 2000 });
await page.locator("#modal .bar button.text", { hasText: "Close" }).click();
await page.waitForFunction(() => !document.querySelector("#modal .pm-md"));
// open again: the read waits, and the README is there already
pend();
await page.locator('.pm-card[data-pkg="opencode-copilot-auth"] .pm-sum').click();
await page.locator("#modal .pm-md p", { hasText: "Paragraph 2." }).waitFor({ timeout: 500 });
assert.equal(await page.locator("#modal .pm-bounce, .sk-bird").count(), 0, "no loader, no bird");
// the README changed since: the new one takes its place, still birdless
release({ readme: readme(5), updated: "2026-10-29T00:00:00Z" });
await page.locator("#modal .pm-md p", { hasText: "Paragraph 4." }).waitFor();
assert.equal(await page.locator("#modal .pm-md").count(), 1, "one README, the new one");
assert.equal(await page.locator("#modal .pm-bounce, .sk-bird").count(), 0, "no loader, no bird");
assert.deepEqual(errors, []);
});
test(engine + ": with reduced motion the lines stay straight and the bird sits still", async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());