web: keep mobile composition stable across keyboard and Back navigation

This commit is contained in:
2026-10-20 16:04:09 +01:00
parent 90cd43bdd7
commit 1d9cb80cdb
9 changed files with 193 additions and 10 deletions
+32 -1
View File
@@ -33,6 +33,9 @@ try {
window.addEventListener('unhandledrejection', (event) => window.__errors.push(String(event.reason)));
const Native = window.WebSocket;
window.WebSocket = class extends Native { constructor(...args) { super(...args); window.__socket = this; } };
// Controlled geometry, not a claim that desktop Chrome has an iOS keyboard.
const viewport = Object.assign(new EventTarget(), {height:844,width:390,scale:1,offsetTop:0});
Object.defineProperty(window, 'visualViewport', {value:viewport,configurable:true});
})()`);
await page.goto(`http://127.0.0.1:${port}/chat/${sessionId}`);
await page.waitForSelector("#chatTranscript .chat-reasoning-toggle");
@@ -61,8 +64,36 @@ try {
await page.evaluate("document.querySelector('.chat-reasoning-viewer .chat-tool-close').click()");
await emit({ message_id:"msg_answer",kind:"step",step:{status:"ended"} });
await eventually(() => page.evaluate("!document.querySelector('#chatStop') && !document.querySelector('.chat-activity-spinner')"));
await page.fill("#chatInput", "Keep this draft and caret");
await page.evaluate(`(() => {
const input = document.querySelector('#chatInput');
input.setSelectionRange(5, 9);
window.__composer = input;
window.visualViewport.height = 430;
window.visualViewport.dispatchEvent(new Event('resize'));
})()`);
await eventually(() => page.evaluate("document.documentElement.classList.contains('keyboard-open')"));
assert.equal(await page.evaluate("document.querySelector('#chatInput') === window.__composer && document.activeElement === window.__composer"), true);
assert.equal(await page.evaluate("document.querySelector('#chatInput').selectionStart"), 5);
assert.equal(await page.evaluate("getComputedStyle(document.querySelector('#chatInput')).fontSize"), "16px");
assert.equal(await page.evaluate("document.querySelector('#chatComposer').getBoundingClientRect().bottom <= 431"), true);
if (process.env.PIPELINES_CAPTURE_DIR) {
await page.screenshot(join(process.env.PIPELINES_CAPTURE_DIR, "keyboard-composer-visible.png"));
}
await page.evaluate("window.visualViewport.height = 844; window.visualViewport.dispatchEvent(new Event('resize'))");
await eventually(() => page.evaluate("!document.documentElement.classList.contains('keyboard-open')"));
await page.click(".chat-back");
await page.waitForSelector("#chatRows");
await page.evaluate("document.querySelector('#chatRows').scrollTop = 280");
const scroll = await page.evaluate("document.querySelector('#chatRows').scrollTop");
assert.ok(scroll > 0);
await page.evaluate("document.querySelector('#chatRows .chat-session-button').click()");
await page.waitForSelector(".chat-back");
await page.click(".chat-back");
await page.waitForSelector("#chatRows");
assert.equal(await page.evaluate("document.querySelector('#chatRows').scrollTop"), scroll);
assert.deepEqual(await page.evaluate("window.__errors"), []);
console.log("Delayed model dialog loads, filters and traps focus; intermediate step retains Stop until terminal turn.");
console.log("Model dialog focus, intermediate/terminal steps, keyboard composer identity/caret and Back scroll restoration passed.");
} finally {
await browser?.close();
serve.kill("SIGTERM");
+18
View File
@@ -0,0 +1,18 @@
import { test } from "node:test";
import assert from "node:assert/strict";
import { mobileViewportState } from "../src/mobileViewport.js";
const base = { width: 390, height: 844, baselineHeight: 844, layoutHeight: 844, editing: true };
test("keyboard geometry follows the visual viewport without assuming dvh resizes", () => {
assert.deepEqual(mobileViewportState({ ...base, height: 430, offsetTop: 20 }), { keyboard: true, height: 430, top: 20 });
// Chromium's resizes-content can shrink both; the pre-focus baseline survives.
assert.equal(mobileViewportState({ ...base, height: 430, layoutHeight: 430 }).keyboard, true);
assert.equal(mobileViewportState({ ...base, height: 430, editing: false, wasOpen: true }).keyboard, true);
assert.equal(mobileViewportState(base).keyboard, false);
});
test("toolbar motion, desktop layouts and pinch zoom never trigger keyboard layout", () => {
assert.equal(mobileViewportState({ ...base, height: 780 }).keyboard, false);
assert.equal(mobileViewportState({ ...base, height: 430, scale: 2 }).keyboard, false);
assert.equal(mobileViewportState({ ...base, height: 430, width: 900 }).keyboard, false);
assert.equal(mobileViewportState({ ...base, height: 430, editing: false }).keyboard, false);
});