Public: anyone can read this; the crew can change it.

A pull's page fits a 390 px phone: its title, branch names and conversation wrap instead of scrolling sideways #9342

Parked opened this
Closed without merging

mason/forge:mason/9327-a-pull-s-page-fits-a-390-px-phone-its-ti → main 3 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
5 files changed +122 −3
docs/design/areas/pull.md +2
@@ -9,3 +9,5 @@ At rest: the state is a dot (`.dot`, `role=img`, one `aria-label`, no `title`),
99 Rare actions (Hold, Take it back) sit in a `<details id="more" class="mt mb">`, the same disclosure Hold always used. Their palette rows link to `?more=1#hold` / `?more=1#take-back`: the server renders the details open for `?more`, so the target is visible with no script. Every other action is a palette row too (`pullActions`, "This pull request"). No new class.
1010
1111 The terminal's pull screen (`src/tui/screens/pull.ts`) draws its own rows and shares no markup with this page; it needs no change.
12
13 On a 390 px phone the page does not scroll sideways (#9327): the title (`.page-head h1`) and every `.mono` (branch names) wrap with `overflow-wrap: anywhere`, comments already do through `.prose`. The diff scrolls inside its own box. No new class; `test/pull-phone-fit.test.ts` holds it.
src/web/style/base.ts +1
@@ -57,6 +57,7 @@ body {
5757 a { color: inherit; text-decoration: none; transition: color 120ms var(--ease); }
5858 a:hover { color: var(--accent); }
5959 code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
60 .mono { overflow-wrap: anywhere; }
6061
6162 h1 { font-size: 20px; font-weight: 620; letter-spacing: -0.02em; line-height: 1.25; text-wrap: balance; }
6263 h2 { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.3; text-wrap: balance; }
src/web/style/components.ts +2 −2
@@ -814,7 +814,7 @@ details[open] > summary.row > .row-lead { transform: rotate(90deg); }
814814 display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
815815 margin: 20px 0 14px;
816816 }
817 .page-head h1 { min-width: 0; }
817 .page-head h1 { min-width: 0; overflow-wrap: anywhere; }
818818 .page-head > .page-head-sub { flex-basis: 100%; margin-top: -4px; }
819819
820820 /* ---- breadcrumbs ---- */
@@ -847,7 +847,7 @@ details[open] > summary.row > .row-lead { transform: rotate(90deg); }
847847 content: ""; position: absolute; left: 13px; top: 8px; bottom: 8px;
848848 width: 2px; background: var(--border);
849849 }
850 .tl-item { position: relative; padding-left: 36px; }
850 .tl-item { position: relative; padding-left: 36px; min-width: 0; }
851851 .tl-item .tl-dot {
852852 position: absolute; left: 4px; top: 6px;
853853 display: inline-flex; align-items: center; justify-content: center;
src/web/style/content.ts +1 −1
@@ -330,7 +330,7 @@ form.inline { display: inline; margin-left: auto; }
330330 .imgview-pane.is-actual .imgview-img { max-width: none; cursor: zoom-out; }
331331
332332 /* ---- prose (markdown) ---- */
333 .prose { padding: 16px 20px; font-size: 15px; line-height: 1.65; overflow-wrap: break-word; }
333 .prose { padding: 16px 20px; font-size: 15px; line-height: 1.65; overflow-wrap: anywhere; }
334334 .prose > * { max-width: var(--measure); }
335335 .prose h1, .prose h2, .prose h3, .prose h4 { margin: 24px 0 8px; }
336336 .prose h1 { font-size: 20px; }
test/pull-phone-fit.test.ts added +116
@@ -0,0 +1,116 @@
1 /**
2 * A pull's page fits a 390 px phone (#9327): the preview seed's pull, given a
3 * long title, a 200-character branch name and a comment holding a 300-character
4 * unbroken word, ships no fixed width over 390 px, wraps its long text, and
5 * (where a Chromium starts) does not scroll sideways.
6 */
7 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
8 import { createHmac } from "node:crypto";
9 import { mkdtemp, rm } from "node:fs/promises";
10 import { tmpdir } from "node:os";
11 import { join } from "node:path";
12 import { createApp, type App } from "../src/app.ts";
13 import { serve, type Servers } from "../src/http/server.ts";
14 import { addComment } from "../src/core/issues.ts";
15 import { createSession } from "../src/core/sessions.ts";
16 import { findChromium } from "../src/looks/capture.ts";
17 import { PREVIEW_PULL_PAGE } from "../src/spawn/preview-looks.ts";
18 import { previewAdmin, seedPreview } from "../src/spawn/preview-seed.ts";
19 import { base as elements, utilities as base } from "../src/web/style/base.ts";
20 import { components } from "../src/web/style/components.ts";
21 import { content } from "../src/web/style/content.ts";
22 import { chromiumRuns, evaluateLoaded } from "./helpers/chrome.ts";
23
24 const KEY = "pull-phone-fit-key";
25 const WORD = "w".repeat(300);
26 const BRANCH = `feature/${"b".repeat(192)}`;
27 const TITLE = `Make every long and winding pull title wrap ${"t".repeat(120)} and many words after it`;
28 let dir: string;
29 let app: App;
30 let servers: Servers;
31 let page: string;
32 let files: string;
33
34 beforeAll(async () => {
35 dir = await mkdtemp(join(tmpdir(), "forge-pull-fit-"));
36 app = createApp({ dataDir: dir, port: 0, previewIdentityKey: KEY });
37 const seeded = await seedPreview(app, { FORGE_APP_ENV: "preview" });
38 if (!seeded.ok) throw new Error(seeded.error);
39 const admin = previewAdmin(app)!;
40 const row = app.db.query("SELECT issue_id AS id FROM pull ORDER BY issue_id").all() as { id: string }[];
41 const number = Number(PREVIEW_PULL_PAGE.split("/").pop());
42 const issue = app.db.query("SELECT id FROM issue WHERE number = ?1 AND id IN (SELECT issue_id FROM pull)").get(number) as { id: string };
43 expect(row.length).toBeGreaterThan(0);
44 app.db.query("UPDATE issue SET title = ?1 WHERE id = ?2").run(TITLE, issue.id);
45 app.db.query("UPDATE pull SET head_branch = ?1 WHERE issue_id = ?2").run(BRANCH, issue.id);
46 for (let i = 0; i < 12; i++) addComment(app.db, { issueId: issue.id, authorId: admin.id, body: `Row ${String(i)} ${WORD} https://example.com/${WORD}` });
47 servers = await serve(app);
48 const said = `u1|trevato|admin|${Date.now() + 60_000}`;
49 const headers = { "x-forge-identity": said, "x-forge-signature": createHmac("sha256", KEY).update(said).digest("base64url") };
50 page = await (await fetch(`${servers.url}${PREVIEW_PULL_PAGE}`, { headers })).text();
51 files = await (await fetch(`${servers.url}${PREVIEW_PULL_PAGE}/files`, { headers })).text();
52 }, 30_000);
53 afterAll(async () => {
54 servers.stop();
55 app.close();
56 await rm(dir, { recursive: true, force: true });
57 });
58
59 describe("a pull's conversation page at 390 px", () => {
60 test("the seeded long content is on the page", () => {
61 expect(page).toContain(TITLE);
62 expect(page).toContain(WORD);
63 // The branch is drawn where the pull says where it came from: the Files step.
64 expect(files).toContain(BRANCH);
65 });
66
67 test("no inline width and no rule the page ships fixes a width over 390 px", () => {
68 for (const m of page.matchAll(/\swidth=["']?(\d+)/gi)) expect(Number(m[1])).toBeLessThanOrEqual(390);
69 expect(page).not.toMatch(/style="[^"]*(?:^|[;\s])min-width\s*:/i);
70 for (const m of page.matchAll(/style="([^"]*)"/g)) {
71 for (const w of m[1]!.matchAll(/(?<![-\w])(?:min-)?width\s*:\s*(-?[\d.]+)(px|rem|em|ch)\b/g)) {
72 expect(Number(w[1]) * (w[2] === "px" ? 1 : w[2] === "ch" ? 8 : 16)).toBeLessThanOrEqual(390);
73 }
74 }
75 const over: string[] = [];
76 for (const css of [base, components, content, ...(page.match(/<style[^>]*>[\s\S]*?<\/style>/g) ?? []), ...(files.match(/<style[^>]*>[\s\S]*?<\/style>/g) ?? [])]) {
77 for (const m of css.matchAll(/(?<![-\w(])(?:min-)?width\s*:\s*(-?[\d.]+)(px|rem|em|ch)\b/g)) {
78 if (Number(m[1]) * (m[2] === "px" ? 1 : m[2] === "ch" ? 8 : 16) > 390) over.push(m[0]);
79 }
80 }
81 expect(over).toEqual([]);
82 });
83
84 test("the long-text containers wrap anywhere", () => {
85 expect(components).toMatch(/\.page-head h1[^{]*\{[^}]*overflow-wrap:\s*(anywhere|break-word)/);
86 expect(elements).toMatch(/\.mono[^{]*\{[^}]*overflow-wrap:\s*(anywhere|break-word)/);
87 expect(content).toMatch(/\.prose\s*\{[^}]*overflow-wrap:\s*(anywhere|break-word)/);
88 });
89 });
90
91 const found = findChromium();
92 const chromium = found !== undefined && chromiumRuns(found) ? found : undefined;
93 if (chromium === undefined) console.log("SKIPPING: no chromium that starts here, so the pull's phone look is not measured");
94
95 describe.skipIf(chromium === undefined)("a pull's conversation page, measured", () => {
96 const measure = `(() => {
97 const vw = document.documentElement.clientWidth;
98 const overflowing = [...document.querySelectorAll("main *, h1")].filter((el) => el.getBoundingClientRect().right > vw + 1).slice(0, 8).map((el) => el.tagName.toLowerCase() + "." + String(el.className));
99 return JSON.stringify({ scrollWidth: document.documentElement.scrollWidth, viewportWidth: vw, overflowing });
100 })()`;
101 const look = async (width: number, height: number) => {
102 const cookies = [{ name: "forge_session", value: createSession(app.db, previewAdmin(app)!.id).token }];
103 const m = JSON.parse(await evaluateLoaded(chromium!, `${servers.url}${PREVIEW_PULL_PAGE}`, { width, height }, cookies, measure)) as { scrollWidth: number; viewportWidth: number; overflowing: string[] };
104 console.log(`pull look ${width}x${height}: ${JSON.stringify(m)}`);
105 return m;
106 };
107 test("phone, 390x844: no sideways scroll", async () => {
108 const m = await look(390, 844);
109 expect(m.overflowing).toEqual([]);
110 expect(m.scrollWidth).toBeLessThanOrEqual(m.viewportWidth);
111 }, 30_000);
112 test("desk, 1280x800: no sideways scroll", async () => {
113 const m = await look(1280, 800);
114 expect(m.scrollWidth).toBeLessThanOrEqual(m.viewportWidth);
115 }, 30_000);
116 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs