diff --git a/services/site/script/check-css-output.ts b/services/site/script/check-css-output.ts index acf5757c6dd..e74f59c04f2 100644 --- a/services/site/script/check-css-output.ts +++ b/services/site/script/check-css-output.ts @@ -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) { diff --git a/services/site/src/component/site/arcade3d/not-found-page.css b/services/site/src/component/site/arcade3d/not-found-page.css new file mode 100644 index 00000000000..aafb5752aca --- /dev/null +++ b/services/site/src/component/site/arcade3d/not-found-page.css @@ -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"; diff --git a/services/site/src/component/site/arcade3d/not-found-page.tsx b/services/site/src/component/site/arcade3d/not-found-page.tsx index c3e7ac3343f..c2bd2a19bc6 100644 --- a/services/site/src/component/site/arcade3d/not-found-page.tsx +++ b/services/site/src/component/site/arcade3d/not-found-page.tsx @@ -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" diff --git a/services/site/src/static/render.tsx b/services/site/src/static/render.tsx index c5eaa3b26ac..080feb8d197 100644 --- a/services/site/src/static/render.tsx +++ b/services/site/src/static/render.tsx @@ -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.