fix(site): give the not-found page one stylesheet of what it renders (#63169)

This commit is contained in:
Adam
2026-11-10 12:20:39 -06:00
committed by GitHub
Unverified
parent 23eab68a3c
commit 23a40da6c9
4 changed files with 27 additions and 6 deletions
+6 -5
View File
@@ -5,15 +5,15 @@
// the production page silently differs from the development server. vite.config.ts's cssTarget
// keeps light-dark() native; this guards against that target being lowered again.
//
// It also fails when a stylesheet outgrows its budget (gzipped): the shell's, which every page links
// and holds up its first paint for, and each of the others, a group of pages' or one that loads on
// demand (script/stylesheet-groups.ts).
// It also fails when a stylesheet outgrows its budget (gzipped): the shell's, which every page but the
// not-found page links and holds up its first paint for, the not-found page's, which it links alone,
// and each of the others, a group of pages' or one that loads on demand (script/stylesheet-groups.ts).
// Run after `vite build`, optionally with the output directory: `bun script/check-css-output.ts .output`.
import path from "node:path"
import { Glob } from "bun"
const root = path.resolve(process.argv[2] ?? path.join(import.meta.dir, "..", ".output"), "public")
const budgets = { shell: 27.5 * 1024, other: 10.5 * 1024 }
const budgets = { shell: 27.5 * 1024, notFound: 26 * 1024, other: 10.5 * 1024 }
const lowered: string[] = []
const over: string[] = []
const shells: string[] = []
@@ -24,7 +24,8 @@ for await (const file of new Glob("**/*.css").scan(root)) {
const shell = path.basename(file).startsWith("shell-")
if (shell) shells.push(file)
const size = Bun.gzipSync(css, { level: 9 }).length
const budget = shell ? budgets.shell : budgets.other
const notFound = path.basename(file).startsWith("not-found-")
const budget = shell ? budgets.shell : notFound ? budgets.notFound : budgets.other
if (size > budget) over.push(`${file} ${(size / 1024).toFixed(1)} kB (budget ${(budget / 1024).toFixed(1)} kB)`)
}
if (lowered.length > 0) {
@@ -0,0 +1,14 @@
/* The not-found page has no site frame, so in production it links this stylesheet alone, not the
shell's (src/static/render.tsx). It carries its own copy of the shell's stylesheets it renders, in
the shell's order: the fonts, the tokens and resets, its tools' (search, tooltips, the phone menu)
own styles, and the site's stylesheet they sit in. Then the arcade's, from its components. */
@import "../../../style/fonts.css";
@import "../../../style/index.css";
@import "../nav-order.css";
@import "../github-link.css";
@import "../phone-menu.css";
@import "../search.css";
@import "../tooltip.css";
@import "../site.css";
@import "../rtl.css";
@import "../locale-type.css";
@@ -1,3 +1,5 @@
// Ahead of the arcade's own stylesheets, as the shell is on other pages.
import "./not-found-page.css"
import { Meta, Title } from "@solidjs/meta"
import { HttpStatusCode } from "@solidjs/start"
import { createSignal, Match, onMount, Switch } from "solid-js"
+5 -1
View File
@@ -75,7 +75,11 @@ export const staticPages: Middleware = async (_event, next) => {
pattern && pages.find((route) => route.page && route.path.replace(/(.)\/$/, "$1") === pattern)?.$component?.import
if (!load) return next()
const page = await load()
const styles = stylesheets(["src/entry-client.tsx", page.id$$ ?? ""])
const shell = stylesheets(["src/entry-client.tsx"])
const own = stylesheets([page.id$$ ?? ""]).filter((file) => !shell.includes(file))
// The not-found page has no frame: its own stylesheet copies what it needs of the shell's
// (arcade3d/not-found-page.css).
const styles = pattern === "/*404" ? own : [...shell, ...own]
const pass: StaticPass = { collect: true, pending: [], values: [], next: 0 }
event.locals.staticPass = pass
// HttpStatusCode (the changelog's missing releases) keeps its status only on a completed render.