Upgrading to 0.9
Upgrading a project from ferrovue 0.8 to 0.9: 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 before is upgrading_to_0_8.
Steps
1. Bump both halves 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:
pnpm add -D ferrovue@^0.9.0and the crate, in Cargo.toml:
ferrovue = "0.9"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.9 as well.
Node 22.18 or newer stays the minimum for the npm package (CI tests 22.18, 22, 24 and 26), and Rust 1.89 or newer, with edition 2024 for the crate that includes the generated code. The peer ranges are those of 0.8: vue ~3.5.44, vue-router ~5.4.0, pinia ~4.1.0, vue-i18n ~11.4.15 and @unhead/vue ~3.4.3.
2. Generate every component again
pnpm ferrovueThe 0.9 compiler writes version 3 of generated code, and mod.rs opens with ferrovue::__compat!(3). Version 3 calls what the 0.8 crate lacks: JsTime and the helpers that read a Date prop and write it into data-props, and the new date, list and string twins. The 0.9 crate supports versions 2 and 3, and a module of version 2 calls nothing that changed, so modules generated by 0.8 still build against it. Generate them again all the same, to get the fixes below. The 0.8 crate supports version 2 alone: given a module of version 3 it stops the build at that line, with what to do:
error: this module was generated as version 3 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 againA CI job that runs pnpm ferrovue --check reports each module as stale until it is generated again with 0.9 and committed. See the version check.
3. The configuration
ferrovue.config.json needs no change. $schema may name the 0.9.0 schema (https://cdn.jsdelivr.net/npm/ferrovue@0.9.0/schema.json) so that the editor knows the new key:
| Key | Default | What it does |
|---|---|---|
dateType | ferrovue::JsDate | the Rust type of a Date prop: JsDate, chrono::DateTime<chrono::Utc> with the crate's chrono feature, or a type of your own that implements JsTime |
The chrono feature is off by default. An application that names chrono's type turns it on:
ferrovue = { version = "0.9", features = ["chrono"] }4. Error codes your CI matches
A script or CI step that matches on --format json's code (or on error[FV…] in the text output) sees these codes change for the same source:
| Source | 0.8 | 0.9 |
|---|---|---|
in, instanceof | FV0619 | FV0631 |
&, |, ^, <<, >>, >>> | FV0619 | FV0632 |
** that is not worked out when compiling | FV0619 | FV0720 |
Math.exp(), Math.log(), the trigonometric functions and their kin | FV0704 | FV0719 |
== or != with a Date | FV0619 | FV1809 |
a part of JSON, Math, Number, String or another global the server does not translate (JSON.parse(), JSON.stringify(x, null, 2), String.fromCharCode(), decodeURIComponent()) | FV0601 | FV0633, naming what it translates of that global |
typeof x === "…" of anything but a query value | FV1234 | compiles, or FV0722 |
a prop typed Date | FV0315 | compiles |
a Date inside a list, a dictionary or an object prop | FV0315 | FV1806 |
What 0.9 newly supports (below) compiles where 0.8 refused it, mostly with FV0601 (Number.isNaN()), FV0602 (.toPrecision(), .toSorted()), FV0704 (Math.sqrt()) or FV0705 (.toFixed(2.5)). FV0619 now stands for == and != alone. FV1234 is retired: the compiler no longer raises it, and error_codes keeps it listed as retired. The title field of FV0604, FV0610, FV0706 and FV0708 names what each now covers:
| Code | Title in 0.9 |
|---|---|
| FV0604 | Field read on a value that is not an object, or that may be absent |
| FV0610 | Hole in an array literal |
| FV0706 | String that may hold half of a surrogate pair compared, searched, joined or encoded |
| FV0708 | Template literal of a value it cannot write |
Behaviour that changed
Date props in data-props
A prop typed Date travels in an island's data-props as the string toISOString() writes, and an invalid date as the bare NaN that data-props already writes for a number JSON cannot carry. mountIslands, mountPage, renderPage and ferrovue/testing's fixtureApp turn each prop the component declares a Date back into one before Vue hydrates. An application that reads an island's props itself and hands them to createSSRApp calls reviveDates(component, props), from ferrovue or ferrovue/client, first:
import { createSSRApp } from "vue";
import { reviveDates } from "ferrovue";
import Post from "./components/Post.vue";
export function hydratePost(el: HTMLElement, props: Record<string, unknown>) {
createSSRApp(Post, reviveDates(Post, props)).mount(el);
}Nothing changes for a component that takes no Date prop. One that took the ISO string as a string and built the date in a computed keeps working as it did; it can now take the date itself. In 0.8:
<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.getUTCFullYear() }}</time>
</template>In 0.9:
<script setup lang="ts">
defineProps<{ published: Date }>();
</script>
<template>
<time :datetime="published.toISOString()">{{ published.getUTCFullYear() }}</time>
</template>The Rust field is then a JsDate (or the dateType), built from milliseconds, an ISO string or the clock:
use ferrovue::JsDate;
let published = JsDate::parse("2024-05-01T09:30:00.000Z").expect("in the date time string format");
assert_eq!(published, JsDate::from_millis(1_714_555_800_000.0));
assert_eq!(published.to_iso_string().as_deref(), Some("2024-05-01T09:30:00.000Z"));
assert!(!JsDate::INVALID.is_valid());A fixture gives a Date prop as an ISO string or a number of milliseconds. serde_json writes an invalid JsDate as null, which does not read back. See dates_and_prices.
.toFixed()
.toFixed() takes a fractional literal, truncated as JavaScript truncates it, and undefined, which is .toFixed(0). Both were refused with FV0705:
<script setup lang="ts">
defineProps<{ price: number }>();
</script>
<template>
<p>{{ price.toFixed(2.5) }} {{ price.toFixed(undefined) }}</p>
</template>writes what price.toFixed(2) and price.toFixed(0) write. Any other argument that is not a literal from 0 to 100 is still FV0705.
Fixes that change generated code
Boolean(user)of an optional or nullable object, list orDate. A truthiness test that is not a narrowing wroteis_some_and(|v| true), whose unused parameter rustc warns on, which fails a build under-D warnings. It is nowis_some()..includes(v)with av-foritem namedv..includes()of a computed list, or of a list of fractions, looking for a loop item namedvcompared each item with itself, and wastruefor every list that was not empty. A template such as this one rendered every option as picked in 0.8 and renders as Vue does in 0.9:vue<script setup lang="ts"> import { computed } from "vue"; const props = defineProps<{ options: string[]; chosen: string[] }>(); const picked = computed(() => props.chosen.filter((c) => c !== "")); </script> <template> <li v-for="v in options" :class="{ on: picked.includes(v) }">{{ v }}</li> </template>A template literal that joins two halves of a surrogate pair.
`${a.charAt(0)}${b}${a.slice(1)}`, two strings that may each hold half of a pair with only a string that may be empty between them, wrote two U+FFFD where JavaScript, given an emptyb, joins the halves into one character. It is refused with FV0706, as two such strings side by side are. A component that compiled with 0.8 may stop here; see halves of surrogate pairs.FV0604 of an optional value.
.lengthor another field of a value that may be absent says that it may be absent, and to narrow it withv-ifor read it with?.. It said the value was not an object.
Newly supported
Each group links to the guide page that covers it in full.
Dates (dates_and_prices): Date props, required, optional or nullable, read in the template, a computed, v-if and v-for and handed to a child's Date prop; .toUTCString(), .toJSON() and JSON.stringify() of a date; Date.UTC() of one to seven parts (dates from their parts); <, <=, > and >= between two dates; || between dates; and a date's validity tested with Number.isNaN(d.getTime()).
Numbers (numbers): .toPrecision() and .toExponential() with no argument or a literal one; Number.isNaN(), Number.isFinite(), Number.isInteger() and Number.isSafeInteger(), of optional numbers too, and the global isNaN() and isFinite() of a present number; the constants of Number and the globals Infinity and NaN. The crate gains the public twins js_to_precision and js_to_exponential:
assert_eq!(ferrovue::js_to_precision(1234.5678, 6), "1234.57");
assert_eq!(ferrovue::js_to_exponential(0.000123, Some(2)), "1.23e-4");
assert_eq!(ferrovue::js_to_fixed(3.14159, 2), "3.14");Math (numbers): Math.sqrt(), Math.sign() (the public js_sign, for which 0, -0 and NaN are their own sign), the eight constants of Math, Math.max(...xs) and Math.min(...xs), and ** and Math.pow() of an integer and a whole exponent from 0, both known when compiling, whose result is within ±2⁵³ (2 ** 10, n * 2 ** 8).
Strings (strings): encodeURIComponent() and encodeURI() (URIs), with the public twins js_encode_uri_component and js_encode_uri; String(), template literals and .concat() of a value that may be absent, written as undefined or null, and of a list, written as its items joined by , (strings from values); positions and limits in .includes(x, i), .startsWith(x, i), .endsWith(x, i), .indexOf(x, i), .lastIndexOf(x, i) and .split(x, n); .substr(), .trimLeft(), .trimRight(), .concat(), .charCodeAt() and .codePointAt().
assert_eq!(ferrovue::js_encode_uri_component("a b&c/d"), "a%20b%26c%2Fd");
assert_eq!(ferrovue::js_encode_uri("/a b?q=1&r=é"), "/a%20b?q=1&r=%C3%A9");
assert!(ferrovue::js_sign(-0.0).is_sign_negative());Lists (strings and optional chains and list items): list[i] and list.at(i), each T | undefined, narrowed by v-if and taken by ?? and ?.; list?.[i]; optional chains that go on past ?. (user?.profile.bio, tags?.at(-1)?.toUpperCase()); .indexOf(), .lastIndexOf(), .findLast(), .findLastIndex() and .concat(); and, in building lists, .reduce() and .reduceRight() with an initial value, .toReversed(), .toSorted() without a comparator or with one of the shapes the server orders by exactly ((a, b) => a - b, a.k - b.k, a < b ? -1 : a > b ? 1 : 0), [...list].sort(…) and [...list].reverse(), and spread in array literals ([...a, x, ...b]).
typeof (props): worked out from each value's type, so typeof x === "string" and typeof x !== "undefined" narrow an optional value in v-if, && and ?:.
Refused on purpose
These stay refused, each with a message that says what to write in its place.
| Construct | Code | Why |
|---|---|---|
Math.exp(), Math.log(), Math.cbrt(), Math.hypot(), the trigonometric functions and their kin | FV0719 | each engine rounds them by its own routines |
** and Math.pow() with a runtime operand, a negative or fractional exponent, or a result beyond ±2⁵³ | FV0720 | Node 22 writes 10 ** -20 as 1.0000000000000001e-20, Node 24 and Firefox as 1e-20 |
literal parts of Date.UTC() that V8 computes by rules Firefox and Safari do not share (a year beyond ±1,000,000, a month beyond ±10,000,000, a year before −399,999, a part beyond 2⁵³ ms brought back within the range) | FV1808 | the engines give different dates; from the props, js_date_utc panics on them |
.toSorted() with a Float key or another comparator shape | FV0830 | a NaN makes the comparator inconsistent, and each engine orders the items its own way |
.toSorted() of a list of objects without a comparator | FV0831 | every item is [object Object] |
.sort() and .reverse() of a prop or state | FV0832 | they change it in place; write .toSorted() and .toReversed() |
.reduce() without an initial value | FV0828 | JavaScript throws on an empty list |
===, !==, == and != with a Date | FV1809 | two dates are equal only when they are one object; compare a.getTime() === b.getTime() |
.toLocaleString(), Intl, .localeCompare() (in a comparator too), $d and $n | FV1805 | locale data differs between Node and each browser |