fix(webui): show latest button for hidden content (#6605)
* fix(webui): show latest button for hidden content * fix(webui): preserve latest navigation after focus scroll
This commit is contained in:
1 parent
c5f2ce5089
commit
f62dfe0ee8
7 files changed
+243
-23
No files matched your search
@@ -110,7 +110,9 @@ const parameters = new URLSearchParams(location.search);
|
||||
const railClient = new NanobotClient({ url: "ws://127.0.0.1:8765", reconnect: false });
|
||||
const railHistory: UIMessage[] = Array.from({ length: 5 }, (_, index) => [
|
||||
{ id: `u${1995 + index}`, role: "user" as const, content: `Question ${1995 + index}`, createdAt: index + 1 },
|
||||
{ id: `a${1995 + index}`, role: "assistant" as const, content: "A synthetic answer.\n\n".repeat(8), createdAt: index + 1 },
|
||||
{ id: `a${1995 + index}`, role: "assistant" as const, content: parameters.has("focus-links") && index === 4
|
||||
? Array.from({ length: 45 }, (_, i) => `[Reference ${i}](https://example.test/ref${i})`).join("\n")
|
||||
: "A synthetic answer.\n\n".repeat(8), createdAt: index + 1 },
|
||||
]).flat();
|
||||
function RailFixture() {
|
||||
const [messages, setMessages] = useState(parameters.has("real") ? [] : railHistory);
|
||||
@@ -148,7 +150,9 @@ function RailFixture() {
|
||||
<button onClick={() => setStreaming(true)} disabled={streaming}>{streaming ? "Streaming" : "Simulate stream"}</button>
|
||||
</div>}
|
||||
{parameters.has("workbench") ? <PaneWorkbench
|
||||
panes={[{ key: "rail", title: "Rail conversation" }]} activePaneKey="rail" layout="columns" showLayoutControl={false}
|
||||
panes={parameters.has("focus-links")
|
||||
? [{ key: "rail", title: "Rail conversation" }, { key: "other", title: "Other conversation" }]
|
||||
: [{ key: "rail", title: "Rail conversation" }]} activePaneKey="rail" layout="columns" showLayoutControl={false}
|
||||
onActivatePane={() => {}} onAddPane={() => {}} onLayoutChange={() => {}} onPaneOrderChange={() => {}}
|
||||
renderPane={(_pane, context) => <>
|
||||
{viewport(context.composerPortalTarget !== undefined, context.navigationFrame)}
|
||||
|
||||
@@ -1,4 +1,21 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { expect, test, type Page } from "@playwright/test";
|
||||
|
||||
async function recordBottomButtonFrames(page: Page) {
|
||||
await page.evaluate(() => {
|
||||
(window as unknown as { bottomButtonFrames: boolean[] }).bottomButtonFrames = [];
|
||||
let start = 0;
|
||||
const sample = () => {
|
||||
(window as unknown as { bottomButtonFrames: boolean[] }).bottomButtonFrames.push(
|
||||
Boolean(document.querySelector('button[aria-label="Scroll to bottom"]')),
|
||||
);
|
||||
if (performance.now() - start < 300) requestAnimationFrame(sample);
|
||||
};
|
||||
document.querySelector('button[aria-label="Scroll to bottom"]')!.addEventListener("click", () => {
|
||||
start = performance.now();
|
||||
requestAnimationFrame(sample);
|
||||
}, { once: true });
|
||||
});
|
||||
}
|
||||
|
||||
for (const { width, dark } of [{ width: 360, dark: false }, { width: 314, dark: true }, { width: 600, dark: false }]) {
|
||||
test.describe(`mobile transcript at ${width}px`, () => {
|
||||
@@ -68,3 +85,74 @@ test.describe("desktop transcript spacing", () => {
|
||||
expect(await scroller.evaluate(node => getComputedStyle(node).maskImage)).toContain("calc(100% - 36px)");
|
||||
});
|
||||
});
|
||||
|
||||
test("bottom button stays hidden throughout smooth navigation", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 360, height: 740 });
|
||||
await page.addInitScript(() => localStorage.setItem("nanobot.locale", "en"));
|
||||
await page.route("**/api/**", route => route.fulfill({ json: {} }));
|
||||
await page.goto("/browser/fixture.html?case=mobile-chat-layout&project");
|
||||
const scroller = page.locator(".thread-message-viewport");
|
||||
const button = page.getByRole("button", { name: "Scroll to bottom" });
|
||||
await expect.poll(() => scroller.evaluate(el => el.scrollHeight - el.clientHeight)).toBeGreaterThan(100);
|
||||
await expect(button).toBeHidden();
|
||||
const readableDistance = () => scroller.evaluate(el => {
|
||||
const rows = [...el.querySelectorAll<HTMLElement>(".thread-message-row")];
|
||||
const row = rows.reverse().find(item => item.getBoundingClientRect().height > 0)!;
|
||||
const gap = el.querySelector<HTMLElement>(".thread-message-end-gap")!;
|
||||
return row.getBoundingClientRect().bottom - (el.getBoundingClientRect().bottom - gap.getBoundingClientRect().height);
|
||||
});
|
||||
expect(await readableDistance()).toBeLessThanOrEqual(1);
|
||||
await scroller.hover();
|
||||
await page.mouse.wheel(0, -120);
|
||||
await expect(button).toBeVisible();
|
||||
expect(await readableDistance()).toBeGreaterThan(0);
|
||||
await expect(button).toBeVisible();
|
||||
await recordBottomButtonFrames(page);
|
||||
await button.click();
|
||||
await expect(button).toBeHidden();
|
||||
await expect.poll(() => scroller.evaluate(el => el.scrollHeight - el.clientHeight - el.scrollTop)).toBeLessThan(1);
|
||||
await page.waitForTimeout(320);
|
||||
const frames = await page.evaluate(() => (window as unknown as { bottomButtonFrames: boolean[] }).bottomButtonFrames);
|
||||
expect(frames.length).toBeGreaterThan(1);
|
||||
expect(frames).not.toContain(true);
|
||||
await expect(button).toBeHidden();
|
||||
});
|
||||
|
||||
test("bottom button stays hidden after focus scrolls a following thread", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 360, height: 740 });
|
||||
await page.addInitScript(() => localStorage.setItem("nanobot.locale", "en"));
|
||||
await page.route("**/api/sessions/**", route => route.fulfill({ json: { prompts: [] } }));
|
||||
await page.goto("/browser/fixture.html?case=rail&workbench=1&focus-links=1");
|
||||
const scroller = page.locator(".thread-message-viewport");
|
||||
const links = scroller.locator("a");
|
||||
const button = page.getByRole("button", { name: "Scroll to bottom" });
|
||||
await expect(links).toHaveCount(45);
|
||||
await expect.poll(() => scroller.evaluate(el => el.scrollHeight - el.clientHeight - el.scrollTop)).toBeLessThan(1);
|
||||
await expect(button).toBeHidden();
|
||||
|
||||
const index = await scroller.evaluate(el => {
|
||||
const top = el.getBoundingClientRect().top;
|
||||
return [...el.querySelectorAll("a")].findIndex(link => {
|
||||
const offset = link.getBoundingClientRect().top - top;
|
||||
return offset > 48 && offset < 100;
|
||||
});
|
||||
});
|
||||
expect(index).toBeGreaterThan(0);
|
||||
await links.nth(index).focus();
|
||||
const initialTop = await scroller.evaluate(el => el.scrollTop);
|
||||
await page.keyboard.press("Shift+Tab");
|
||||
await expect(links.nth(index - 1)).toBeFocused();
|
||||
await expect(button).toBeVisible();
|
||||
const distance = initialTop - await scroller.evaluate(el => el.scrollTop);
|
||||
expect(distance).toBeGreaterThan(0);
|
||||
expect(distance).toBeLessThan(48);
|
||||
|
||||
await recordBottomButtonFrames(page);
|
||||
await button.click();
|
||||
await expect.poll(() => scroller.evaluate(el => el.scrollHeight - el.clientHeight - el.scrollTop)).toBeLessThan(1);
|
||||
await page.waitForTimeout(320);
|
||||
const frames = await page.evaluate(() => (window as unknown as { bottomButtonFrames: boolean[] }).bottomButtonFrames);
|
||||
expect(frames.length).toBeGreaterThan(1);
|
||||
expect(frames).not.toContain(true);
|
||||
await expect(button).toBeHidden();
|
||||
});
|
||||
Reference in new issue
Block a user