Closing bug classes in a constrained Rust web framework
Why a framework on a constrained Rust platform should fail the build rather than shim: strict generated contracts, an honest TanStack Start port, post-mortem lints and build-time compression.

On this page
Rename a field on a server endpoint and every backend test still passes while the page renders a blank value, because the client was typed against a guess. Ferrite, my cloud platform, runs Rust applications with no filesystem, no raw sockets, no server-side JavaScript, one crate dependency, and no build scripts or procedural macros, distributing shared libraries as source packages. Making Ferrite productive for React developers and coding agents requires familiar abstractions, and the common way to supply them is compatibility shims that accept the upstream API and quietly do less. Shims get existing code compiling quickly, which is why people keep writing them, until the gap surfaces in production as an empty field, a stale view, or a permission check that never ran.
Static checking takes the opposite position: enforce each invariant at the earliest stage that can see it, and fail the build rather than degrade at runtime. I built two frameworks on Ferrite around that rule: a full-stack framework where one Rust crate owns routing, data loading, mutations, and caching while a Vite and React bundle renders the UI across a generated typed contract, and a Rust port of the server contract behind TanStack Start, a full-stack React framework.
Typed contracts between Rust and React
Because Ferrite’s admission gate forbids procedural macros and build scripts, an app cannot derive its wire contract through compile-time reflection. A local code generator reads the route and mutation declarations instead and writes plain, committed Rust and TypeScript that both compilers check. In a port of Next.js Commerce, Vercel’s reference storefront, the add-to-cart mutation is declared once in Rust; renaming a field on its payload breaks the TypeScript build at every call site.
That contract holds only if the generator has no escape hatches. An unrecognized Rust type is a build error, never TypeScript’s any. Integers wider than 53 bits cross the wire as decimal strings so JavaScript cannot truncate them. Floating-point fields are disallowed in mutation results: replies are recorded for idempotent replay, and NaN serializes to null only after the write has committed.
Porting TanStack Start and Nitro
Porting an existing framework’s server contract tests the same rule harder. TanStack Start compiles routes, response rules, and asset metadata through Nitro, its underlying server toolkit, and expects a runtime that honors them. Recreating Nitro in Rust only stays trustworthy as an explicit inventory rather than a permissive shim.
The port reproduces Nitro’s route rule precedence and cache freshness arithmetic directly, changes behavior openly where the host differs, and fails the build on everything else. Nitro’s stale-while-revalidate relies on background revalidation after the response is sent; a single-reply handler cannot do that, so the port serves stale on the first expired request and revalidates inline on the next. Server-function middleware has no safe substitute and breaks the build: accepting it as a no-op looks harmless until the ignored middleware is the permission check.
Turning post-mortems into static lints
Post-mortems surface a second class of defects that belong in the framework rather than in per-app patches. Stale views traced back to two React mistakes: server-seeded client queries were marked fresh forever via TanStack Query’s staleTime: Infinity with no invalidation hook, and a mutation read React state through a closure instead of taking it as a mutation variable.
Both became static lint rules. A literal-only check misses extracted constants and shared imports, so the linter resolves identifiers through local declarations, constants, and imports. Any server-backed query with an infinite staleTime must declare a freshness key, mutations cannot close over useState, and an infinite default on QueryClient is rejected outright because every query inherits it and none can declare a freshness key for it. Running the lint across all 22 framework apps in CI caught three live defects.
Build-time asset compression and caching
Pushing work and metadata to the earliest stage that has them shapes asset delivery too. Static assets on Ferrite were served uncompressed with a 60-second cache, so hashed bundles revalidated every minute and the largest app transferred 6.6 MB on a first visit. The deployed crate cannot import compression libraries and has no reason to recompress static files per request, whereas the build step has host tooling and Vite’s manifest showing which paths are content-hashed.
The build now hashes every emitted asset, stores precompressed brotli and gzip copies when they save at least ten percent, and bundles Vite’s manifest metadata alongside them. At request time, the runtime negotiates Accept-Encoding, sets Content-Encoding, Vary: Accept-Encoding, and per-representation ETag headers, and caches hashed paths for a year as immutable while revalidating unhashed ones. Because the admission gate forbids app-defined macros, the build cannot splice hashed entry names into the HTML shell at compile time; it emits plain constants, the shell keeps stable entry URLs, and the runtime rewrites them once at boot. On the largest app, a first visit fell from 6.6 MB to 1.5 MB.
Chris Chabot, October 2026