Skip to content

Commit da21731

Browse files
committed
Landing page prerendered to HTML at build time and sent for / without a session; build page buttons side by side; GitHub sign-in matches any verified email; org:add-member task
1 parent 3ca28a7 commit da21731

20 files changed

Lines changed: 279 additions & 38 deletions

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ Visual regression testing for documents, browsers and apps. Send a PDF, a page s
44
your laptop; VisualCI renders it in one pinned environment, skips anything whose hash it has seen, diffs the rest
55
page by page, and waits for your approval in the pull request.
66

7-
Status: design stage. See [docs/design.md](docs/design.md).
7+
Status: live at https://visualci.com, used by DocSpring. The design is in [docs/design.md](docs/design.md).

‎server/frontend/landing.html‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<meta name="description" content="Visual regression testing for PDFs, browser screenshots and mobile screenshots. Rendered in one pinned environment, diffed page by page, approved in the pull request." />
7+
<meta name="color-scheme" content="light dark" />
8+
<link rel="icon" href="/favicon.svg" type="image/svg+xml" />
9+
<title>VisualCI</title>
10+
<script>
11+
try {
12+
var t = localStorage.getItem('vci-theme')
13+
if (t === 'light' || t === 'dark') document.documentElement.dataset.theme = t
14+
} catch (e) {}
15+
</script>
16+
</head>
17+
<body>
18+
<div id="root"><!--landing--></div>
19+
<script type="module" src="/src/landing-client.tsx"></script>
20+
</body>
21+
</html>

‎server/frontend/package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"packageManager": "pnpm@10.12.4",
77
"scripts": {
88
"dev": "vite",
9-
"build": "tsc -b && vite build",
9+
"build": "tsc -b && vite build && vite build --ssr src/landing-server.tsx --outDir dist-ssr && node scripts/prerender.mjs",
1010
"preview": "vite preview"
1111
},
1212
"dependencies": {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Puts the landing page's server-rendered HTML into dist/landing.html, after `vite build` (the browser bundles) and
2+
// `vite build --ssr` (the renderer, in dist-ssr). Fails if the placeholder is missing, so a broken build never ships a
3+
// blank landing page.
4+
import { readFile, rm, writeFile } from 'node:fs/promises'
5+
import { fileURLToPath, pathToFileURL } from 'node:url'
6+
7+
const root = fileURLToPath(new URL('..', import.meta.url))
8+
const { render } = await import(pathToFileURL(`${root}dist-ssr/landing-server.js`).href)
9+
const file = `${root}dist/landing.html`
10+
const html = await readFile(file, 'utf8')
11+
const placeholder = '<!--landing-->'
12+
if (!html.includes(placeholder)) throw new Error(`${file} has no ${placeholder}`)
13+
const body = render()
14+
if (body.length < 1000) throw new Error(`the landing page rendered only ${body.length} characters`)
15+
await writeFile(file, html.replace(placeholder, body))
16+
await rm(`${root}dist-ssr`, { recursive: true, force: true })
17+
console.log(`prerendered dist/landing.html (${body.length} characters of HTML)`)

‎server/frontend/src/LandingApp.tsx‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
2+
import { Landing } from './pages/Landing'
3+
4+
/** The landing page on its own: prerendered to `dist/landing.html` at build time (landing-server.tsx) and hydrated in
5+
* the browser (landing-client.tsx). The server sends it for `/` to visitors without a session, so they see the page
6+
* at once instead of the app's loading spinner. */
7+
export function makeLandingClient() {
8+
return new QueryClient({ defaultOptions: { queries: { retry: false, refetchOnWindowFocus: false } } })
9+
}
10+
11+
export function LandingApp({ client }: { client: QueryClient }) {
12+
return (
13+
<QueryClientProvider client={client}>
14+
<Landing />
15+
</QueryClientProvider>
16+
)
17+
}

‎server/frontend/src/components/Logo.tsx‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,24 @@ export function Mark({ size = 20 }: { size?: number }) {
1010
)
1111
}
1212

13-
export function Logo() {
14-
return (
15-
<Link to="/" className="logo" aria-label="VisualCI home">
13+
/** `plain`: an ordinary link, for the prerendered landing page, which has no router. */
14+
export function Logo({ plain = false }: { plain?: boolean }) {
15+
const inner = (
16+
<>
1617
<Mark />
1718
<span>VisualCI</span>
19+
</>
20+
)
21+
if (plain) {
22+
return (
23+
<a href="/" className="logo" aria-label="VisualCI home">
24+
{inner}
25+
</a>
26+
)
27+
}
28+
return (
29+
<Link to="/" className="logo" aria-label="VisualCI home">
30+
{inner}
1831
</Link>
1932
)
2033
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react'
2+
import { hydrateRoot } from 'react-dom/client'
3+
import '@fontsource-variable/geist'
4+
import '@fontsource-variable/geist-mono'
5+
import './styles.css'
6+
import { LandingApp, makeLandingClient } from './LandingApp'
7+
8+
const root = document.getElementById('root')
9+
if (!root) throw new Error('No root element found')
10+
11+
hydrateRoot(
12+
root,
13+
<React.StrictMode>
14+
<LandingApp client={makeLandingClient()} />
15+
</React.StrictMode>,
16+
)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react'
2+
import { renderToString } from 'react-dom/server'
3+
import { LandingApp, makeLandingClient } from './LandingApp'
4+
5+
/** The landing page's HTML, for scripts/prerender.mjs. */
6+
export function render(): string {
7+
return renderToString(
8+
<React.StrictMode>
9+
<LandingApp client={makeLandingClient()} />
10+
</React.StrictMode>,
11+
)
12+
}

‎server/frontend/src/lib/theme.ts‎

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
import { useEffect, useState } from 'react'
1+
import { useCallback, useEffect, useState, useSyncExternalStore } from 'react'
22

33
export type ThemePref = 'system' | 'light' | 'dark'
44
const KEY = 'vci-theme'
55

6+
// The choice made on this page, which outlasts blocked storage until the page is left.
7+
let chosen: ThemePref | null = null
8+
69
function read(): ThemePref {
10+
if (chosen) return chosen
711
try {
812
const v = localStorage.getItem(KEY)
913
return v === 'light' || v === 'dark' ? v : 'system'
@@ -12,20 +16,34 @@ function read(): ThemePref {
1216
}
1317
}
1418

19+
const listeners = new Set<() => void>()
20+
21+
function subscribe(listener: () => void) {
22+
listeners.add(listener)
23+
return () => {
24+
listeners.delete(listener)
25+
}
26+
}
27+
28+
/** The theme preference. The prerendered landing page renders `system` on the server, and React swaps in the stored
29+
* preference after hydrating (useSyncExternalStore's server snapshot), so the two renders match. The page's colours
30+
* come from the inline script in the HTML, which sets `data-theme` before anything paints. */
1531
export function useTheme(): [ThemePref, (t: ThemePref) => void] {
16-
const [pref, setPref] = useState<ThemePref>(read)
17-
useEffect(() => {
32+
const pref = useSyncExternalStore(subscribe, read, () => 'system' as const)
33+
const set = useCallback((t: ThemePref) => {
34+
chosen = t
1835
const root = document.documentElement
19-
if (pref === 'system') delete root.dataset.theme
20-
else root.dataset.theme = pref
36+
if (t === 'system') delete root.dataset.theme
37+
else root.dataset.theme = t
2138
try {
22-
if (pref === 'system') localStorage.removeItem(KEY)
23-
else localStorage.setItem(KEY, pref)
39+
if (t === 'system') localStorage.removeItem(KEY)
40+
else localStorage.setItem(KEY, t)
2441
} catch {
2542
// Storage blocked: the choice lasts for this page only.
2643
}
27-
}, [pref])
28-
return [pref, setPref]
44+
for (const l of listeners) l()
45+
}, [])
46+
return [pref, set]
2947
}
3048

3149
export function usePersistentState<T extends string>(key: string, initial: T, allowed: readonly T[]) {

‎server/frontend/src/pages/BillingPage.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function BillingPage() {
3232
<div>
3333
<h1>Billing</h1>
3434
<p className="muted">
35-
Credits pay for renders, diffs and AI summaries. Unchanged snapshots and hash hits are free.
35+
Credits pay for rendered pages and diffs. Unchanged snapshots and files VisualCI has seen before are free.
3636
</p>
3737
</div>
3838
</div>

0 commit comments

Comments
 (0)