Skip to content

Commit 2388946

Browse files
chore(size): add page: hackernews scenario (examples/hackernews client entry)
The client entry of examples/hackernews as its vite build ships it, through the harness: the generated entry (installServerComponents + hydrate of the plugin's document shell and default error boundary) around the example's own src/, compiled hydratable by the measured checkout's compiler, with the router resolved the way the example's build resolves it (the solid export condition: dist/index.jsx + per-module output), so the router's server-form fallback — and action behind it — is the lazy chunk it is in a Vite build. Harness: bundle.mjs compiles .tsx like .jsx (Rolldown strips the types the JSX compiler leaves), runs the native "use server" directive pass in client mode under a scenario's compile.serverFunctions root, loads .css as empty, and attributes examples/ modules as app. No other scenario's number moved (every recorded minified matches to the byte). Measured locally: 176,581 B minified / 54,557 B brotli; cap at measured + 10 B rounded up to 0.01 KB, to be confirmed against CI. Co-authored-by: Cursor <[email protected]>
1 parent d231b99 commit 2388946

6 files changed

Lines changed: 278 additions & 15 deletions

File tree

‎scripts/size/README.md‎

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ compiled-template scenarios — a compiled floor and a JSX todo app in CSR and
88
hydrating form — the frames client as a package, two server-component PAGES:
99
base and live, their two compiled counterparts — the same pages as JSX with
1010
the templates a real page has — the same two hand-written pages under
11-
`@solidjs/router`, and two server-entry floors: `getRequestEvent`/`isServer` and
11+
`@solidjs/router`, the client entry of `examples/hackernews` as the example's
12+
build ships it, and two server-entry floors: `getRequestEvent`/`isServer` and
1213
`renderToString`) with hard brotli limits on the eager entry chunk. CI fails
1314
when a scenario exceeds its limit and grew more than a small minified
1415
allowance over its base (see [The gate](#the-gate)) — that means tree-shaking regressed, or a deliberate
@@ -175,6 +176,41 @@ pages' rendered `web.js`). The hand-written pages stay as the frames-only
175176
floor (their caps are the frozen ones); the compiled pages are the number a
176177
real page moves by.
177178

179+
## The example scenario
180+
181+
`page: hackernews` bundles a real application: the client entry of
182+
`examples/hackernews` (the server-components HackerNews) as its `vite build`
183+
ships it. The fixture, `fixtures/hackernews/entry.jsx`, is
184+
`@solidjs/vite-plugin`'s generated client entry written out —
185+
`installServerComponents()`, then `hydrate()` of the plugin's document shell
186+
and default error boundary (the other two files beside it) around the app —
187+
and the app is the example's own `src/`, reached unchanged through its `~`
188+
alias and compiled hydratable like the other compiled scenarios. Two things
189+
the harness does for it that the plugin does in a Vite build: `.tsx`
190+
compiles like `.jsx`, with the type annotations the JSX compiler leaves in
191+
place stripped by Rolldown as Vite strips them, and the example's
192+
`"use server"` modules go through the native directive pass in client mode
193+
(`compile.serverFunctions` names the example's root), so each exported view
194+
becomes a `createServerReference` proxy and the server-only code is gone —
195+
the example's `api.ts` is its whole server-function surface. Its `.css`
196+
import loads as an empty module (Vite extracts it to a stylesheet). The
197+
router is this directory's pinned `@solidjs/router`, not the version the
198+
example's own `package.json` installs under `examples/hackernews/node_modules`
199+
(aliased, so the scenario does not move with the workspace install), and it
200+
is resolved the way the example's build resolves it: the `solid` export
201+
condition `@solidjs/vite-plugin` puts first — `dist/index.jsx` plus the
202+
router's per-module output, its JSX compiled by the measured checkout's
203+
compiler like the app's own. That is a different artifact from the flat
204+
`dist/index.js` the two router scenarios resolve (the `default` condition,
205+
the fallback for consumers without a Solid compiler): the flat bundle is
206+
built with `inlineDynamicImports`, so `data/events`' lazy
207+
`import("./serverForms")` — the server-form fallback, and through it
208+
`action` and the flight consumer — is eager there and a lazy chunk here,
209+
as it is in a Vite build. The example's modules report as the `app`
210+
package; the router's as `other`. Not a floor: an inline cap. The example
211+
itself is not changed for the scenario; if it changes, the scenario moves,
212+
which is the point.
213+
178214
## Frozen floor caps
179215

180216
The three floor scenarios — the signals floor, the simple app, and the
@@ -250,3 +286,9 @@ breaks.
250286
`--minified-only` mode from CI's measurement of `next` @ fff1615ee (Size
251287
run 37443080193); every cap unchanged. The base comparison remains the fail-safe
252288
for a cap without a recorded minified.
289+
- **2026-10-07 — the example scenario.** `page: hackernews` bundles
290+
`examples/hackernews`'s client entry (above). `bundle.mjs` compiles `.tsx`
291+
as well as `.jsx`, runs the `"use server"` directive pass in client mode
292+
under a scenario's `compile.serverFunctions` root, loads `.css` as empty,
293+
and attributes an example's modules as `app`. No other scenario's number
294+
moved.

‎scripts/size/bundle.mjs‎

Lines changed: 81 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,23 @@
3838
// module it reaches are compiled; the output is handed to Rolldown as plain
3939
// JS. The compiler sees only each file's basename, so no host path can reach
4040
// the output and the numbers are the same on every machine.
41+
//
42+
// Example applications (2026-10-07): a compiled scenario may bundle one of
43+
// the repo's examples/ as an application ships it — its `.tsx` sources
44+
// (compiled like `.jsx`; the type annotations the JSX compiler leaves in
45+
// place are stripped by Rolldown, as Vite strips them) and, with
46+
// `compile.serverFunctions` naming the example's root, its `"use server"`
47+
// modules as the client build sees them: the native directive pass in
48+
// client mode replaces each exported function with a `createServerReference`
49+
// proxy and drops the server-only body and its imports, exactly what
50+
// @solidjs/vite-plugin does before the JSX compile. Function IDs hash the
51+
// root-relative path, so that output is host-independent too. A `.css`
52+
// import loads as an empty module (Vite extracts it to a stylesheet; none
53+
// of it is in the script). An example's own modules are the `app` package.
4154

4255
import { readFileSync } from "node:fs";
4356
import { createRequire } from "node:module";
44-
import { basename, dirname, isAbsolute, join, relative } from "node:path";
57+
import { basename, dirname, extname, isAbsolute, join, relative, sep } from "node:path";
4558
import { fileURLToPath } from "node:url";
4659
import { brotliCompressSync, constants } from "node:zlib";
4760
import { rolldown } from "rolldown";
@@ -61,6 +74,13 @@ export const packagesRoot = process.env.SIZE_PACKAGES_ROOT
6174
// package in every report: the compiled app's own bytes, separable from
6275
// the runtime's.
6376
export const fixturesRoot = join(here, "fixtures");
77+
// The repo's example applications; a `page: <example>` scenario bundles one
78+
// through its fixture entry. Like fixtures/, an example's own modules are
79+
// the `app` package. The example comes from this checkout even when
80+
// SIZE_PACKAGES_ROOT measures another's dists: the compare job measures the
81+
// base's runtime under the head's harness and fixtures, and the example is
82+
// a fixture here.
83+
export const examplesRoot = join(here, "..", "..", "examples");
6484

6585
const resolvePath = p =>
6686
p.startsWith("../../packages/")
@@ -73,15 +93,48 @@ const resolvePath = p =>
7393
// (Linux CI and macOS alike), falling back to the installed platform
7494
// package — so no path here depends on the host.
7595
let compiler;
76-
const compile = (id, hydratable) => {
77-
compiler ??= require(join(packagesRoot, "compiler", "index.js"));
78-
return compiler.transform(readFileSync(id, "utf8"), {
96+
const loadCompiler = () => (compiler ??= require(join(packagesRoot, "compiler", "index.js")));
97+
const compile = (code, id, hydratable) =>
98+
loadCompiler().transform(code, {
7999
filename: basename(id),
80100
generate: "dom",
81101
hydratable,
82102
dev: false
83103
}).code;
104+
105+
// The `"use server"` pass, client mode, with the Vite plugin's defaults: the
106+
// runtime is `@solidjs/web/server-functions` (the page alias routes it to
107+
// the client dist), the ID hash is of the path relative to `root`, the
108+
// production posture. A module without the directive comes back `valid:
109+
// false` and is left as it is; the substring test is the plugin's own fast
110+
// path.
111+
const SERVER_FUNCTIONS_RUNTIME = "@solidjs/web/server-functions";
112+
const compileDirectives = (code, id, root) => {
113+
if (!code.includes("use server")) return code;
114+
const result = loadCompiler().transformDirectives(code, {
115+
filename: id,
116+
root,
117+
mode: "client",
118+
env: "production",
119+
register: { kind: "named", name: "registerServerReference", source: SERVER_FUNCTIONS_RUNTIME },
120+
create: { kind: "named", name: "createServerReference", source: SERVER_FUNCTIONS_RUNTIME }
121+
});
122+
return result.valid ? result.code : code;
123+
};
124+
125+
// What the compile plugin loads itself: JSX/TSX everywhere (the compiler),
126+
// and under the server-functions root every script module (the directive
127+
// pass; the plugin's include is `src/**/*.{jsx,tsx,ts,js,mjs,cjs}`). The
128+
// output's module type tells Rolldown whether types remain to strip.
129+
const SCRIPT_TYPES = {
130+
".js": "js",
131+
".mjs": "js",
132+
".cjs": "js",
133+
".jsx": "js",
134+
".ts": "ts",
135+
".tsx": "ts"
84136
};
137+
const JSX_EXTENSIONS = new Set([".jsx", ".tsx"]);
85138

86139
export const brotli = buf =>
87140
brotliCompressSync(buf, { params: { [constants.BROTLI_PARAM_QUALITY]: 11 } }).length;
@@ -102,17 +155,19 @@ const ENTRY = "\0scenario-entry";
102155

103156
/**
104157
* Maps a module id to the package that shipped it; a compiled scenario's own
105-
* sources (fixtures/) are "app", anything else outside packages/ is "other".
158+
* sources (fixtures/, and the examples/ an example scenario bundles) are
159+
* "app", anything else outside packages/ is "other".
106160
*/
107161
export function packageOf(id) {
108-
if (id.startsWith(fixturesRoot)) return "app";
162+
if (id.startsWith(fixturesRoot + sep) || id.startsWith(examplesRoot + sep)) return "app";
109163
const m = id.match(/packages\/([^/]+)\/(?:([^/]+)\/)?dist\//);
110164
if (!m) return "other";
111165
const [, pkg, sub] = m;
112166
return sub && sub !== "dist" ? `${pkg}/${sub}` : pkg;
113167
}
114168
export function moduleOf(id) {
115-
if (id.startsWith(fixturesRoot)) return `app:${relative(fixturesRoot, id)}`;
169+
if (id.startsWith(fixturesRoot + sep)) return `app:${relative(fixturesRoot, id)}`;
170+
if (id.startsWith(examplesRoot + sep)) return `app:${relative(join(here, "..", ".."), id)}`;
116171
return id.replace(/^.*packages\//, "").replace(/\/dist\/(prod\/|observe\/)?/, ":");
117172
}
118173

@@ -145,17 +200,29 @@ export async function bundle(scenario) {
145200
resolveId: id => (id === ENTRY ? ENTRY : null),
146201
load: id => (id === ENTRY ? synthetic : null)
147202
},
148-
// Compiled scenarios: every `.jsx` module is compiled before Rolldown
149-
// parses it, and arrives as plain JS so Rolldown's own JSX transform
150-
// never runs on it.
203+
// Compiled scenarios: every `.jsx`/`.tsx` module is compiled before
204+
// Rolldown parses it, and arrives as JS (or type-annotated JS, which
205+
// Rolldown strips) so Rolldown's own JSX transform never runs on it.
206+
// Under `compile.serverFunctions` the directive pass runs first.
151207
...(scenario.compile
152208
? [
153209
{
154210
name: "scenario-compile",
155-
load: id =>
156-
id.endsWith(".jsx")
157-
? { code: compile(id, !!scenario.compile.hydratable), moduleType: "js" }
158-
: null
211+
load: id => {
212+
if (id.endsWith(".css")) return { code: "", moduleType: "empty" };
213+
const ext = extname(id);
214+
const type = SCRIPT_TYPES[ext];
215+
const jsx = JSX_EXTENSIONS.has(ext);
216+
const root = scenario.compile.serverFunctions
217+
? resolvePath(scenario.compile.serverFunctions)
218+
: null;
219+
const directives = root && type && id.startsWith(root + sep);
220+
if (!jsx && !directives) return null;
221+
let code = readFileSync(id, "utf8");
222+
if (directives) code = compileDirectives(code, id, root);
223+
if (jsx) code = compile(code, id, !!scenario.compile.hydratable);
224+
return { code, moduleType: type };
225+
}
159226
}
160227
]
161228
: [])
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// @solidjs/vite-plugin 3.0.0-next.35's built-in document shell
2+
// (`virtual:solid-ssr-document`, SSR start mode) as the plugin emits it:
3+
// minimal, hydration-ready. The client entry script is injected into <head>
4+
// by the handler, not rendered here.
5+
import { HydrationScript } from "@solidjs/web";
6+
7+
export default function Document(props) {
8+
return (
9+
<html lang="en">
10+
<head>
11+
<meta charset="utf-8" />
12+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
13+
<HydrationScript />
14+
</head>
15+
<body>{props.children}</body>
16+
</html>
17+
);
18+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// `page: hackernews`: the client entry of examples/hackernews as
2+
// @solidjs/vite-plugin 3.0.0-next.35 generates it for that example's config
3+
// (`solid({ start: {}, ssr: true, serverFunctions: { components: true } })`,
4+
// the default `errorBoundary`, no devtools) — `virtual:solid-ssr-entry-client`
5+
// written out: install the server-component transport, then hydrate the
6+
// document with the app inside the plugin's default error boundaries. The
7+
// app is the example's own `src/app.tsx` (through its `~` alias), reached
8+
// unchanged; `document.jsx` and `error-boundary.jsx` beside this file are
9+
// the plugin's other two generated modules. Together they are what the
10+
// example's `vite build` hands the browser as its one eager script.
11+
import { hydrate } from "@solidjs/web";
12+
import { installServerComponents } from "@solidjs/web/frames";
13+
import { DefaultErrorBoundary } from "./error-boundary.jsx";
14+
import Document from "./document.jsx";
15+
import App from "~/app";
16+
17+
installServerComponents();
18+
19+
hydrate(
20+
() => (
21+
<DefaultErrorBoundary>
22+
<Document>
23+
<DefaultErrorBoundary>
24+
<App />
25+
</DefaultErrorBoundary>
26+
</Document>
27+
</DefaultErrorBoundary>
28+
),
29+
document
30+
);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// @solidjs/vite-plugin 3.0.0-next.35's default error boundary
2+
// (`virtual:solid-ssr-error-boundary`), emitted into production builds
3+
// unless `start.errorBoundary: false`; the generated entry wraps the
4+
// document and the app in it.
5+
import { Errored } from "solid-js";
6+
import { httpStatus, isServer } from "@solidjs/web";
7+
8+
function ErrorFallback(props) {
9+
console.error(props.error());
10+
httpStatus(500);
11+
return (
12+
<span style="font-size:1.5em;text-align:center;position:fixed;left:0;bottom:55%;width:100%">
13+
{isServer ? "500 | Internal Server Error" : "Error | Uncaught Client Exception"}
14+
</span>
15+
);
16+
}
17+
18+
export function DefaultErrorBoundary(props) {
19+
return <Errored fallback={error => <ErrorFallback error={error} />}>{props.children}</Errored>;
20+
}

‎scripts/size/scenarios.js‎

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,29 @@ const pageAlias = {
104104
...alias
105105
};
106106

107+
// examples/hackernews as the harness bundles it (2026-10-07): the example's
108+
// `~` alias is its src/, and `@solidjs/router` is this directory's pinned
109+
// copy (`2.0.0-next.35`), not the `2.0.0-next.29` the example's own
110+
// package.json installs under examples/hackernews/node_modules — the
111+
// harness's router is the one whose upgrade is a recorded re-base, and the
112+
// scenario must not move with the workspace install. It resolves the way
113+
// the example's Vite build resolves it: @solidjs/vite-plugin puts the
114+
// `solid` export condition first, which is `dist/index.jsx` plus the
115+
// router's per-module output, JSX compiled by the app's compiler (here the
116+
// measured checkout's, hydratable, like the app's own `.tsx`). The router
117+
// scenarios above resolve the `default` condition, the flat `dist/index.js`
118+
// fallback for consumers without a Solid compiler — a different artifact:
119+
// its build inlines `data/events`' `import("./serverForms")`, so the
120+
// server-form fallback and, through it, `action` and the flight consumer
121+
// are eager there and a lazy chunk here. The rest is the page alias: the
122+
// example's `solid-js` / `@solidjs/web` / frames / server-function imports
123+
// route to the dists.
124+
const hackernewsAlias = {
125+
"~": "../../examples/hackernews/src",
126+
"@solidjs/router": "node_modules/@solidjs/router/dist/index.jsx",
127+
...pageAlias
128+
};
129+
107130
// Observe tier (documentation/plans/observe-tier-plan.md): the artifacts the
108131
// `observe` export condition selects — wiring kept (attribution hook sites,
109132
// owner labels, edge counters, the diagnostics channel), checks folded. Its
@@ -4539,6 +4562,69 @@ module.exports = [
45394562
capMinified: 148668,
45404563
alias: pageAlias
45414564
},
4565+
{
4566+
name: "page: hackernews (examples/hackernews client entry)",
4567+
// A real application's eager script: the client entry of
4568+
// examples/hackernews — the server-components HackerNews — as its
4569+
// `vite build` ships it. The fixture (fixtures/hackernews/entry.jsx) is
4570+
// @solidjs/vite-plugin 3.0.0-next.35's generated client entry written
4571+
// out (`installServerComponents()`, `hydrate()` of the plugin's document
4572+
// shell and default error boundary around the app); the app is the
4573+
// example's own src/, unchanged, compiled hydratable by the measured
4574+
// checkout's compiler: `createRouter` with three `defineRoute`s (six
4575+
// feed paths, `/stories/:id`, `/users/:id`), each with a `preload`, the
4576+
// instance as the root with a render-prop layout, two `<Loading>`
4577+
// boundaries, four server components mounted with `dynamic()` (the nav
4578+
// directly; the three routes through the router's `query` — the
4579+
// example's `"use server"` views compile, client side, to
4580+
// `createServerReference` proxies: the one `api.ts` module is the
4581+
// example's whole server-function surface), and the one client
4582+
// component (`Toggle`: a signal, a delegated click, `class`/`style`
4583+
// effects). No client stores, no `action`, no element spread. The
4584+
// router is resolved as the example's build resolves it (the `solid`
4585+
// condition; see hackernewsAlias), so its server-form fallback —
4586+
// `data/serverForms`, `data/action`, signals' `action` — is the lazy
4587+
// chunk it is in the example's build, reported and not counted. The
4588+
// router's own modules report as `other`; the example's as `app`.
4589+
// The example mounts with `dynamic()`, not #3870's `dynamicComponent`
4590+
// (which is not on this base); it carries `dynamic`'s string-tag
4591+
// branch and the spread runtime it retains, as #3870 measured.
4592+
// Not a floor: an inline cap.
4593+
// Landing (2026-10-07, next @ 49a8dca84 + #3838): measured locally at
4594+
// 54,557 B (176,581 B minified): signals 64,308, frames 35,009, router
4595+
// 22,616 (`routing.js` 6,616, `data/query.js` 3,260, `utils.js` 2,767,
4596+
// `routers/factory.jsx` 2,584, `data/events.js` 1,997, components
4597+
// 1,327, claims 1,296, history 1,045, scroll restoration 835, …), web
4598+
// 20,630, solid 18,097, sf 13,510, app 2,412 (the example's own
4599+
// modules 1,651 — `app.tsx` 505, `toggle.tsx` 426 — and the generated
4600+
// entry/document/error boundary 761). Lazy: the codec 6,074 B br, the
4601+
// router's `serverForms.js` 2,360 (`data/serverForms`, `data/action`,
4602+
// signals' `action`). On the flat `dist/index.js` the same page is
4603+
// 181,895 / 56,084: +5,314 / +1,527 for the inlined server-form
4604+
// fallback and what it reaches. Against `next` @ 3c1d51267 measured
4605+
// with this harness, 177,417 / 54,976: −836 / −419, which is the
4606+
// thirteen commits `next` took after this branch's base (#3849 and the
4607+
// signals/web fixes beside it), not this branch's. Cap at local
4608+
// measured + 10 B rounded up to 0.01 KB; to be confirmed against CI's
4609+
// measurement (Node 24) + 10 B.
4610+
// Re-based (2026-10-07, next @ d231b9911 — #3838 and #3860's frames
4611+
// tiers merged): 47,849 B (145,471 B minified): signals 41,036 (the
4612+
// store engine — `store/store.js`, reconcile, projection — is in the
4613+
// lazy `trace.js` now, 8.19 KB br; `store/utils.js` 3,425 and
4614+
// `store/types.js` 789 stay eager for `dynamic()`'s element arm, the
4615+
// lanes 5,343 + verdict 2,682 for the router's navigation core),
4616+
// frames 26,950, router 23,376, web 20,344, solid 17,309, sf 13,967,
4617+
// app 2,491. The −31,110 / −6,708 against the landing figure is
4618+
// `next`'s (the tiers), not this scenario's. The example still mounts
4619+
// with `dynamic()`; its move to `dynamicComponent` (now on `next`) is
4620+
// the example's own change and will show here when it lands. Cap at
4621+
// local measured + 10 B rounded up to 0.01 KB, same caveat.
4622+
path: "fixtures/hackernews/entry.jsx",
4623+
compile: { hydratable: true, serverFunctions: "../../examples/hackernews" },
4624+
limit: "47.86 KB",
4625+
capMinified: 145471,
4626+
alias: hackernewsAlias
4627+
},
45424628
{
45434629
name: "server: floor (getRequestEvent + isServer)",
45444630
// What a server module that only asks "am I on the server / which

0 commit comments

Comments
 (0)