From 0b99686ca71533550f1220a8b4b654e866bfe546 Mon Sep 17 00:00:00 2001 From: Joshua Oosthuizen Date: Thu, 26 Nov 2026 10:54:43 +0200 Subject: [PATCH] website 1.0.0: release checks, contrast and map fixes - e2e: every section variant in every template (axe and 312 screenshots compared with local baselines), Lighthouse on a phone (median of three, CPU slowdown calibrated to the machine), the whole suite on real Postgres with E2E_DATABASE_URL, a frozen clock, E2E_REUSE for running servers. - Fixes found by them: contrast on Bold's service times panel and Calendar event dates; the OpenStreetMap embed loads only once on screen; the messages page's first thumbnail is eager, its host preconnected. - The restore e2e waits for its second publish (raced on Postgres). - docs: Hub 2.22.0 deployed; website@1.0.0 released. Co-Authored-By: Claude Opus 5.5 --- apps/website/CHANGELOG.md | 18 +- apps/website/WHATS-NEW.md | 23 + apps/website/backend/package.json | 2 +- apps/website/e2e/.gitignore | 2 + apps/website/e2e/admin.spec.ts | 2 + apps/website/e2e/lighthouse.spec.ts | 94 + apps/website/e2e/server.ts | 39 +- apps/website/e2e/variants.spec.ts | 80 + apps/website/frontend/package.json | 2 +- apps/website/frontend/src/app/globals.css | 8 +- apps/website/frontend/src/site/LazyMap.tsx | 32 + .../frontend/src/site/MessagePlayer.tsx | 5 +- apps/website/frontend/src/site/PageView.tsx | 12 +- .../frontend/src/site/sections/index.tsx | 12 +- apps/website/playwright.config.ts | 7 +- docs/HANDOVER.md | 16 +- docs/VERSIONS.md | 18 +- docs/WEBSITE-1.0-PLAN.md | 6 + package-lock.json | 1738 ++++++++++++++++- package.json | 2 + 20 files changed, 2083 insertions(+), 35 deletions(-) create mode 100644 apps/website/e2e/lighthouse.spec.ts create mode 100644 apps/website/e2e/variants.spec.ts create mode 100644 apps/website/frontend/src/site/LazyMap.tsx diff --git a/apps/website/CHANGELOG.md b/apps/website/CHANGELOG.md index d3cf94d..79e9010 100644 --- a/apps/website/CHANGELOG.md +++ b/apps/website/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog — Church Website -## [Unreleased] +## [1.0.0] — 2026-11-26 ### Added @@ -39,6 +39,22 @@ `e2e/screens/`; the admin's flows (edit, preview, publish; discard; a shared link, revoked; restore; a template switch; a Viewer; signing in from a deep admin page) and axe on every admin screen. +- **The release checks** (§13): **every section variant in every template** (`e2e/variants.spec.ts`: + 26 × 4, axe on each, and 312 screenshots at phone, tablet and desktop compared with the last + baselines, kept on the machine that runs them, not in git); **Lighthouse on a phone** + (`e2e/lighthouse.spec.ts`: home, an event and the messages in each template, the median of three + runs with the CPU slowdown calibrated to the machine: SEO 100, accessibility 95+, performance + 90+); and **the same suite on real Postgres** + (`E2E_DATABASE_URL=postgresql://…/_e2e`: the database made again, the migrations applied with + `prisma migrate deploy`). The e2e server's clock is frozen, so the demo's dates are the same every + run. +- **The map loads only once it's on screen** (the With map service times): until then, a link to + it. The iframe's own lazy loading fetched OpenStreetMap's 300 KB script with the page on a phone, + and told OpenStreetMap about every visitor. **The messages page's first thumbnail isn't lazy** + (it's the largest thing on screen), and the page connects to its host at once. +- **Contrast on Bold** (found by the variant checks): the service times' notes on Bold's dark panel + (Panel and With map), and the dates of the Calendar events on a dark band, are light now + (`cc-dark` on the panel; `cc-brand-text`, which the dark rules can override, for the dates). - **The admin** (§4, §10): a dashboard with the setup checklist, pending changes, storage and notes about the church's colours; Template and style (the template, each homepage section's layout with the recommended ones first, the homepage order, the style settings); Pages (details, search diff --git a/apps/website/WHATS-NEW.md b/apps/website/WHATS-NEW.md index 7b9cd96..97e29ad 100644 --- a/apps/website/WHATS-NEW.md +++ b/apps/website/WHATS-NEW.md @@ -2,3 +2,26 @@ What each version changes for the church, in plain language (read by the Hub like Cross Events' WHATS-NEW.md; a section shows once its version is tagged). + +## 1.0.0 — requires accounts 1.7.0 + +- **Your church's own website**, managed by you. Choose one of four templates (Heritage, Bold, + Community or Clean), then make it yours: each homepage section has two or three layouts, and you + pick the fonts, corners, colours and spacing. Your logo, colours and details come from your + church profile, so the website, Cross Events and your sign-in pages look like one church. +- **Nothing goes live until you say so.** Every change is a draft. Preview the whole site at phone, + tablet and desktop size (and share a preview link), then press **Publish** once. Every published + version is kept, and you can go back to any of them. Until your first Publish, visitors see a + "Coming soon" page. +- **Pages for everything a visitor looks for:** Plan your visit, About, Ministries, Leadership, + Events, Messages, Give and Contact, plus your own pages built from blocks. +- **Messages straight from YouTube:** link your channel or playlist and each new video appears by + itself, or add messages by hand with a YouTube or Spotify link. +- **Events:** add simple events here, and show the events from your Cross Events (with a link to + register there). +- **People and roles:** Owners, Admins, Editors, Ministry leaders (only their own ministry) and + Viewers, all signing in with their church account. An audit log shows who changed what. +- **Found by search engines:** titles and descriptions you can edit, share images, your church on + maps and in local search, and your Google and Bing verification codes. +- **Photos made safe and fast:** location details removed from every photo, and the right size + sent to each screen. 5 GB of uploads included; ask for more under Media library. diff --git a/apps/website/backend/package.json b/apps/website/backend/package.json index e0b2305..d82cb3e 100644 --- a/apps/website/backend/package.json +++ b/apps/website/backend/package.json @@ -1,6 +1,6 @@ { "name": "@crosscode/website-backend", - "version": "0.1.0", + "version": "1.0.0", "description": "Church Website: the public site's content API, the admin API, publishing and uploads", "private": true, "type": "module", diff --git a/apps/website/e2e/.gitignore b/apps/website/e2e/.gitignore index da43889..410546f 100644 --- a/apps/website/e2e/.gitignore +++ b/apps/website/e2e/.gitignore @@ -2,3 +2,5 @@ test-results/ playwright-report/ .uploads/ screens/ +lighthouse/ +variants.spec.ts-snapshots/ diff --git a/apps/website/e2e/admin.spec.ts b/apps/website/e2e/admin.spec.ts index eac2734..6a6e00f 100644 --- a/apps/website/e2e/admin.spec.ts +++ b/apps/website/e2e/admin.spec.ts @@ -100,6 +100,8 @@ test("restore an older version, then publish it", async ({ page, context }) => { await page.getByRole("button", { name: "Restore" }).click(); await expect(page.getByText("Version 1 is back in your drafts")).toBeVisible(); await page.getByRole("button", { name: "Publish all changes" }).click(); + // Wait for it, as above: on real Postgres the publish takes long enough to race the page load. + await expect(page.getByText("Published: visitors see it now.")).toBeVisible(); await page.goto("/about"); await expect(page.getByRole("heading", { level: 1, name: "About us" })).toBeVisible(); }); diff --git a/apps/website/e2e/lighthouse.spec.ts b/apps/website/e2e/lighthouse.spec.ts new file mode 100644 index 0000000..1c46525 --- /dev/null +++ b/apps/website/e2e/lighthouse.spec.ts @@ -0,0 +1,94 @@ +/** + * Lighthouse, mobile (WEBSITE-1.0-PLAN §13, ROADMAP §11 "Checks"): the demo church's home page, an + * event and the messages page in each template, with the template's defaults. SEO 100, + * accessibility 95+, performance 90+. Lighthouse's default run is a phone on a throttled + * connection (simulated), against the production build the other specs use; each page is measured + * three times (LIGHTHOUSE_RUNS), with the CPU slowdown calibrated to this machine + * (calibratedSlowdown), and the median run counts. Its reports go to + * e2e/lighthouse/ (not kept in git) for a look when a score drops. + */ +import fs from "node:fs"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; +import { chromium, expect, test } from "@playwright/test"; +import * as chromeLauncher from "chrome-launcher"; +import lighthouse from "lighthouse"; + +const BACKEND = "http://127.0.0.1:5310"; +const SITE = "http://localhost:3310"; +const TEMPLATES = ["heritage", "bold", "community", "clean"] as const; +const MIN = { seo: 1, accessibility: 0.95, performance: 0.9 } as const; +const RUNS = Number(process.env.LIGHTHOUSE_RUNS ?? 3); + +/** + * Lighthouse's 4× CPU slowdown stands a fast desktop (its benchmark about 1500) in for a mid-range + * phone. On a slower or busy machine the same 4× makes a far slower phone than the target, and the + * score measures the machine: here the benchmark moved from 1450 to 460 between runs a minute + * apart. So a quick probe reads the benchmark first and the slowdown is scaled to it (at least ×1), + * as Lighthouse's throttling notes advise; the thresholds stay the same. + */ +const slowdownFor = (index: number) => Math.round(Math.min(4, Math.max(1, (4 * index) / 1500)) * 10) / 10; + +async function calibratedSlowdown(url: string): Promise { + const probe = await lighthouse(`${SITE}${url}`, { port: chrome.port, logLevel: "error", onlyAudits: ["viewport"] }); + return slowdownFor(probe?.lhr.environment.benchmarkIndex ?? 1500); +} + +/** + * One measured run, calibrated. The machine can slow down between the probe and the run; a run + * whose own benchmark called for a much smaller slowdown than it used is taken again (twice at most). + */ +async function measure(url: string) { + let r; + for (let attempt = 0; attempt < 3; attempt++) { + const slowdown = await calibratedSlowdown(url); + r = await lighthouse(`${SITE}${url}`, { port: chrome.port, output: "html", logLevel: "error", onlyCategories: Object.keys(MIN), throttling: { cpuSlowdownMultiplier: slowdown } as never }); + if (!r || slowdown <= slowdownFor(r.lhr.environment.benchmarkIndex) * 1.3) break; + } + return r; +} +const reports = path.join(path.dirname(fileURLToPath(import.meta.url)), "lighthouse"); + +test.describe.configure({ timeout: 600_000 }); + +let chrome: chromeLauncher.LaunchedChrome; +test.beforeAll(async () => { + fs.mkdirSync(reports, { recursive: true }); + chrome = await chromeLauncher.launch({ chromePath: chromium.executablePath(), chromeFlags: ["--headless=new", "--no-first-run"] }); +}); +test.afterAll(async () => { await chrome?.kill(); }); + +for (const template of TEMPLATES) { + test(`${template}: home, an event and the messages, on a phone`, async ({ request, page }) => { + expect((await request.post(`${BACKEND}/test/demo?template=${template}`)).ok()).toBeTruthy(); + await page.goto("/events"); + const event = await page.locator('main a[href^="/events/"]').first().getAttribute("href"); + expect(event).toBeTruthy(); + + const failed: string[] = []; + for (const [name, url] of [["home", "/"], ["event", event!], ["messages", "/messages"]] as const) { + // Once to warm the server, then measured RUNS times; the median run (by performance) counts, + // as Lighthouse advises: one run's total blocking time moves by 200ms+ on a busy machine. + await request.get(url); + const runs = []; + for (let n = 0; n < RUNS; n++) { + const r = await measure(url); + expect(r, `${template} ${name}`).toBeTruthy(); + runs.push(r!); + } + runs.sort((a, b) => (a.lhr.categories.performance?.score ?? 0) - (b.lhr.categories.performance?.score ?? 0)); + const result = runs[Math.floor(RUNS / 2)]; + fs.writeFileSync(path.join(reports, `${template}-${name}.html`), String(result!.report)); + const scores = Object.fromEntries(Object.keys(MIN).map((c) => [c, result!.lhr.categories[c]?.score ?? 0])); + const env = result!.lhr.environment; + console.log(`[lighthouse] ${template} ${name}: ${Object.entries(scores).map(([c, s]) => `${c} ${Math.round(s * 100)}`).join(", ")} (benchmark ${Math.round(env.benchmarkIndex)}, CPU ×${result!.lhr.configSettings.throttling.cpuSlowdownMultiplier})`); + for (const [c, min] of Object.entries(MIN)) { + if (scores[c]! < min) { + const audits = Object.values(result!.lhr.audits).filter((a) => a.score !== null && a.score < 0.9 && (result!.lhr.categories[c]?.auditRefs ?? []).some((r) => r.id === a.id && r.weight > 0)); + failed.push(`${template} ${name} ${c} ${Math.round(scores[c]! * 100)} < ${min * 100}: ${audits.map((a) => `${a.id}${a.displayValue ? ` (${a.displayValue})` : ""}`).join(", ")}`); + } + } + } + expect(failed).toEqual([]); + }); +} diff --git a/apps/website/e2e/server.ts b/apps/website/e2e/server.ts index 007b615..b406130 100644 --- a/apps/website/e2e/server.ts +++ b/apps/website/e2e/server.ts @@ -1,16 +1,21 @@ /** * The e2e backend (playwright.config.ts): the Website's backend on port 5310 with the in-memory - * database from the backend tests (no Postgres needed) and the demo church published. The pages - * run with `next dev` on 3310 and send /api here. + * database from the backend tests (no Postgres needed), or a real Postgres with E2E_DATABASE_URL + * (freshPostgres, below), and the demo church published. The pages run as a production build on + * 3310 and send /api here. * * Test helpers: POST /test/demo?template= loads the demo church on that template; * POST /test/design { variants?, style?, home? } changes the design and publishes again. */ +import { execSync } from 'node:child_process'; import fs from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; import express from 'express'; +import pg from 'pg'; +import { PrismaPg } from '@prisma/adapter-pg'; import { websiteTemplateSchema } from '@crosscode/contracts'; +import { PrismaClient } from '../backend/src/generated/prisma/client.js'; import { createApp } from '../backend/src/app.js'; import { createCtx } from '../backend/src/context.js'; import { loadDemo } from '../backend/src/demo/demoChurch.js'; @@ -19,12 +24,38 @@ import { hashToken } from '../backend/src/lib/crypto.js'; import { publish } from '../backend/src/site/snapshot.js'; import { memoryDb } from '../backend/tests/support/memoryDb.js'; +const { Client } = pg; const here = path.dirname(fileURLToPath(import.meta.url)); const uploads = path.join(here, '.uploads'); fs.mkdirSync(uploads, { recursive: true }); -const db = memoryDb(); -const ctx = createCtx(loadConfig({ WEBSITE_URL: 'http://localhost:3310', NODE_ENV: 'test', JOBS_ENABLED: 'false', HUB_URL: 'http://127.0.0.1:1', UPLOAD_DIR: uploads, TRUST_PROXY: 'true' }), db as never); +const db = process.env.E2E_DATABASE_URL ? await freshPostgres(process.env.E2E_DATABASE_URL) : memoryDb(); + +/** + * The real-Postgres run (WEBSITE-1.0-PLAN §13): `E2E_DATABASE_URL=postgresql://…/ccw_website_e2e npx + * playwright test`. The database is dropped and made again, the migrations applied with `prisma + * migrate deploy` (as `crosscode deploy` does), and the same suite runs on it. The name must end in + * `_e2e`, so a real site's database is never dropped. + */ +async function freshPostgres(url: string) { + const target = new URL(url); + const name = target.pathname.slice(1); + if (!/^[a-z0-9_]+_e2e$/.test(name)) throw new Error(`E2E_DATABASE_URL must name a database ending in _e2e (got "${name}").`); + const admin = new URL(url); + admin.pathname = '/postgres'; + const pg = new Client({ connectionString: admin.toString() }); + await pg.connect(); + await pg.query(`DROP DATABASE IF EXISTS ${name} WITH (FORCE)`); + await pg.query(`CREATE DATABASE ${name}`); + await pg.end(); + execSync('npx prisma migrate deploy', { cwd: path.join(here, '../backend'), env: { ...process.env, DATABASE_URL: url }, stdio: 'inherit' }); + console.log(`[e2e] On Postgres: ${name}, migrations applied.`); + return new PrismaClient({ adapter: new PrismaPg({ connectionString: url }) }); +} +// A frozen clock (a Monday morning), so the demo's dates, and so the screenshots, are the same every +// run (variants.spec.ts). E2E_NOW changes it. +const frozen = new Date(process.env.E2E_NOW ?? '2026-11-23T06:00:00Z'); +const ctx = createCtx(loadConfig({ WEBSITE_URL: 'http://localhost:3310', NODE_ENV: 'test', JOBS_ENABLED: 'false', HUB_URL: 'http://127.0.0.1:1', UPLOAD_DIR: uploads, TRUST_PROXY: 'true' }), db as never, { now: () => new Date(frozen) }); await loadDemo(ctx, websiteTemplateSchema.parse(process.env.DEMO_TEMPLATE ?? 'heritage'), { uploadDir: uploads }); const app = express(); diff --git a/apps/website/e2e/variants.spec.ts b/apps/website/e2e/variants.spec.ts new file mode 100644 index 0000000..683a033 --- /dev/null +++ b/apps/website/e2e/variants.spec.ts @@ -0,0 +1,80 @@ +/** + * Every section variant in every template (WEBSITE-1.0-PLAN §3, "Checks per variant", and §13): the + * demo church's homepage with all eight sections showing, one variant changed at a time. For each, + * axe finds no violations (WCAG 2.2 AA) and the section looks as it did last time at phone, tablet + * and desktop width: 26 variants × 4 templates × 3 widths = 312 screenshots, compared with + * `toHaveScreenshot` against the baselines in e2e/variants.spec.ts-snapshots/. + * + * The baselines aren't in git (about 20 MB, and each operating system draws text a little + * differently): they're kept on the machine that runs the release checks. Take them at a release + * (`npx playwright test variants --update-snapshots`, then look through them), and the next + * release's run shows every section that changed. The e2e server freezes the clock (E2E_NOW), so + * the demo's dates never change between runs. What comes from outside is masked: the video, the + * map (OpenStreetMap) and YouTube's thumbnails. + */ +import AxeBuilder from "@axe-core/playwright"; +import { expect, test, type Page } from "@playwright/test"; +import { SECTION_TYPES, SECTION_VARIANTS, TEMPLATE_VARIANTS } from "../backend/src/site/variants.js"; + +const BACKEND = "http://127.0.0.1:5310"; +const TEMPLATES = Object.keys(TEMPLATE_VARIANTS) as (keyof typeof TEMPLATE_VARIANTS)[]; +const WIDTHS = [["phone", { width: 390, height: 844 }], ["tablet", { width: 820, height: 1180 }], ["desktop", { width: 1366, height: 900 }]] as const; +// Every section showing, in a fixed order, so the nth
in
is the nth type here. +const HOME = SECTION_TYPES.map((section) => ({ section, hidden: false })); + +async function design(page: Page, variants: Record) { + const res = await page.request.post(`${BACKEND}/test/design`, { data: { variants, home: HOME } }); + expect(res.ok()).toBeTruthy(); +} + +/** + * Lazy images load only once scrolled to: go through the page, then wait for every image. The + * site's own images must really have loaded (a broken one is "complete" too). + */ +async function loadImages(page: Page) { + await page.evaluate(async () => { + for (let y = 0; y < document.body.scrollHeight; y += 500) { window.scrollTo(0, y); await new Promise((r) => setTimeout(r, 40)); } + window.scrollTo(0, 0); + }); + await page.waitForFunction(() => Array.from(document.images).every((i) => i.complete), null, { timeout: 30_000 }); + const broken = await page.evaluate(() => Array.from(document.images) + .filter((i) => new URL(i.currentSrc || i.src, location.href).origin === location.origin && i.naturalWidth === 0) + .map((i) => i.currentSrc || i.src)); + expect(broken, "images that didn't load").toEqual([]); +} + +for (const template of TEMPLATES) { + test.describe(`${template} variants`, () => { + test.beforeAll(async ({ request }) => { + expect((await request.post(`${BACKEND}/test/demo?template=${template}`)).ok()).toBeTruthy(); + }); + + for (const [i, type] of SECTION_TYPES.entries()) { + for (const variant of SECTION_VARIANTS[type]) { + test(`${type}: ${variant}`, async ({ page }) => { + await design(page, { [type]: variant }); + await page.setViewportSize(WIDTHS[2][1]); + expect((await page.goto("/"))?.status()).toBe(200); + await expect(page.locator("html")).toHaveAttribute("data-template", template); + const sections = page.locator("main > section"); + await expect(sections).toHaveCount(SECTION_TYPES.length); + await loadImages(page); + + const axe = await new AxeBuilder({ page }).withTags(["wcag2a", "wcag2aa", "wcag21aa", "wcag22aa"]).analyze(); + expect(axe.violations.map((v) => `${v.id} (${v.nodes.length}) ${v.nodes[0]?.target}`)).toEqual([]); + + const section = sections.nth(i); + for (const [name, size] of WIDTHS) { + await page.setViewportSize(size); + await loadImages(page); + await expect(section).toHaveScreenshot(`${template}-${type}-${variant}-${name}.png`, { + mask: [page.locator("main video"), page.locator("main [data-map]"), page.locator('main img[src*="ytimg.com"]')], + animations: "disabled", + maxDiffPixelRatio: 0.01, + }); + } + }); + } + } + }); +} diff --git a/apps/website/frontend/package.json b/apps/website/frontend/package.json index e10e173..ddc6763 100644 --- a/apps/website/frontend/package.json +++ b/apps/website/frontend/package.json @@ -1,6 +1,6 @@ { "name": "@crosscode/website-frontend", - "version": "0.1.0", + "version": "1.0.0", "private": true, "description": "Church Website: the church's public site in its template, and the admin", "scripts": { diff --git a/apps/website/frontend/src/app/globals.css b/apps/website/frontend/src/app/globals.css index 6a95c8e..e261431 100644 --- a/apps/website/frontend/src/app/globals.css +++ b/apps/website/frontend/src/app/globals.css @@ -66,11 +66,15 @@ h1, h2, h3 { /* Text on a dark background (Bold's cards and bands, a dark section): light, and still AA. */ .cc-dark .cc-muted, [data-template="bold"] .cc-card .cc-muted, [data-section-colour="mixed"] .cc-section:not(.cc-own-bg):nth-of-type(3n) .cc-muted { color: rgb(255 255 255 / 0.8); } - .cc-dark .cc-link, .cc-dark .cc-eyebrow, [data-template="bold"] .cc-card .cc-link, [data-template="bold"] .cc-card .cc-eyebrow, + .cc-dark .cc-link, .cc-dark .cc-eyebrow, .cc-dark .cc-brand-text, + [data-template="bold"] .cc-card .cc-link, [data-template="bold"] .cc-card .cc-eyebrow, [data-template="bold"] .cc-card .cc-brand-text, [data-section-colour="mixed"] .cc-section:not(.cc-own-bg):nth-of-type(3n) .cc-link, - [data-section-colour="mixed"] .cc-section:not(.cc-own-bg):nth-of-type(3n) .cc-eyebrow { color: rgb(255 255 255); } + [data-section-colour="mixed"] .cc-section:not(.cc-own-bg):nth-of-type(3n) .cc-eyebrow, + [data-section-colour="mixed"] .cc-section:not(.cc-own-bg):nth-of-type(3n) .cc-brand-text { color: rgb(255 255 255); } .cc-muted { color: rgb(75 85 99); } + /* The church's colour as text (made AA on light by the palette): here, not a utility, so the dark rules above win. */ + .cc-brand-text { color: rgb(var(--brand-text)); } .cc-link { color: rgb(var(--brand-text)); @apply underline-offset-4 hover:underline; } .cc-eyebrow { @apply text-sm font-semibold uppercase tracking-widest; color: rgb(var(--brand-text)); } [data-template="heritage"] .cc-eyebrow { @apply font-normal tracking-[0.25em]; font-variant: small-caps; text-transform: none; } diff --git a/apps/website/frontend/src/site/LazyMap.tsx b/apps/website/frontend/src/site/LazyMap.tsx new file mode 100644 index 0000000..36fd3df --- /dev/null +++ b/apps/website/frontend/src/site/LazyMap.tsx @@ -0,0 +1,32 @@ +"use client"; + +import { useEffect, useRef, useState } from "react"; + +/** + * The OpenStreetMap embed, loaded only once it's on screen (no Google, no cookies). An iframe's own + * `loading="lazy"` loads anything within about 1,250px of the screen, so on a phone the map + * (300 KB of OpenStreetMap's script) loaded with the page and slowed it down (Lighthouse, + * WEBSITE-1.0-PLAN §13), and OpenStreetMap saw every visitor. Until then: a link to the map. + */ +export function LazyMap({ src, href }: { src: string; href: string | null }) { + const box = useRef(null); + const [show, setShow] = useState(false); + useEffect(() => { + const el = box.current; + if (!el || typeof IntersectionObserver === "undefined") { setShow(true); return; } + const io = new IntersectionObserver((entries) => { + if (entries.some((e) => e.isIntersecting)) { setShow(true); io.disconnect(); } + }, { rootMargin: "100px" }); + io.observe(el); + return () => io.disconnect(); + }, []); + return ( +
+ {show ? ( +