Skip to content

ferrovueVue 3 components, rendered by Rust

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

Two halves ​

ferrovue has a build-time half and a run-time half, released together under one version number.

text
 Button.vue ──(ferrovue compiler, Node)──▶ button.rs ──(your Rust server)──▶ HTML ──▶ Vue hydrates it
What it isPublished as
The compilerReads <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 clientnpm: ferrovue
The runtimeThe crate the generated Rust calls: escaping, slots, islands, <RouterLink> matching, the page headcrates.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.

From a component to HTML ​

A component:

vue
<!-- 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:

rust
#[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, &lt;script&gt;!<!----><!----></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.

Quick start ​

Install both halves:

sh
pnpm add -D ferrovue
cargo add ferrovue serde --features serde/derive
cargo add --dev serde_json

pnpm 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.

Performance ​

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.

ScenarioWhat rendersOutputVue renderToStringferrovueSpeed-up
smallNav: two <RouterLink>s resolved against the current route206 B36.41 µs0.989 µs36.8×
listLists: 1,000 words, 1,000 numbers, 100 groups of 10 members102 KiB355.8 µs46.16 µs7.7×
treeTree: a recursive component, binary tree 8 levels deep (255 nodes)9.5 KiB522.2 µs3.86 µs135.2×
pageDashboard: 22 Panels with named slots, a Text, 20 Frames holding loops8.0 KiB181.3 µs5.06 µs35.8×

The README's Performance section has the method, the machine and how to run the benchmarks.