Byte-identical to Vue
The generated Rust writes exactly the bytes Vue's renderToString writes for the same props, so Vue hydrates the page without a mismatch. Every supported construct is held to fixtures recorded from Vue.
Single-file components compiled to Rust render functions whose HTML is byte-identical to Vue's renderToString. The browser hydrates it with the same .vue file.
ferrovue has a build-time half and a run-time half, released together under one version number.
Button.vue ──(ferrovue compiler, Node)──▶ button.rs ──(your Rust server)──▶ HTML ──▶ Vue hydrates it| What it is | Published as | |
|---|---|---|
| The compiler | Reads <script setup lang="ts"> components and writes one Rust module per component, at build time on Node. Also the ferrovue command, the Vite plugin, the editor plugin and the browser client | npm: ferrovue |
| The runtime | The crate the generated Rust calls: escaping, slots, islands, <RouterLink> matching, the page head | crates.io: ferrovue, API on docs.rs |
ferrovue takes what @vue/compiler-sfc compiles a template to for server rendering and translates that small, closed vocabulary into Rust that writes the same bytes. Vue still decides element structure, attribute order, whitespace and fragment markers. In the browser, Vue hydrates the HTML with the same component.
A component:
<!-- client/components/Greeting.vue -->
<script setup lang="ts">
defineProps<{ name: string; unread: number; note?: string }>();
</script>
<template>
<p class="greeting">Hello, {{ name }}!<b v-if="unread">{{ unread }} new</b><i v-if="note">{{ note }}</i></p>
</template>pnpm ferrovue writes src/generated/greeting.rs, which a Rust server calls:
#[rustfmt::skip]
mod generated;
use generated::greeting::{self, Props};
let props = Props::new("Ada", 3).note("welcome back");
let html = greeting::html(&props).into_string();
assert_eq!(html, r#"<p class="greeting">Hello, Ada!<b>3 new</b><i>welcome back</i></p>"#);
let hostile = greeting::html(&Props::new("<script>", 0)).into_string();
assert_eq!(hostile, r#"<p class="greeting">Hello, <script>!<!----><!----></p>"#);The output is what Vue's renderToString writes for the same props, comment markers included. greeting::island(&props) wraps it in an element the browser hydrates with mountIslands from ferrovue.
Install both halves:
pnpm add -D ferrovue
cargo add ferrovue serde --features serde/derive
cargo add --dev serde_jsonpnpm ferrovue init writes a starter ferrovue.config.json and a component, and pnpm ferrovue generates the Rust. The quick start walks through configuring, generating, rendering and checking in CI, and the guide covers each part in order. ferrovue needs Rust 1.89 or later and edition 2024 in the crate that includes the generated code.
Time to render one component to an HTML string: Vue's renderToString on Node, and the Rust that ferrovue generated from the same .vue file, given the same props.
| Scenario | What renders | Output | Vue renderToString | ferrovue | Speed-up |
|---|---|---|---|---|---|
small | Nav: two <RouterLink>s resolved against the current route | 206 B | 36.41 µs | 0.989 µs | 36.8× |
list | Lists: 1,000 words, 1,000 numbers, 100 groups of 10 members | 102 KiB | 355.8 µs | 46.16 µs | 7.7× |
tree | Tree: a recursive component, binary tree 8 levels deep (255 nodes) | 9.5 KiB | 522.2 µs | 3.86 µs | 135.2× |
page | Dashboard: 22 Panels with named slots, a Text, 20 Frames holding loops | 8.0 KiB | 181.3 µs | 5.06 µs | 35.8× |
The README's Performance section has the method, the machine and how to run the benchmarks.