Skip to content

Upgrading to 0.8 ​

Upgrading a project from ferrovue 0.7 to 0.8: the steps to take, what behaves differently, and what a component may now use.

The CHANGELOG lists every change; this page picks out what an application notices. The page for the release after is upgrading_to_0_9.

Steps ​

1. Bump both halves and the peers together ​

The npm package and the crates are released together at one version, and generated code works with the crate of its own release. Bump the npm package:

sh
pnpm add -D ferrovue@^0.8.0

and the crate, in Cargo.toml:

toml
ferrovue = "0.8"

ferrovue depends on ferrovue-core, ferrovue-router and ferrovue-i18n at exactly its own version, so an application that names only ferrovue gets the other three with it. One that names any of them itself bumps it to 0.8 as well. ferrovue and ferrovue-router require serde_json 1.0.154 or newer, which Cargo picks as it resolves the bump.

The 0.8 npm package compiles with @vue/compiler-sfc 3.5.44, and the peer ranges move with it:

Peer0.70.8
vue~3.5.43~3.5.44
vue-router~5.3.1~5.4.0
pinia~4.0.3~4.1.0
vue-i18n~11.4.13~11.4.15
@unhead/vue~3.4.2~3.4.3
sh
pnpm add vue@~3.5.44 vue-router@~5.4.0 pinia@~4.1.0 vue-i18n@~11.4.15 @unhead/vue@~3.4.3

(each optional peer only if the project uses it). Node 22.18 or newer and Rust 1.89 or newer stay the minimums.

2. Generate every component again ​

sh
pnpm ferrovue

The 0.8 compiler writes version 2 of generated code, and mod.rs opens with ferrovue::__compat!(2). Version 2 calls the date twins and builds RouteDef, i18n::Locale, i18n::Message and i18n::Args with their constructors. The 0.8 crate supports version 2 alone, so a module generated by 0.7 (version 1) stops the build at that line:

text
error: this module was generated as version 1 of ferrovue's generated code, and this `ferrovue` crate supports version 2: use the `ferrovue` npm package and the `ferrovue` crate of one release, and run `ferrovue` to generate the module again

A 0.7 crate stops a module of version 2 the same way. Generate the modules with the 0.8 npm package and commit them; pnpm ferrovue --check in CI then passes. See the version check.

3. Rust you write against the crates ​

These changes are breaking for code outside the crates; generated code already follows them.

RouteDef, i18n::Locale, i18n::Message, i18n::Args, HeadHtml and Link are #[non_exhaustive]. Their fields stay public to read. A struct literal outside the crates no longer compiles, and a pattern that destructures one ends in ... Build them with the const constructors:

0.70.8
RouteDef { path, name: Some(n), view, children }RouteDef::new(path).with_name(n).with_view(false).with_children(&[…])
Locale { name, messages }Locale::new(name, &[(key, message), …])
Message { cases }Message::new(&[case, …])
Args { plural: Some(n), ..Args::default() }Args::new().with_plural(n), with .with_named(&[…]) and .with_list(&[…])
HeadHtml { head_tags, .. }HeadHtml::default(), then set its fields
Link { … }Route::link, Route::link_named or Route::link_path
rust
use ferrovue::i18n::{Args, Locale, Message, Part, Value};
use ferrovue::{HeadHtml, RouteDef};

const BOOKS: &[RouteDef<'static>] = &[RouteDef::new(":id").with_name("book")];
const ROUTES: &[RouteDef<'static>] = &[RouteDef::new("/books").with_view(false).with_children(BOOKS)];
assert_eq!(ROUTES[0].children[0].name, Some("book"));

static EN: Locale = Locale::new("en", &[("hello", Message::new(&[&[Part::Text("Hello, "), Part::Named("name")]]))]);
assert_eq!(EN.name, "en");

let named = [("name", Value::Str("Ada"))];
let args = Args::new().with_named(&named).with_plural(2);
assert_eq!(args.plural, Some(2));

let mut head = HeadHtml::default();
head.head_tags.push_str("<title>Books</title>");
assert_eq!(head.body_tags, "");

ferrovue::ammonia is gone. The ammonia feature no longer re-exports the ammonia crate. A Sanitised::with policy of your own takes ammonia as a dependency of your own crate, which Cargo resolves to the release ferrovue uses, and names ammonia::Builder where it named ferrovue::ammonia::Builder:

toml
ferrovue = { version = "0.8", features = ["ammonia"] }
ammonia = "4"
rust
use ferrovue::Sanitised;

let mut policy = ammonia::Builder::empty();
policy.add_tags(["em"]);
assert_eq!(Sanitised::with(&policy, "<p><em>only</em> this</p>").as_str(), "<em>only</em> this");

The feature requires ammonia 4.2.4, which fixes RUSTSEC-2021-0157, RUSTSEC-2026-0373 and RUSTSEC-2021-0158. A Sanitised::with policy that allows style attributes or SVG was exposed with ammonia 4.2.1 to 4.2.3; Sanitised::new allows neither.

The helpers only generated code calls are #[doc(hidden)]. js_trim, js_slice, js_split, js_cmp, class_into, merge_props, scoped_slot_into, teleport_into, trusted_into and the rest the CHANGELOG lists keep their paths and signatures in 0.8, so code that calls one still compiles, and from 0.8 on a release may change one along with the version of generated code. Code that calls one itself (a test holding its own helper to JavaScript's trim, say) keeps a copy of its own. What an application calls stays documented: the numbers of ferrovue-core, slot_into, attrs_into, passed_attrs_into, query_into and every type.

#[must_use]. Slot::new, Part::new, Page::slot, PageRecord::script, HeadValue::object, Chunks::for_islands and Chunks::for_source warn when their result is dropped, which fails a build under -D warnings.

4. Error codes your CI matches ​

ferrovue.config.json needs no change. A script or CI step that matches on --format json's code sees these change for the same source:

Source0.70.8
new Date(s) of an ISO string, new Date(ms)FV0624compiles
new Date(), Date.now()FV0624 and FV0601FV1801
new Date of anything but one present string or numberFV0624FV1802
a date literal outside ECMAScript's date time string formatFV0624FV1803
.getHours() and the other local getters, .toString() of a dateFV0624FV1804
.toLocaleString(), .toLocaleDateString(), .toLocaleTimeString(), .localeCompare(), Intl, $d, $nFV0602 for the methodsFV1805
a call of a setup binding the server cannot evaluate (const { d } = useI18n(), then d(x))FV0601, naming $setupFV0613, with the reason

FV1805 is permanent: the locale data each engine ships differs. See dates_and_prices for the pattern that replaces it.

Behaviour that changed ​

A computed is worked out when the render first reads it ​

0.7 worked out every computed before the render. Vue works one out when the render first reads it, so a computed that throws in JavaScript, under a v-if that is false, panicked in 0.7 where Vue renders the page. In 0.8 a computed whose expression may panic (.repeat(), .padStart(), .padEnd(), new Date(s), Date.parse(s), .toISOString(), t() and helpers, or another such computed) is a std::cell::LazyCell, worked out at its first read and kept for the rest of the render:

vue
<script setup lang="ts">
import { computed } from "vue";
const props = defineProps<{ published: string; show: boolean }>();
const iso = computed(() => new Date(props.published).toISOString());
</script>

<template>
  <time v-if="show" :datetime="iso">{{ iso.slice(0, 10) }}</time>
</template>

With show false this renders <!----> whatever published holds. One that a v-bind() in <style> reads is worked out as the render starts, as Vue's server works out the style variables. Every other computed is generated as before. See errors_and_limits.

Strings a date is read from ​

js_date_parse, which new Date(s) and Date.parse(s) of a prop compile to, panics on a string outside ECMAScript's date time string format: a date alone, or a date and time with a Z or an offset (2024-05-01, 2024-05-01T09:30:00.000Z, 2024-05-01T09:30+02:00). Browsers may each read another string their own way, so a server that hands a component a date string writes it in that format, as dates_and_prices shows from Rust:

rust
assert_eq!(ferrovue::js_to_iso_string(1_714_555_800_000.0), "2024-05-01T09:30:00.000Z");

A number compared with itself ​

x === x, true unless x is NaN, compiles to !x.is_nan(), which Clippy accepts in generated code. 0.7 wrote x == x, which Clippy flags.

FV0613 gives one location ​

FV0613 for a setup binding the server cannot evaluate names one location, where the template reads the binding. It repeated the location and source line of the expression inside the setup after the reason, which a script that parses the message may have relied on.

Newly supported ​

Dates (dates_and_prices), in the part of Date that reads the same on the server and in every browser: new Date(s) and Date.parse(s) of a string in ECMAScript's date time string format (four-digit and expanded years), new Date(ms) of a number, and .toISOString(), .getTime(), .valueOf() and the .getUTC…() methods, invalid dates included. The generated code calls twins held to vectors recorded from Node, which Chromium, Firefox and WebKit read alike in four time zones:

vue
<script setup lang="ts">
import { computed } from "vue";
const props = defineProps<{ published: string }>();
const date = computed(() => new Date(props.published));
</script>

<template>
  <time :datetime="date.toISOString()">
    {{ date.getUTCDate() }}/{{ date.getUTCMonth() + 1 }}/{{ date.getUTCFullYear() }}
  </time>
</template>

Prices and formatted dates (dates_and_prices): the guide page sets out how to format them in Rust and pass a string, or fill them into a vue-i18n message, end to end.

Refused on purpose ​

ConstructCodeWhy
new Date(), Date.now()FV1801the server renders at one moment and the browser hydrates at another
new Date(year, month, …)FV1802it reads its parts in the time zone of the machine running it
a date and time without a Z or an offset (2024-05-01T09:30)FV1803it is read in the time zone of the machine running it
.getHours(), .getTimezoneOffset(), .toString()FV1804they read the server's time zone, which differs from the reader's
.toLocaleString(), Intl, .localeCompare(), $d, $nFV1805locale data differs between Node, Chromium, Firefox and Safari