Skip to content

Commit 23a40da

Browse files
authored
fix(site): give the not-found page one stylesheet of what it renders (#63169)
1 parent 23eab68 commit 23a40da

4 files changed

Lines changed: 27 additions & 6 deletions

File tree

‎services/site/script/check-css-output.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
// the production page silently differs from the development server. vite.config.ts's cssTarget
66
// keeps light-dark() native; this guards against that target being lowered again.
77
//
8-
// It also fails when a stylesheet outgrows its budget (gzipped): the shell's, which every page links
9-
// and holds up its first paint for, and each of the others, a group of pages' or one that loads on
10-
// demand (script/stylesheet-groups.ts).
8+
// It also fails when a stylesheet outgrows its budget (gzipped): the shell's, which every page but the
9+
// not-found page links and holds up its first paint for, the not-found page's, which it links alone,
10+
// and each of the others, a group of pages' or one that loads on demand (script/stylesheet-groups.ts).
1111
// Run after `vite build`, optionally with the output directory: `bun script/check-css-output.ts .output`.
1212
import path from "node:path"
1313
import { Glob } from "bun"
1414

1515
const root = path.resolve(process.argv[2] ?? path.join(import.meta.dir, "..", ".output"), "public")
16-
const budgets = { shell: 27.5 * 1024, other: 10.5 * 1024 }
16+
const budgets = { shell: 27.5 * 1024, notFound: 26 * 1024, other: 10.5 * 1024 }
1717
const lowered: string[] = []
1818
const over: string[] = []
1919
const shells: string[] = []
@@ -24,7 +24,8 @@ for await (const file of new Glob("**/*.css").scan(root)) {
2424
const shell = path.basename(file).startsWith("shell-")
2525
if (shell) shells.push(file)
2626
const size = Bun.gzipSync(css, { level: 9 }).length
27-
const budget = shell ? budgets.shell : budgets.other
27+
const notFound = path.basename(file).startsWith("not-found-")
28+
const budget = shell ? budgets.shell : notFound ? budgets.notFound : budgets.other
2829
if (size > budget) over.push(`${file} ${(size / 1024).toFixed(1)} kB (budget ${(budget / 1024).toFixed(1)} kB)`)
2930
}
3031
if (lowered.length > 0) {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* The not-found page has no site frame, so in production it links this stylesheet alone, not the
2+
shell's (src/static/render.tsx). It carries its own copy of the shell's stylesheets it renders, in
3+
the shell's order: the fonts, the tokens and resets, its tools' (search, tooltips, the phone menu)
4+
own styles, and the site's stylesheet they sit in. Then the arcade's, from its components. */
5+
@import "../../../style/fonts.css";
6+
@import "../../../style/index.css";
7+
@import "../nav-order.css";
8+
@import "../github-link.css";
9+
@import "../phone-menu.css";
10+
@import "../search.css";
11+
@import "../tooltip.css";
12+
@import "../site.css";
13+
@import "../rtl.css";
14+
@import "../locale-type.css";

‎services/site/src/component/site/arcade3d/not-found-page.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Ahead of the arcade's own stylesheets, as the shell is on other pages.
2+
import "./not-found-page.css"
13
import { Meta, Title } from "@solidjs/meta"
24
import { HttpStatusCode } from "@solidjs/start"
35
import { createSignal, Match, onMount, Switch } from "solid-js"

‎services/site/src/static/render.tsx‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ export const staticPages: Middleware = async (_event, next) => {
7575
pattern && pages.find((route) => route.page && route.path.replace(/(.)\/$/, "$1") === pattern)?.$component?.import
7676
if (!load) return next()
7777
const page = await load()
78-
const styles = stylesheets(["src/entry-client.tsx", page.id$$ ?? ""])
78+
const shell = stylesheets(["src/entry-client.tsx"])
79+
const own = stylesheets([page.id$$ ?? ""]).filter((file) => !shell.includes(file))
80+
// The not-found page has no frame: its own stylesheet copies what it needs of the shell's
81+
// (arcade3d/not-found-page.css).
82+
const styles = pattern === "/*404" ? own : [...shell, ...own]
7983
const pass: StaticPass = { collect: true, pending: [], values: [], next: 0 }
8084
event.locals.staticPass = pass
8185
// HttpStatusCode (the changelog's missing releases) keeps its status only on a completed render.

0 commit comments

Comments
 (0)