Public: anyone can read this; the crew can change it.
A repository's head page fits a 390 px phone: its name, description, branch picker and actions wrap, nothing scrolls sideways #9387
mason/forge:mason/9379-a-repository-s-head-page-fits-a-390-px-p → main 3 commits fork
4 files
changed +122
−4
docs/design/areas/code.md +2
| @@ -4,3 +4,5 @@ | ||
| 4 | 4 | - `.pdf-view`, `.pdf-links`, `.pdf-frame`, `.pdf-fallback` — a PDF on its blob page (`render/pdf.ts`): one card holding the browser's viewer in a full-width frame 80vh tall (480px at least), under an always-visible Open · Download line (the frame is 60vh on a phone so a thumb can scroll past it), with a padded link line inside for a browser that cannot draw it. |
| 5 | 5 | |
| 6 | 6 | `.ex-more` also closes a windowed directory page and the side Files column: the "Show all N entries" link to `?all=1`. |
| 7 | ||
| 8 | - Fit at 390 px (#9379): no new class. `[data-repo-head]` (an attribute on the repository head page's wrapper) breaks long words anywhere; the tree's `.row-title` wraps instead of ellipsizing, the branch picker may shrink to the column, and a README's table scrolls inside its own box. |
src/web/pages/repo.ts +4 −4
| @@ -1269,7 +1269,7 @@ async function codeHome(ctx: Ctx, repo: Repo): Promise<Response> { | ||
| 1269 | 1269 | |
| 1270 | 1270 | if (refs.branches.length === 0) { |
| 1271 | 1271 | const emptyRendering = performance.now(); |
| 1272 | const body = html`${scopeHeader(ctx, scope, "code")}${archivedLine(ctx, repo)}${noApp} | |
| 1272 | const body = html`<div data-repo-head>${scopeHeader(ctx, scope, "code")}${archivedLine(ctx, repo)}${noApp} | |
| 1273 | 1273 | <div class="mt"> |
| 1274 | 1274 | ${empty({ |
| 1275 | 1275 | icon: "repo", |
| @@ -1288,7 +1288,7 @@ async function codeHome(ctx: Ctx, repo: Repo): Promise<Response> { | ||
| 1288 | 1288 | <h2>Get started</h2>`, |
| 1289 | 1289 | }, |
| 1290 | 1290 | )} |
| 1291 | </div>`; | |
| 1291 | </div></div>`; | |
| 1292 | 1292 | const emptyResponse = page({ |
| 1293 | 1293 | ctx, |
| 1294 | 1294 | title: repo.name, |
| @@ -1339,7 +1339,7 @@ async function codeHome(ctx: Ctx, repo: Repo): Promise<Response> { | ||
| 1339 | 1339 | ? null |
| 1340 | 1340 | : upstreamOffer(ctx.app, ctx.auth.user, repo, parent, drift?.ahead); |
| 1341 | 1341 | const rendering = performance.now(); |
| 1342 | const body = html`${scopeHeader(ctx, scope, "code", { | |
| 1342 | const body = html`<div data-repo-head>${scopeHeader(ctx, scope, "code", { | |
| 1343 | 1343 | branchCount: refs.branches.length, |
| 1344 | 1344 | })}${timePhase(ctx.request, "behind", () => behindLine(ctx, repo))}${originAheadLine(ctx, repo)}${archivedLine(ctx, repo)}${noApp} |
| 1345 | 1345 | ${offerUpstream(repo, parent, offer)} |
| @@ -1360,7 +1360,7 @@ async function codeHome(ctx: Ctx, repo: Repo): Promise<Response> { | ||
| 1360 | 1360 | readme, |
| 1361 | 1361 | rail: aboutCard(ctx, repo, refs, drift), |
| 1362 | 1362 | })} |
| 1363 | ${codeMount(scope, ref)} ${finderDialog()} ${liveMount({ repo: scope.base })}`; | |
| 1363 | ${codeMount(scope, ref)} ${finderDialog()} ${liveMount({ repo: scope.base })}</div>`; | |
| 1364 | 1364 | const response = page({ |
| 1365 | 1365 | ctx, |
| 1366 | 1366 | title: repo.name, |
src/web/style/content.ts +7
| @@ -146,6 +146,13 @@ a.origin-chip:hover { border-color: var(--border-strong); color: var(--fg); } | ||
| 146 | 146 | text-align: center; user-select: all; word-break: break-all; |
| 147 | 147 | } |
| 148 | 148 | [data-apps], [data-bet-card], [data-milestone] { overflow-wrap: anywhere; } |
| 149 | /* A repository's head page (#9379): the owner's words (name, description, branch, file names) break anywhere; the picker and the tree's rows wrap in the column; a README's table scrolls inside its own box. */ | |
| 150 | [data-repo-head] { overflow-wrap: anywhere; } | |
| 151 | [data-repo-head] .repo-title > span { min-width: 0; } | |
| 152 | [data-repo-head] .bar > .menu { min-width: 0; max-width: 100%; } | |
| 153 | [data-repo-head] .bar > .menu > summary { max-width: 100%; } | |
| 154 | [data-repo-head] .row-title { white-space: normal; overflow: visible; } | |
| 155 | [data-repo-head] .prose table { display: block; max-width: 100%; overflow-x: auto; } | |
| 149 | 156 | [data-bet-card] h2, [data-bet-card] ul, [data-bet-card] p { margin-block: 8px; } |
| 150 | 157 | [data-bet-card] ul { padding-inline-start: 16px; } |
| 151 | 158 | [data-bet-card] { max-height: 80vh; overflow-x: hidden; overflow-y: auto; } |
test/repo-head-fit.test.ts added +109
| @@ -0,0 +1,109 @@ | ||
| 1 | /** | |
| 2 | * A repository's head page fits a 390 px phone (#9379): seeded with a | |
| 3 | * 250-character unbroken word where the page shows a branch, a file name, a | |
| 4 | * description and a README, and with many rows, the page fixes no width over | |
| 5 | * 390 px, its long-text container wraps anywhere, and a README's code scrolls | |
| 6 | * inside its own box. | |
| 7 | */ | |
| 8 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 9 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 10 | import { tmpdir } from "node:os"; | |
| 11 | import { join } from "node:path"; | |
| 12 | import { createBranch } from "../src/actions/branches.ts"; | |
| 13 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 14 | import { createApp, type App } from "../src/app.ts"; | |
| 15 | import { createSession } from "../src/core/sessions.ts"; | |
| 16 | import { createUser } from "../src/core/users.ts"; | |
| 17 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 18 | import { utilities as base } from "../src/web/style/base.ts"; | |
| 19 | import { components } from "../src/web/style/components.ts"; | |
| 20 | import { content } from "../src/web/style/content.ts"; | |
| 21 | import { findChromium } from "../src/looks/capture.ts"; | |
| 22 | import { chromiumRuns, evaluateLoaded } from "./helpers/chrome.ts"; | |
| 23 | ||
| 24 | const WORD = "W".repeat(250); | |
| 25 | let dir: string; | |
| 26 | let app: App; | |
| 27 | let servers: Servers; | |
| 28 | let page: string; | |
| 29 | let session: { name: string; value: string }; | |
| 30 | ||
| 31 | const must = <T>(r: { ok: true; value: T } | { ok: false; error: unknown }): T => { | |
| 32 | if (!r.ok) throw new Error(JSON.stringify(r.error)); | |
| 33 | return r.value; | |
| 34 | }; | |
| 35 | ||
| 36 | beforeAll(async () => { | |
| 37 | dir = await mkdtemp(join(tmpdir(), "forge-head-fit-")); | |
| 38 | app = createApp({ dataDir: dir, port: 0 }); | |
| 39 | servers = await serve(app); | |
| 40 | const u = must(await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true })); | |
| 41 | const repo = must(await createRepo(app, u, { name: "fit", visibility: "public", description: `A description with ${WORD} in it` })); | |
| 42 | const files = [ | |
| 43 | { path: "README.md", content: `# ${WORD}\n\n${WORD}\n\n\`\`\`\n${"code ".repeat(80)}${WORD}\n\`\`\`\n\n| a | b |\n|---|---|\n| ${WORD} | ${WORD} |\n` }, | |
| 44 | { path: `${WORD.slice(0, 120)}.txt`, content: "x" }, | |
| 45 | ...Array.from({ length: 40 }, (_, n) => ({ path: `file-${n}-${WORD.slice(0, 100)}.md`, content: "x" })), | |
| 46 | ]; | |
| 47 | must(await commitToBranch(app, u, repo, { message: `A message ${WORD}`, files })); | |
| 48 | must(await createBranch(app, u, repo, { name: `feature/${"b".repeat(200)}` })); | |
| 49 | const token = createSession(app.db, u.id).token; | |
| 50 | session = { name: "forge_session", value: token }; | |
| 51 | const cookie = `forge_session=${token}; forge_mode=dev`; | |
| 52 | page = await (await fetch(`${servers.url}/alice/fit`, { headers: { cookie } })).text(); | |
| 53 | }, 60_000); | |
| 54 | afterAll(async () => { | |
| 55 | servers.stop(); | |
| 56 | app.close(); | |
| 57 | await rm(dir, { recursive: true, force: true }); | |
| 58 | }); | |
| 59 | ||
| 60 | describe("a repository's head page at 390 px", () => { | |
| 61 | test("the long content is on the page, in many rows", () => { | |
| 62 | expect(page).toContain(WORD.slice(0, 120)); | |
| 63 | expect(page).toContain("data-repo-head"); | |
| 64 | expect(page.match(/<li/g)!.length).toBeGreaterThan(10); | |
| 65 | }); | |
| 66 | ||
| 67 | test("no inline width, and no rule the page ships fixes a width over 390 px", () => { | |
| 68 | expect(page).not.toMatch(/style="[^"]*(?:^|[;\s"])(?:min-)?width\s*:/i); | |
| 69 | for (const m of page.matchAll(/\swidth=["']?(\d+)/gi)) expect(Number(m[1])).toBeLessThanOrEqual(390); | |
| 70 | const over: string[] = []; | |
| 71 | for (const css of [base, components, content, ...(page.match(/<style[^>]*>[\s\S]*?<\/style>/g) ?? [])]) { | |
| 72 | for (const m of css.matchAll(/(?<![-\w(])(?:min-)?width\s*:\s*(-?[\d.]+)(px|rem|em|ch)\b/g)) { | |
| 73 | const px = Number(m[1]) * (m[2] === "px" ? 1 : m[2] === "ch" ? 8 : 16); | |
| 74 | if (px > 390) over.push(m[0]); | |
| 75 | } | |
| 76 | } | |
| 77 | expect(over).toEqual([]); | |
| 78 | }); | |
| 79 | ||
| 80 | test("the long-text container wraps anywhere", () => { | |
| 81 | const rule = content.match(/(?:^|\n)([^\n{]*\[data-repo-head\][^\n{]*)\{([^}]*)\}/); | |
| 82 | expect(rule).not.toBeNull(); | |
| 83 | expect(rule![2]).toMatch(/overflow-wrap:\s*(?:anywhere|break-word)/); | |
| 84 | expect(content).toMatch(/\[data-repo-head\] \.row-title[^{]*\{[^}]*white-space:\s*normal/); | |
| 85 | expect(content).toMatch(/\[data-repo-head\] \.prose table[^{]*\{[^}]*overflow-x:\s*auto/); | |
| 86 | }); | |
| 87 | }); | |
| 88 | ||
| 89 | const found = findChromium(); | |
| 90 | const chromium = found !== undefined && chromiumRuns(found) ? found : undefined; | |
| 91 | if (chromium === undefined) console.log("SKIPPING: no chromium that starts on this machine, so the repository head phone look is not measured"); | |
| 92 | ||
| 93 | describe.skipIf(chromium === undefined)("a repository's head page, measured at 390x844", () => { | |
| 94 | const measure = `(() => { | |
| 95 | const vw = document.documentElement.clientWidth; | |
| 96 | const scope = [...document.querySelectorAll("[data-repo-head], [data-repo-head] *")]; | |
| 97 | // An element inside a box that scrolls or clips on its own (a tab strip, a code block, a table) does not widen the page. | |
| 98 | const clipped = (el) => { for (let p = el.parentElement; p && p !== document.body; p = p.parentElement) { if (getComputedStyle(p).overflowX !== "visible") return true; } return false; }; | |
| 99 | const overflowing = scope.filter((el) => !clipped(el) && el.getBoundingClientRect().right > vw + 1).slice(0, 8).map((el) => el.tagName.toLowerCase() + "." + String(el.className) + "@" + Math.round(el.getBoundingClientRect().right)); | |
| 100 | return JSON.stringify({ scrollWidth: document.documentElement.scrollWidth, viewportWidth: vw, wrapped: scope.length > 0, overflowing }); | |
| 101 | })()`; | |
| 102 | test("no sideways scroll", async () => { | |
| 103 | const m = JSON.parse(await evaluateLoaded(chromium!, `${servers.url}/alice/fit`, { width: 390, height: 844 }, [session], measure)) as { scrollWidth: number; viewportWidth: number; wrapped: boolean; overflowing: string[] }; | |
| 104 | console.log(`repo head 390x844: ${JSON.stringify(m)}`); | |
| 105 | expect(m.wrapped).toBe(true); | |
| 106 | expect(m.overflowing).toEqual([]); | |
| 107 | expect(m.scrollWidth).toBeLessThanOrEqual(m.viewportWidth); | |
| 108 | }, 30_000); | |
| 109 | }); |
new above
offline