From d26277336cf33fcbb6c02dfbdbf02a57cbf44877 Mon Sep 17 00:00:00 2001 From: Adam <2363879+adamdotdevin@users.noreply.github.com> Date: Mon, 9 Nov 2026 16:41:26 -0600 Subject: [PATCH] refactor(site): keep dev-only code out of production pages and group small shared chunks (#62964) --- bun.lock | 5 - services/site/package.json | 1 - services/site/script/check-client-bundle.ts | 49 ++-- services/site/script/fold-settings.ts | 10 +- .../site/src/component/rolling-number.tsx | 58 ----- .../site/arcade3d/not-found-page.tsx | 14 +- .../site/src/component/site/design-mode.tsx | 2 +- .../site/src/component/site/home-order.tsx | 2 + .../site/src/component/site/mono-fonts.ts | 4 +- .../src/component/site/open-source-fork.tsx | 12 +- .../src/component/site/open-source-proof.tsx | 31 +-- .../site/src/component/site/product-data.ts | 220 ----------------- .../src/component/site/product-details.ts | 223 ++++++++++++++++++ .../site/src/component/site/product-page.tsx | 3 +- ...ducts-order.css => products-order.dev.css} | 0 .../src/component/site/products-order.tsx | 2 +- services/site/src/component/site/settings.ts | 2 +- services/site/src/component/site/site.css | 2 +- services/site/src/context/language.tsx | 25 +- .../src/i18n/content/areas/product-details.ts | 3 +- services/site/src/lib/github.ts | 3 +- services/site/src/lib/page-markdown.ts | 3 +- services/site/src/lib/press-content.ts | 5 +- services/site/src/lib/product-markdown.ts | 2 +- services/site/src/routes/index.tsx | 10 +- services/site/vite.config.ts | 20 ++ 26 files changed, 345 insertions(+), 366 deletions(-) delete mode 100644 services/site/src/component/rolling-number.tsx create mode 100644 services/site/src/component/site/product-details.ts rename services/site/src/component/site/{products-order.css => products-order.dev.css} (100%) diff --git a/bun.lock b/bun.lock index cd47895226a..92f42abf769 100644 --- a/bun.lock +++ b/bun.lock @@ -953,7 +953,6 @@ "@textjs/react": "1.6.1", "fuzzysort": "3.1.0", "nitro": "3.0.260903-beta", - "number-flow": "0.6.2", "react": "19.3.1", "react-dom": "19.3.1", "solid-js": "catalog:", @@ -3237,8 +3236,6 @@ "escape-string-regexp": ["escape-string-regexp@4.0.0", "", {}, "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA=="], - "esm-env": ["esm-env@1.2.2", "", {}, "sha512-Epxrv+Nr/CaL4ZcFGPJIYLWFom+YeV1DqMLHJoEd9SYRxNbaFruBwfEX/kkHUJf55j2+TUbmDcmuilbP1TmXHA=="], - "esprima": ["esprima@4.0.1", "", { "bin": { "esparse": "./bin/esparse.js", "esvalidate": "./bin/esvalidate.js" } }, "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A=="], "estree-util-attach-comments": ["estree-util-attach-comments@3.0.0", "", { "dependencies": { "@types/estree": "^1.0.0" } }, "sha512-cKUwm/HUcTDsYh/9FgnuFqpfquUbwIqwKM26BVCGDPVgvaCl/nDCCjUfiLlx6lsEZ3Z4RFxNbOQ60pkaEwFxGw=="], @@ -4035,8 +4032,6 @@ "nth-check": ["nth-check@2.1.1", "", { "dependencies": { "boolbase": "^1.0.0" } }, "sha512-lqjrjmaOoAnWfMmBPL+XNnynZh2+swxiX3WUE0s4yEHI6m+AwrK2UZOimIRl3X/4QctVqS8AiZjFqyOGrMXb/w=="], - "number-flow": ["number-flow@0.6.2", "", { "dependencies": { "esm-env": "^1.1.4" } }, "sha512-MCnImG4Q5vPwhSXnov56nOuyyKn6LC+Qd7II1UiKc+ACRtug5iAtn0+CwXNxM38AC5lSowEY+oYEtZX2qMnUyw=="], - "object-assign": ["object-assign@4.1.1", "", {}, "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg=="], "object-hash": ["object-hash@2.2.0", "", {}, "sha512-gScRMn0bS5fH+IuwyIFgnh9zBdo4DV+6GhygmWM9HyNJSgS0hScp1f5vjtm7oIIOiT9trXrShAkLFSc2IqKNgw=="], diff --git a/services/site/package.json b/services/site/package.json index 72b189d6dc7..0e348c6304a 100644 --- a/services/site/package.json +++ b/services/site/package.json @@ -34,7 +34,6 @@ "@textjs/react": "1.6.1", "fuzzysort": "3.1.0", "nitro": "3.0.260903-beta", - "number-flow": "0.6.2", "react": "19.3.1", "react-dom": "19.3.1", "solid-js": "catalog:", diff --git a/services/site/script/check-client-bundle.ts b/services/site/script/check-client-bundle.ts index ca557725ac9..4dcbbe71cb4 100644 --- a/services/site/script/check-client-bundle.ts +++ b/services/site/script/check-client-bundle.ts @@ -64,29 +64,36 @@ console.log( // Each page's budget in kB, gzipped: what it was when last measured, plus a kB of room. Lower a // budget when a page gets lighter; a page without one fails until it has one. const budgets: Record = { - "[...404].tsx": 103.1, - "brand/index.tsx": 106.9, - "changelog/[tag].tsx": 100.1, - "changelog/index.tsx": 99.3, - "desktop.tsx": 126.9, - "devices.tsx": 50.6, - "product/browse.tsx": 105.7, - "font/index.tsx": 120.2, - "ide.tsx": 126.9, - "index.tsx": 117.2, - "legal/index.tsx": 150.7, - "legal/privacy-policy/index.tsx": 140.3, - "legal/terms-of-service/index.tsx": 135.6, - "mini.tsx": 126.9, - "mobile.tsx": 126.9, - "press/index.tsx": 111.6, - "product/index.tsx": 114.3, - "sdk.tsx": 126.9, - "terminal.tsx": 126.9, - "video-editor/index.tsx": 49, + "[...404].tsx": 100.3, + "brand/index.tsx": 103.7, + "changelog/[tag].tsx": 97.2, + "changelog/index.tsx": 96.4, + "desktop.tsx": 125.7, + "devices.tsx": 53.1, + "product/browse.tsx": 102.1, + "font/index.tsx": 118, + "ide.tsx": 125.7, + "index.tsx": 112.8, + "legal/index.tsx": 147.6, + "legal/privacy-policy/index.tsx": 137.1, + "legal/terms-of-service/index.tsx": 132.4, + "mini.tsx": 125.7, + "mobile.tsx": 125.7, + "press/index.tsx": 111.1, + "product/index.tsx": 110.4, + "sdk.tsx": 125.7, + "terminal.tsx": 125.7, + "video-editor/index.tsx": 51.5, } -type Chunk = { file: string; imports?: string[] } +type Chunk = { file: string; name?: string; imports?: string[]; css?: string[] } const manifest: Record = await Bun.file(path.join(root, ".vite/manifest.json")).json() +// Most pages load the shared "common" chunk (vite.config.ts), so a stylesheet in it would block +// their first paint too. +const commonCss = Object.values(manifest).flatMap((chunk) => (chunk.name === "common" ? (chunk.css ?? []) : [])) +if (commonCss.length) { + console.error(`check-client-bundle: the common chunk brings stylesheets to every page: ${commonCss.join(", ")}`) + process.exit(1) +} const sizes = new Map() const gzipped = async (file: string) => { const known = sizes.get(file) diff --git a/services/site/script/fold-settings.ts b/services/site/script/fold-settings.ts index eb5daff586f..e29bbb0e36d 100644 --- a/services/site/script/fold-settings.ts +++ b/services/site/script/fold-settings.ts @@ -4,7 +4,8 @@ // reads every `siteSettings.` as the default's literal, `designMode()` as false and // `import.meta.env.DEV` as false, then folds what that decides (``, ``/``, // ternaries, `&&`/`||`, `if`), so the branches production never takes, and everything only they -// import, leave the bundle. The server and the browser builds fold the same way, so hydration keys +// import, leave the bundle. It also drops the data-design and data-design-copy attributes, which +// only Design mode reads. The server and the browser builds fold the same way, so hydration keys // still match. The development server is untouched. import { existsSync } from "node:fs" import { mkdir, readFile, writeFile } from "node:fs/promises" @@ -41,7 +42,7 @@ const designModules = [ const ogModule = path.join(root, "lib/og.ts") const ogCards = path.join(root, "lib/og-images.json") const candidate = - /\b(siteSettings|siteSettingsDefaults|setSiteSetting|designMode|designEditing|designCopy|ogImage|import\.meta\.env\.(DEV|PROD))\b/ + /\b(siteSettings|siteSettingsDefaults|setSiteSetting|designMode|designEditing|designCopy|ogImage|data-design|import\.meta\.env\.(DEV|PROD))\b/ export function foldSettingsForProduction(): Plugin { let cards: Record = {} @@ -154,6 +155,11 @@ function foldSettings(file: string, cards: Record, trimImports: let liveStore: types.Identifier | undefined const store = () => (liveStore ??= program.scope.generateUidIdentifier("live")) program.traverse({ + JSXAttribute(attribute) { + const name = attribute.node.name + if (types.isJSXIdentifier(name) && ["data-design", "data-design-copy"].includes(name.name)) + attribute.remove() + }, MetaProperty(meta) { const env = meta.parentPath.parentPath if (!env?.isMemberExpression() || !meta.parentPath.isMemberExpression()) return diff --git a/services/site/src/component/rolling-number.tsx b/services/site/src/component/rolling-number.tsx deleted file mode 100644 index df1af6ca20c..00000000000 --- a/services/site/src/component/rolling-number.tsx +++ /dev/null @@ -1,58 +0,0 @@ -import NumberFlow from "number-flow" -import { continuous } from "number-flow/plugins" -import { createEffect, onCleanup, onMount } from "solid-js" - -export function RollingNumber(props: { - value: number - target: number - timing: () => { duration: number; easing: string; spinEasing: string } -}) { - let root!: HTMLSpanElement - // Keep the server-rendered text stable while the custom element owns its contents. - const initial = props.value.toLocaleString() - const growing = props.target.toLocaleString().length > initial.length - - onMount(() => { - if (new Intl.NumberFormat().resolvedOptions().numberingSystem !== "latn") { - createEffect(() => { - root.textContent = props.value.toLocaleString() - }) - return - } - - const flow = new NumberFlow() - flow.format = { useGrouping: true, maximumFractionDigits: 0 } - flow.trend = 1 - if (growing) flow.plugins = [continuous] - flow.opacityTiming = { duration: 180, easing: "ease-out" } - const motion = window.matchMedia("(prefers-reduced-motion: reduce)") - const updateMotion = () => { - flow.animated = !motion.matches - } - updateMotion() - motion.addEventListener("change", updateMotion) - onCleanup(() => motion.removeEventListener("change", updateMotion)) - root.replaceChildren(flow) - createEffect(() => { - const value = props.value - if (flow.value === value) return - const timing = props.timing() - flow.transformTiming = { duration: timing.duration, easing: timing.easing } - flow.spinTiming = { - duration: timing.duration, - easing: growing ? "cubic-bezier(0.45, 0, 0.55, 1)" : timing.spinEasing, - } - flow.update(value) - }) - }) - - return ( - - {initial} - - ) -} 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 86cf2ea106c..c216d105154 100644 --- a/services/site/src/component/site/arcade3d/not-found-page.tsx +++ b/services/site/src/component/site/arcade3d/not-found-page.tsx @@ -13,11 +13,11 @@ import { ogImage } from "~/lib/og" * The not-found page: the real 404 route and its previews render this same tree, so the preview's * HTML (which the dev server serves for bad URLs) hydrates cleanly as the 404 route. Settings › * 404 arcade › Mode picks the version (layers by default; settings.ts loads the saved mode after - * hydration, so the server's layers markup always hydrates); `only3D` (the /dev/404-3d preview) - * always shows the three.js one. Phones get the layers stack with its still light and the - * hybrid's phone flow (arcade/phone.ts), which loads no WebGL there. + * hydration, so the server's layers markup always hydrates). Phones get the layers stack with its + * still light and the hybrid's phone flow (arcade/phone.ts), which loads no WebGL there. Each mode's + * setting comes first in its `when`, so production folds the modes it never shows out of the bundle. */ -export function NotFoundPage(props: { title: string; status: number; only3D?: boolean }) { +export function NotFoundPage(props: { title: string; status: number }) { const [phone, setPhone] = createSignal(false) onMount(() => setPhone(isPhone())) return ( @@ -36,13 +36,13 @@ export function NotFoundPage(props: { title: string; status: number; only3D?: bo {/* Before anything is parsed, so the saved tone applies from the first paint. */}