fix(site): fetch the docs' status bars from a 79-byte endpoint when the footer comes near (#62962)

This commit is contained in:
Adam
2026-11-09 16:29:58 -06:00
committed by GitHub
Unverified
parent 20c056d842
commit 6ee519e071
4 changed files with 40 additions and 25 deletions
+1 -1
View File
@@ -16,7 +16,7 @@
- Pages are plain HTML in the site's docs layout (`layouts/DocsLayout.tsx`: the root attributes production renders, the logo and section lockup, the section nav, the article, search and Contents, and the site's footer). They render the site's own components on the server (`component/site/`: `DocsLockup`, `CodeFrame`, `FileTree`, `HeadingLink`, `OnThisPage`, `ContentsMenu`, the phone menu, the footer's parts) with the English strings, and never hydrate. Use those components instead of copying their markup; a component the docs need to drive from `client.ts` renders its state as attributes (`hidden`, `aria-expanded`, `data-state`, `data-code`).
- A page links its stylesheet, `styles/docs.css` (the site's stylesheets, `docs-variants.css` and the docs' own base rules, built with the site's production CSS plugins), and the one browser script, `client.ts`. They never load the site's built files, and the site's pages never load the docs'.
- Everything a page loads lives under `/docs` (the stylesheet, script and fonts are built to `/docs/_build`, images are in `public/docs/assets`), so the docs never depend on the site's files and never collide with them (the site's own build files are at `/_build`). The build fails otherwise.
- Interactive pieces (the theme switch, copy buttons, heading links, tabs, the lockup's menus, the phone menus, the Contents rail, search, the status bars) are delegated listeners in `client.ts`, keyed on the attributes the components render. Don't add Solid state or effects to docs components; they only run on the server. `script/build.ts` fails when `client.ts` is over 6.5 kB gzipped or `docs.css` over 28 kB.
- Interactive pieces (the theme switch, copy buttons, heading links, tabs, the lockup's menus, the phone menus, the Contents rail, search, the status bars) are delegated listeners in `client.ts`, keyed on the attributes the components render. Don't add Solid state or effects to docs components; they only run on the server. `script/build.ts` fails when `client.ts` is over 11 kB gzipped or `docs.css` over 29 kB.
- `client.ts` also reports the page to the Console's funnel, as the site's pages do (the site's `AGENTS.md`, "Funnel"). Its config (`lib/funnel-config.ts`) is built in, since a chunk would bring Vite's preload helper into every page. Code blocks are `data-funnel-copy` regions and tabs carry `data-funnel`; search reports counts, never the query.
- The theme is the site's (`opencode-theme`, the site's pre-paint script), inline in `layouts/DocsLayout.tsx` so pages never flash. Navigation is ordinary page loads, made instant by Speculation Rules and cross-document view transitions.
- `vite.ts` compiles MDX the way Astro's MDX integration did (GitHub-flavoured Markdown, smart punctuation, Shiki with the github-light and github-dark themes, GitHub-style heading ids). `rehype-shiki.ts` puts each fenced block in the site's `CodeFrame` (a terminal for shell, `FileTree` for a `├──` tree, the file's icon for a `title="file"`), and `rehype-headings.ts` wraps h2 and h3 in `HeadingLink`.
+23 -22
View File
@@ -390,13 +390,8 @@ nav.addEventListener("scroll", fade, { passive: true })
// The sidebar leaves with the article at the page's end, but the logo and lockup stay fixed
// (site.css): while it is on its way out its items pass under them, and data-under fades them there,
// as Site does on the site's own pages.
// as Site does on the site's own pages. The scroll spy below sets it, in the same frame.
const sidebar = nav.parentElement!
function under() {
sidebar.toggleAttribute("data-under", sidebar.getBoundingClientRect().top < -0.5)
}
window.addEventListener("scroll", under, { passive: true })
under()
// The Contents rail and its phone bar mark the section being read: the last heading past a third of
// the window, or at the end of the page the one the address names (else the last in view). The rail
@@ -451,13 +446,15 @@ function nameSection(title: string, animate: boolean) {
let spied = ""
function spy() {
sidebar.toggleAttribute("data-under", sidebar.getBoundingClientRect().top < -0.5)
const tops = headings.map((heading) => ({ id: heading.id, top: heading.getBoundingClientRect().top }))
const visible = tops.filter((item) => item.top >= 0 && item.top < innerHeight)
const bottom = scrollY + innerHeight >= html.scrollHeight - 2
const end = visible.find((item) => `#${item.id}` === decodeURIComponent(location.hash)) ?? visible.at(-1)
const id = (bottom && end ? end : tops.filter((item) => item.top <= innerHeight / 3).at(-1))?.id ?? tops[0]?.id
// Desktop hides the Contents bar (display: none), so it has no offsetParent and nothing to measure.
const contents = $<HTMLElement>("[data-component=contents-menu]")
if (contents)
if (contents?.offsetParent)
contents.toggleAttribute(
"data-stuck",
scrollY > 0 && contents.getBoundingClientRect().top <= parseFloat(getComputedStyle(contents).top) + 0.5,
@@ -646,7 +643,8 @@ function choose(option: HTMLAnchorElement) {
}
// The status bars, as the site's footer shows them: the last five 3-hour windows by their worst
// service, then the live status. Kept a minute in sessionStorage, since every docs page is a full load.
// service, then the live status (the site's /status.json). Asked for once the footer comes near, and
// kept five minutes in sessionStorage, since every docs page is a full load.
type Status = "operational" | "degraded" | "outage" | "unknown"
const headlines = {
operational: "All systems operational",
@@ -654,7 +652,6 @@ const headlines = {
outage: "Service disruption",
unknown: "Status unavailable",
}
const rank = { unknown: 0, operational: 1, degraded: 2, outage: 3 }
function showStatus(bars: Status[]) {
const link = $("[data-component=status]")
if (!link) return
@@ -672,17 +669,21 @@ function showStatus(bars: Status[]) {
}
const saved = JSON.parse(sessionStorage.getItem("docs-status-bars") ?? "null") as { bars: Status[]; at: number } | null
if (saved?.bars?.length === 6) showStatus(saved.bars)
const idle = (run: () => void) => ("requestIdleCallback" in window ? requestIdleCallback(run) : setTimeout(run, 1500))
if (!saved || Date.now() - saved.at > 60_000)
idle(() =>
fetch("/status/api/status", { signal: AbortSignal.timeout(10_000) })
.then((response) => (response.ok ? response.json() : Promise.reject()))
.then((body: { status: Status; history: { services: Record<string, Status> }[] }) => {
const worst = (list: Status[]) => list.reduce<Status>((a, b) => (rank[b] > rank[a] ? b : a), "unknown")
const bars = [...body.history.slice(-5).map((entry) => worst(Object.values(entry.services))), body.status]
if (bars.length !== 6 || !bars.every((bar) => bar in rank)) return
sessionStorage.setItem("docs-status-bars", JSON.stringify({ bars, at: Date.now() }))
showStatus(bars)
})
.catch(() => undefined),
const footerStatus = $("[data-component=status]")
if (footerStatus && (!saved || Date.now() - saved.at > 300_000)) {
const near = new IntersectionObserver(
(entries) => {
if (!entries[0].isIntersecting) return
near.disconnect()
fetch("/status.json", { signal: AbortSignal.timeout(10_000) })
.then((response) => (response.ok ? response.json() : Promise.reject()))
.then((body: { bars: Status[] }) => {
sessionStorage.setItem("docs-status-bars", JSON.stringify({ bars: body.bars, at: Date.now() }))
showStatus(body.bars)
})
.catch(() => undefined)
},
{ rootMargin: "100% 0px" },
)
near.observe(footerStatus)
}
+3 -2
View File
@@ -7,8 +7,9 @@ const rank: Record<ServiceStatus, number> = { unknown: 0, operational: 1, degrad
// The public status page API. It sends no CORS headers, so this runs on the server. Every page's
// footer shows it, so it is reused for a minute and refreshed in the background (lib/edge-cache.ts):
// a render waits at most 300 ms, else the footer shows its usual placeholder bars.
const bars = staleValue<ServiceStatus[]>({
// a render waits at most 300 ms, else the footer shows its usual placeholder bars. The docs' static
// pages read the same bars from /status.json (routes/status.json.ts).
export const bars = staleValue<ServiceStatus[]>({
key: "status/bars",
freshFor: 60_000,
wait: 300,
+13
View File
@@ -0,0 +1,13 @@
import { bars } from "~/lib/status"
// The footer's status bars (lib/status.ts) for pages that render without them: the V2 docs are
// static HTML, so their script asks here once the footer comes near (src/docs/client.ts). About
// 100 bytes, where the status page's own snapshot is about 90 kB.
export async function GET() {
const value = (await bars()).value
if (!value) return new Response(null, { status: 503, headers: { "Cache-Control": "no-store" } })
return Response.json(
{ bars: value },
{ headers: { "Cache-Control": "public, max-age=60, stale-while-revalidate=300" } },
)
}