gui: a Settings option pressed through two redraws clicks its newest self (#3922)

Browser access draws twice per renderSettings: once at once, and once
more when its /api/web-page answer comes. When that answer landed
between the release and the click segs' pointerup sets off, the option
the release found was gone by the click and nothing was sent, which
segs-press-redraw's sweep saw on Network's web-page list. The click now
goes to the control's newest self (same segsWho, same option), found
again whether or not a draw came since; dragged off or gone still picks
nothing.

From Coffemon's patch on #3922 (JoeyWu-tech, fix/3922-segs-newest,
c1b5575af and e8c831736): the test's new redrawn-twice case, reveal()
waiting for each wheel's scroll to land, and the README entry, taken as
is. The app.js change is his, shorter: his kept b when still there and
looked up the newest self otherwise (+298 bytes); the lookup finds b
itself when b is still there, so it is used alone (+129 bytes). Main's
core had 18 bytes of room left when this landed; TestCoreScriptBudget
is green and no budget is raised.

What was run (mote, Playwright 1.62.0, Chromium and WebKit, en, zh, ja,
de, 900 and 440px):
- The new test on main's app.js: 22 of 42 red, both engines.
- With this change: 42 of 42.
- Broken by hand (the newest self's option taken as [0], not p.i):
  Chromium 17 red.
- go test -run TestCoreScriptBudget ./internal/gui: ok.

Not tried: the real app's webview, or a loaded Mac.

Co-authored-by: JoeyWu-tech <joey110551567@gmail.com>
This commit is contained in:
yetone
2026-10-28 16:58:22 +08:00
co-authored by JoeyWu-tech
parent ae03279458
commit 761e0e0105
3 changed files with 45 additions and 6 deletions
+2 -1
View File
@@ -6837,7 +6837,8 @@ addEventListener("pointerup", (e) => {
addEventListener("click", seen, true);
setTimeout(() => {
removeEventListener("click", seen, true);
if (!clicked && b.isConnected) b.click();
// its newest self: b, or what a draw since put there (#3922)
if (!clicked) [...document.querySelectorAll(".segs")].find((x) => segsWho(x) === p.who)?.querySelectorAll(":scope > .opt")[p.i]?.click();
});
}, true);
+4 -1
View File
@@ -874,7 +874,10 @@ node --test --test-concurrency=1 internal/gui/tests/settings-sections.test.cjs i
(`renderSettings()`, as a save's answer does) while the button is held and
lets go on the same spot: Lightweight mode → On is posted once and shown on.
Dragged off to the other option, or to the same option of another control,
nothing is posted, and a plain click is posted once, not twice. It then
nothing is posted, and a plain click is posted once, not twice. Drawn
again once more after it is let go and before the click that sets off,
as Browser access is when the answer to its state comes then (#3922),
On is posted once. It then
presses every option control on every Settings tab (49 in English, the
warm-up, check-in, sync and local network ones included) the same way and
checks that the control drawn in its place is clicked once on the same
+39 -4
View File
@@ -6,8 +6,11 @@
// and nothing was saved. Pressed, redrawn and let go on the same option,
// Lightweight mode → On is saved once; dragged off to another option, or to
// the same option of another control, nothing is; a click with no redraw
// is saved once. Every segs control on every Settings tab is pressed the
// same way and its new self clicked once. Chromium and WebKit, in English,
// is saved once. Pressed, redrawn, let go and redrawn again before its
// click comes, as a draw that asks for its state draws once more with the
// answer (Browser access, #3922), the newest On is saved once. Every segs
// control on every Settings tab is pressed the same way and its new self
// clicked once. Chromium and WebKit, in English,
// Chinese, Japanese and German, in a wide and a narrow window, the API faked.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
@@ -65,18 +68,35 @@ async function open(engine, lang, width, tab, posted, st, t, touch = false) {
const settle = (page) => page.evaluate(() => new Promise((ok) => setTimeout(ok, 80)));
// brought out from under the header and the foot by the reader's wheel, as
// code's scrolls are put back, till the pointer at its middle is on it
// code's scrolls are put back, till the pointer at its middle is on it.
// Each wheel's scroll lands before the option is looked at again: WebKit's
// glides on for some 200ms (a wheel of 150px is at 9, 111, 142, 149 and
// 150 by its frames), and a box read on the way was pressed where the
// option had been, off it (#3922)
async function reveal(page, loc) {
for (let i = 0; i < 40; i++) {
const b = await loc.boundingBox();
const h = page.viewportSize().height;
if (b && await loc.evaluate((o, [x, y]) => o.contains(document.elementFromPoint(x, y)), mid(b))) return b;
await page.mouse.move(page.viewportSize().width / 2, h / 2);
const was = await page.evaluate(() => document.getElementById("view-settings").scrollTop);
await page.mouse.wheel(0, b && b.y < h / 2 ? -150 : 150);
await page.waitForTimeout(60);
await landed(page, was);
}
throw new Error("could not bring the option into view");
}
// landed: Settings' view moved from where it was and then held still for
// three frames in turn, or didn't move in a second (it is at its end)
const landed = (page, was) => page.evaluate((was) => new Promise((ok) => {
const v = document.getElementById("view-settings"), t0 = performance.now();
let last = v.scrollTop, still = 0;
const frame = () => {
still = v.scrollTop === last ? still + 1 : 0;
last = v.scrollTop;
if (last !== was ? still >= 3 : performance.now() - t0 > 1000) ok(); else requestAnimationFrame(frame);
};
requestAnimationFrame(frame);
}), was);
const mid = (b) => [b.x + b.width / 2, b.y + b.height / 2];
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
@@ -147,6 +167,21 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.waitForTimeout(300);
assert.deepEqual(saves(), [true, false], `posted ${JSON.stringify(posted)}`);
assert.equal(await on(), w.off);
// pressed, redrawn, let go, and redrawn again before the click it
// set off comes, as Browser access is when its state's answer lands
// then (#3922): the newest On is clicked, once
await page.mouse.move(...mid(await reveal(page, opt("lightweightSegs", w.on))));
await page.mouse.down();
await page.evaluate(() => {
renderSettings();
addEventListener("pointerup", () => renderSettings(), { capture: true, once: true });
});
await page.mouse.up();
for (let i = 0; i < 40 && saves().length < 3; i++) await page.waitForTimeout(50);
await page.waitForTimeout(300);
assert.deepEqual(saves(), [true, false, true], `redrawn twice, posted ${JSON.stringify(posted)}`);
assert.equal(await on(), w.on);
assert.deepEqual(errors, []);
});