Porting
Moving an existing Vue 3 server-rendered app to ferrovue: a Vite SSR setup, or a Node server that calls renderToString.
Each step links to the page that covers it in depth. The repository's examples/fullstack is a finished app of this shape to compare with: an axum server, a Vite client, islands, Pinia, vue-router and streaming.
What changes and what stays
ferrovue replaces the server half. The Node process that builds an app with createSSRApp, loads data, and calls renderToString from @vue/server-renderer becomes a Rust binary. At build time the ferrovue compiler turns each .vue file into a Rust module, and the server calls that module's render with the component's props: a function call that writes into a String, with no JavaScript runtime.
The client half stays. The browser still runs Vue, built by Vite with @vitejs/plugin-vue from the same .vue files, and hydrates the HTML the Rust server wrote. vue-router, Pinia, vue-i18n and @unhead/vue keep running in the browser as they do now. The server writes the bytes Vue's renderToString writes for the same input, so hydration finds the DOM it expects.
The project's vue and its integrations must be in the ranges ferrovue supports, since its output is held to fixtures recorded from one version of each: the README's Versions table lists them, and support says how they move.
1. Install both halves
pnpm add -D ferrovue
cargo add ferrovue serde --features serde/derive
cargo add --dev serde_jsonThe crate that includes the generated code uses edition 2024. quick_start says what each dependency is for, and the crate's feature flags (axum, actix-web, stream, router, i18n, chrono, ammonia, …) are listed on the crate's front page.
2. Configure
pnpm ferrovue init writes a starter ferrovue.config.json; or write one at the project root with the two required keys:
{
"$schema": "./node_modules/ferrovue/schema.json",
"components": "client/components",
"out": "src/generated"
}Then add a key for each part of the app the server must reproduce:
| The app uses | Configure | See |
|---|---|---|
| vue-router | routes (a JSON file of routes, or { "pages": "client/pages" }), or router with base and the link classes createRouter is given | routing |
| Pinia | stores, the directory of store files | pinia |
| vue-i18n | i18n: { messages, locale?, fallbackLocale? } | i18n |
<style scoped>, v-bind() in <style>, <style module> | scopeId, viteRoot and isProduction as the Vite build sets them, and cssModules as Vite's css.modules | scoped_styles |
v-html | trustedHtml, the Rust type of a TrustedHtml prop | escaping |
Date props | dateType, when the default ferrovue::date::JsDate does not suit | dates_and_prices |
| Functions of its own called from templates | helpers | errors_and_limits |
| Components from a library the compiler refuses | twins | errors_and_limits |
| Custom directives with no server output | clientDirectives | quick_start |
The quick_start table describes every key, and the JSON Schema named by $schema lets an editor complete and check them.
3. Generate the Rust and commit it
pnpm ferrovueThis writes one module per component into out, with mod.rs declaring them. Include the directory once, with #[rustfmt::skip] on the mod generated; line, and commit it: the server builds from it with no Node installed. In CI, pnpm ferrovue --check fails when a committed module is stale. A Vite project can add the ferrovue/vite plugin, which regenerates the modules in the dev server and before a build. generated_code describes each file and what of it is stable API.
4. Move the server to Rust
What the Node server did per request moves into a Rust handler:
- Responding. The
axumandactix-webfeatures make a render a response:web_frameworks.streamingsends a page in the order its parts are ready. - Loading data. Data a component awaits at the top of
<script setup>becomes a loader: declare the function withdefineLoader, implement the generatedLoaderstrait in Rust, and render throughloaders::load, which writes the results for the client to hydrate from (loaders). Data fetched inonServerPrefetch, or beforerenderToString, is loaded by the handler and passed in as props; the compiler refusesonServerPrefetchand any other top-levelawait, and the client receives the same values through the island's props, the page record or the Pinia state. - Routing. Build the router once from the generated
route_table::router(), resolve each request withrouter.at(path), and choose the page from the route's name and parameters. A layout with<RouterView>takes the page as itsrouter_viewslot:routing. - Pinia. The state is a generated Rust struct filled per request and passed to
render;state_script_intowrites it into the page, andhydrateStateon the client starts every store from it:pinia. - vue-i18n. Build an
I18nper request with the generatedi18n(locale):i18n. - The page head and teleports.
useHeadanduseSeoMetawrite into aHead, and<Teleport>intoTeleports, which the server places in the page:headandteleports. - provide and inject. What the client app gives
app.provideis a generatedProvides:provide_inject.
5. Choose how the client hydrates
islands_and_hydration describes three ways, which a page may combine with islands:
- The whole app, as a Vue SSR app hydrates now: the client keeps its
createSSRApp(Root)and mounts it on the server's element, starting from the same props, route, state and locale. This is the smallest change to the client: hydrating the whole app. - A page recorded part by part: the server writes the layout and its parts with
Page, andmountPagehydrates them as one app: hydrating a page. - Islands: each interactive component hydrates on its own from its props, with
mountIslandsand theferrovue/islandsmodule the Vite plugin writes. The rest of the page stays static HTML, and the browser fetches only the islands' code. A component has anisland()when its render needs its props alone: islands.
Islands or a page compares them, and what makes hydration fail lists the usual causes of a mismatch.
6. Work through what the compiler refuses
The first run on an existing app usually reports errors, all of them at once, then a line that counts them. Each names the file, line and column, and has a stable code:
error[FV1805]: components/Card.vue:4:17: `.toLocaleString()` formats by locale with `Intl`, whose output differs between Node, Chromium, Firefox and Safari: format the value in Rust and pass a string, or translate it with `$t` (see the `dates_and_prices` guide)
4 | <template><p>{{ n.toLocaleString() }}</p></template>
| ^
= docs: https://docs.rs/ferrovue/latest/ferrovue/guide/error_codes/index.html#fv1805pnpm ferrovue --format json writes the same errors as JSON, each with its code, severity, title, message and docs link, which makes a long list easy to sort by code and work through one kind at a time. error_codes explains every code, and quick_start has a VS Code problem matcher for them. The ferrovue/volar plugin underlines them in the editor as you type: quick_start.
errors_and_limits lists what is refused and why. The ways around a refusal, from the least work:
- Rewrite the expression as the message suggests: narrow an optional value before use, join a list before binding it to an attribute, compare values of one type.
- Type an object literal with the interface it builds: a
computedreturning an object (computed((): Card => …)), a function's return type, a.map((x): Row => ({ … }))callback. The compiler builds the literal as that interface's Rust struct, where an untyped one is refused (FV0634): object literals. - Compute the value in Rust and pass it as a prop. Locale formatting, the current time and anything else the server cannot reproduce exactly is worked out by the handler and passed as a
stringornumberprop, which the client receives unchanged: format in Rust, pass a string. - A helper: a function of your own the template calls, mapped to a Rust twin in
helpers: helpers. <ClientOnly>fromferrovue, around content the server need not render. The server writes the#fallbackslot, and the compiler does not read the default slot at all: client-only content.- A Rust twin: a component the server must render and the compiler cannot compile, such as a component library's button, rendered by a Rust function of yours named in
twins: Rust twins.
Helpers and twins are your code, and ferrovue does not check that they write what Vue writes: hold the components that use them to Vue with fixtures, as the next step does. When none of these fits a construct you need, support says how to ask for it.
7. Verify the output against Vue
testing holds an application's own components to Vue with fixtures and two calls. A checklist for a port:
- Fixtures for every component. A directory per component under
fixtures/, each fixture a JSON file of props, with$slots,$route,$storesand$localewhere the component takes them. Give each component a typical case, an empty or falsy one, and one with<,&,"and'in every prop that reaches the page. - The Vue half. A vitest file calls
conformanceSuitefromferrovue/testingwith the configuration, every component, and the app's ownpinia,vueRouterandvueI18nmodules. Run it in a DOM environment with@vitejs/plugin-vueconfigured as the client build configures it. - Record from Vue.
FERROVUE_FIXTURES_WRITE=1writes each fixture's.htmlfrom Vue'srenderToString. Read the recorded HTML before committing it. - Run it again without recording. The suite fails when a render differs from the recorded
.html, when Vue's hydration of it logs a warning, when a component has no fixtures, and when the committed Rust is stale. - The Rust half.
ferrovue::conformance!("fixtures", generated::render_json, at_least = N)writes a test that renders every fixture with the generated Rust and compares the bytes, and fails when it finds fewer thanNfixtures. - Pages and client renders.
hydrateRecordedPagefromferrovue/testing/browserhydrates a page as the server wrote it: testing a page. An app that renders the next page from its record on navigation passesclientRender: truetoconformanceSuite. - Your own tests.
fixtureAppfromferrovue/testing/browserbuilds the app a fixture describes, for a vitest test of your own: fixtures in your own vitest tests. - In CI. Run
pnpm ferrovue --check, the vitest suite andcargo teston every change, so a component edit that changes the output fails until its fixtures are recorded again and reviewed.