Public: anyone can read this; the crew can change it.
The /explore page fits a 390 px phone: no sideways scroll, long app and forge names wrap #9395
mason/forge:mason/9370-the-explore-page-fits-a-390-px-phone-no → main 10 commits fork 1 thread · 1 unresolved
4 files
changed +118
−7
src/web/studio/explore.ts +3 −2
| @@ -162,7 +162,7 @@ export async function explorePage(ctx: Ctx): Promise<Response> { | ||
| 162 | 162 | { label: "This week", updated: "7d" as const }, |
| 163 | 163 | { label: "This month", updated: "30d" as const }, |
| 164 | 164 | ]; |
| 165 | const body = html`${pageHead("Explore", { | |
| 165 | const body = html`<div data-explore>${pageHead("Explore", { | |
| 166 | 166 | sub: "Apps and their makers, ranked by forks, ships, use and how lately — the numbers on every row.", |
| 167 | 167 | })} |
| 168 | 168 | <form method="get" action="/explore" class="bar mb"> |
| @@ -214,7 +214,8 @@ export async function explorePage(ctx: Ctx): Promise<Response> { | ||
| 214 | 214 | </div> |
| 215 | 215 | ${rows.length === 0 |
| 216 | 216 | ? emptyState(ctx, query) |
| 217 | : listCard(rows.map(rowHtml))}`; | |
| 217 | : listCard(rows.map(rowHtml), { wrap: true })} | |
| 218 | </div>`; | |
| 218 | 219 | const response = page({ ctx, title: "Explore", body }); |
| 219 | 220 | notePhase(ctx.request, "render", performance.now() - rendering); |
| 220 | 221 | return response; |
src/web/style/content.ts +1 −1
| @@ -158,7 +158,7 @@ a.origin-chip:hover { border-color: var(--border-strong); color: var(--fg); } | ||
| 158 | 158 | [data-tell] .page-head-sub { flex-wrap: wrap; } |
| 159 | 159 | [data-tell] .comment-body img { max-width: 100%; height: auto; } |
| 160 | 160 | [data-tell] pre { max-width: 100%; overflow-x: auto; } |
| 161 | [data-apps], [data-apps-page], [data-bet-card], [data-milestone], [data-now], [data-people] { overflow-wrap: anywhere; } | |
| 161 | [data-apps], [data-apps-page], [data-bet-card], [data-milestone], [data-now], [data-explore], [data-people] { overflow-wrap: anywhere; } | |
| 162 | 162 | [data-bet-card] h2, [data-bet-card] ul, [data-bet-card] p { margin-block: 8px; } |
| 163 | 163 | [data-bet-card] ul { padding-inline-start: 16px; } |
| 164 | 164 | [data-bet-card] { max-height: 80vh; overflow-x: hidden; overflow-y: auto; } |
src/web/ui.ts +9 −4
| @@ -895,13 +895,18 @@ export function messageText(text: string): Html { | ||
| 895 | 895 | return html`<div class="prose" data-text="message"><pre>${text}</pre></div>`; |
| 896 | 896 | } |
| 897 | 897 | |
| 898 | /** A card wrapping a `<ul class="list">` — the shape every listing takes. */ | |
| 899 | export function listCard(rows: Html[], o: CardOptions = {}): Html { | |
| 898 | /** | |
| 899 | * A card wrapping a `<ul class="list">` — the shape every listing takes. | |
| 900 | * `wrap` makes it a `setting-list`: rows wrap and long titles break, for | |
| 901 | * listings of user-named things on a phone. | |
| 902 | */ | |
| 903 | export function listCard(rows: Html[], o: CardOptions & { wrap?: boolean } = {}): Html { | |
| 904 | const { wrap, ...card_ } = o; | |
| 900 | 905 | return card( |
| 901 | html`<ul class="list"> | |
| 906 | html`<ul class="list${wrap ? " setting-list" : ""}"> | |
| 902 | 907 | ${rows} |
| 903 | 908 | </ul>`, |
| 904 | { ...o, pad: false }, | |
| 909 | { ...card_, pad: false }, | |
| 905 | 910 | ); |
| 906 | 911 | } |
| 907 | 912 |
test/explorer-fit.test.ts added +105
| @@ -0,0 +1,105 @@ | ||
| 1 | /** | |
| 2 | * The /explore page fits a 390 px phone (#9370): seeded with an unbroken | |
| 3 | * long word as app name and description, and many rows, the page ships no | |
| 4 | * fixed width over 390 px, its rows wrap, and nothing scrolls sideways. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 7 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { createApp, type App } from "../src/app.ts"; | |
| 11 | import { createRepo } from "../src/actions/repos.ts"; | |
| 12 | import { createApp as insertApp } from "../src/core/apps.ts"; | |
| 13 | import { createUser } from "../src/core/users.ts"; | |
| 14 | import { createSession } from "../src/core/sessions.ts"; | |
| 15 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 16 | import { utilities as base } from "../src/web/style/base.ts"; | |
| 17 | import { components } from "../src/web/style/components.ts"; | |
| 18 | import { content } from "../src/web/style/content.ts"; | |
| 19 | import { findChromium } from "../src/looks/capture.ts"; | |
| 20 | import { chromiumRuns, evaluateLoaded } from "./helpers/chrome.ts"; | |
| 21 | ||
| 22 | const LONG = "L".repeat(250); | |
| 23 | let dir: string; | |
| 24 | let app: App; | |
| 25 | let servers: Servers; | |
| 26 | let page: string; | |
| 27 | let session: { name: string; value: string }; | |
| 28 | ||
| 29 | beforeAll(async () => { | |
| 30 | dir = await mkdtemp(join(tmpdir(), "forge-explore-fit-")); | |
| 31 | app = createApp({ dataDir: dir, port: 0 }); | |
| 32 | servers = await serve(app); | |
| 33 | const made = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 34 | if (!made.ok) throw new Error(made.error); | |
| 35 | for (let i = 0; i < 24; i++) { | |
| 36 | const r = await createRepo(app, made.value, { | |
| 37 | name: i === 0 ? "n".repeat(60) : `app-${i}`, | |
| 38 | visibility: "public", | |
| 39 | description: i === 0 ? LONG : i === 1 ? "A long and winding description ".repeat(8) : `App ${i}`, | |
| 40 | }); | |
| 41 | if (!r.ok) throw new Error(JSON.stringify(r.error)); | |
| 42 | const rec = insertApp(app.db, { repoId: r.value.id, slug: `alice-${i}`, access: "public" }); | |
| 43 | if (!rec.ok) throw new Error(rec.error); | |
| 44 | } | |
| 45 | const token = createSession(app.db, made.value.id).token; | |
| 46 | session = { name: "forge_session", value: token }; | |
| 47 | page = await (await fetch(`${servers.url}/explore`, { headers: { cookie: `forge_session=${token}; forge_mode=dev` } })).text(); | |
| 48 | }, 60_000); | |
| 49 | afterAll(async () => { | |
| 50 | servers.stop(); | |
| 51 | app.close(); | |
| 52 | await rm(dir, { recursive: true, force: true }); | |
| 53 | }); | |
| 54 | ||
| 55 | describe("/explore at 390 px", () => { | |
| 56 | test("renders the seeded long content in many rows", () => { | |
| 57 | expect(page).toContain(LONG); | |
| 58 | expect(page).toContain("n".repeat(60)); | |
| 59 | expect(page.match(/class="row[ "]/g)!.length).toBeGreaterThan(12); | |
| 60 | expect(page).toContain("data-explore"); | |
| 61 | }); | |
| 62 | ||
| 63 | test("no inline width, and no rule the page ships fixes a width over 390 px", () => { | |
| 64 | expect(page).not.toMatch(/style="[^"]*(?:^|[;\s"])(?:min-|max-)?width\s*:/i); | |
| 65 | for (const m of page.matchAll(/\swidth=["']?(\d+)/gi)) expect(Number(m[1])).toBeLessThanOrEqual(390); | |
| 66 | const over: string[] = []; | |
| 67 | for (const css of [base, components, content, ...(page.match(/<style[^>]*>[\s\S]*?<\/style>/g) ?? [])]) { | |
| 68 | for (const m of css.matchAll(/(?<![-\w(])(?:min-)?width\s*:\s*(-?[\d.]+)(px|rem|em|ch)\b/g)) { | |
| 69 | if (Number(m[1]) * (m[2] === "px" ? 1 : m[2] === "ch" ? 8 : 16) > 390) over.push(m[0]); | |
| 70 | } | |
| 71 | } | |
| 72 | expect(over).toEqual([]); | |
| 73 | }); | |
| 74 | ||
| 75 | test("the rows wrap anywhere: the list is a setting-list inside [data-explore]", () => { | |
| 76 | expect(page).toMatch(/<ul class="list setting-list">/); | |
| 77 | const rule = content.match(/(?:^|\n)([^\n{]*\[data-explore\][^\n{]*)\{([^}]*)\}/); | |
| 78 | expect(rule).not.toBeNull(); | |
| 79 | expect(rule![1]).toMatch(/(?:^|,)\s*\[data-explore\]\s*(?:,|$)/); | |
| 80 | expect(rule![2]).toMatch(/overflow-wrap:\s*(?:anywhere|break-word)/); | |
| 81 | expect(content).toMatch(/\.bar \.seg\s*\{[^}]*max-width:\s*100%[^}]*overflow-x:\s*auto/); | |
| 82 | expect(components).toMatch(/\.setting-list \.row-title[^{]*\{[^}]*overflow-wrap:\s*anywhere/); | |
| 83 | }); | |
| 84 | }); | |
| 85 | ||
| 86 | const found = findChromium(); | |
| 87 | const chromium = found !== undefined && chromiumRuns(found) ? found : undefined; | |
| 88 | if (chromium === undefined) console.log("SKIPPING: no chromium that starts on this machine, so the explore phone look is not measured"); | |
| 89 | ||
| 90 | describe.skipIf(chromium === undefined)("/explore, measured at 390x844", () => { | |
| 91 | test("no sideways scroll", async () => { | |
| 92 | const measure = `(() => { | |
| 93 | const vw = document.documentElement.clientWidth; | |
| 94 | const scope = [...document.querySelectorAll("[data-explore], [data-explore] *")]; | |
| 95 | const overflowing = scope.filter((el) => el.getBoundingClientRect().right > vw + 1).slice(0, 8).map((el) => el.tagName.toLowerCase()); | |
| 96 | return JSON.stringify({ scrollWidth: document.documentElement.scrollWidth, viewportWidth: vw, scoped: scope.length > 0, overflowing, rows: document.querySelectorAll("[data-explore] li").length }); | |
| 97 | })()`; | |
| 98 | const m = JSON.parse(await evaluateLoaded(chromium!, `${servers.url}/explore`, { width: 390, height: 844 }, [session], measure)) as { scrollWidth: number; viewportWidth: number; scoped: boolean; overflowing: string[]; rows: number }; | |
| 99 | console.log(`explore 390x844: ${JSON.stringify(m)}`); | |
| 100 | expect(m.scoped).toBe(true); | |
| 101 | expect(m.rows).toBeGreaterThan(12); | |
| 102 | expect(m.overflowing).toEqual([]); | |
| 103 | expect(m.scrollWidth).toBeLessThanOrEqual(m.viewportWidth); | |
| 104 | }, 30_000); | |
| 105 | }); |
new above
offline