Skip to content

Upgrading to 0.12 ​

Upgrading a project from ferrovue 0.11 to 0.12: the steps to take and what behaves differently.

The CHANGELOG lists every change; this page picks out what an application notices. Most of it is one change: every item of the crates and of the npm package is named at the module or entry that defines it, and nothing is lifted to a root above it. A re-export cannot carry #[deprecated], so every path moves in 0.12, with no release that deprecates the old paths first. Steps 3 and 4 cover that change, with a table of every path that moved. The other changes of 0.12 to unions of string literals have sections of their own, steps 5 and 6 and Behaviour that changed. The page for the release before is upgrading_to_0_11.

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:

sh
pnpm add -D ferrovue@^0.12.0

and the crate, in Cargo.toml:

toml
ferrovue = "0.12"

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.12 as well. A project that lists ferrovue@0.11.0 in pnpm's minimumReleaseAgeExclude adds ferrovue@0.12.0 beside it, and removes the 0.11.0 entry once the lockfile no longer holds it: pnpm checks the lockfile against the policy before it resolves again.

2. Generate every component again ​

sh
pnpm ferrovue

The 0.12 compiler writes version 6 of generated code, and mod.rs opens with ferrovue::__compat!(6). Version 6 reads the literal of every union's enum through Union, which the 0.11 crate lacks, and names every item of the crates at the module that defines it: fv::html::Html, fv::render::Refused, fv::router::Route, fv::core::escape_into. The 0.12 crate no longer has the paths earlier versions call, so it supports version 6 alone, and stops a module generated by 0.11 at its first line:

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

The 0.11 crate supports versions 2 to 5, and stops a module of version 6 the same way. Every generated file changes once. A CI job that runs pnpm ferrovue --check reports each module as stale until it is generated again with 0.12 and committed. See the version check.

3. Name the crates' items at their modules ​

The ferrovue crate's items are in public modules, one per concept, and each item is reached through the module that defines it:

ModuleWhat it holds
htmlA component's HTML (Html, Hydrate), and the HTML a caller hands v-html (TrustedHtml, BasicHtml, InlineHtml, Sanitised)
renderWhat a render takes beside its props and what it refuses: Slot, slot_into, Refused
propsRecord, Union, ParseUnionError
dateJsDate, JsTime, DateOutOfRange
headHead, HeadHtml, HeadValue
pagePage and its parts, slots, holes and record, hole, split_holes, Chunks, Teleports, state_script_into
loadersLoads, LoadError, load
attrsAttr, Attrs, attrs_into, passed_attrs_into
webHtmlStream, and the responses for axum, actix-web and maud (the stream, axum, actix-web and maud features)
testingcheck_fixtures, which conformance! calls

The three crates ferrovue depends on are its modules core, router and i18n, whole: ferrovue::Router is ferrovue::router::Router, ferrovue::escape_into is ferrovue::core::escape_into. ferrovue::dioxus keeps its path. ferrovue::i18n was a module before and keeps every path below it (ferrovue::i18n::Args); ferrovue::I18n is ferrovue::i18n::I18n.

rust
use ferrovue::core::escape_into;
use ferrovue::props::Record;
use ferrovue::router::Router;

// 0.11: ferrovue::Router, ferrovue::escape_into and ferrovue::Record.
let router = Router::new(&["/", "/books/:id"]);
assert_eq!(router.at("/books/dune").param("id"), Some("dune"));

let mut out = String::new();
escape_into(&mut out, "Tom & Jerry");
assert_eq!(out, "Tom & Jerry");

let scores: Record<'_, i64> = [("b", 1), ("10", 2)].into_iter().collect();
assert_eq!(scores.keys().collect::<Vec<_>>(), ["10", "b"]);

The Rust of an application stops compiling at each path that moved. For a path written in full (ferrovue::state_script_into(…)), rustc says the item is not found in ferrovue and suggests no module, so this table is the reference. Each item and the path it has now:

0.110.12Feature
ferrovue::BasicHtmlferrovue::html::BasicHtml
ferrovue::Htmlferrovue::html::Html
ferrovue::Hydrateferrovue::html::Hydrate
ferrovue::InlineHtmlferrovue::html::InlineHtml
ferrovue::Sanitisedferrovue::html::Sanitisedammonia
ferrovue::TrustedHtmlferrovue::html::TrustedHtml
ferrovue::Refusedferrovue::render::Refused
ferrovue::Slotferrovue::render::Slot
ferrovue::slot_intoferrovue::render::slot_into
ferrovue::ParseUnionErrorferrovue::props::ParseUnionError
ferrovue::Recordferrovue::props::Record
ferrovue::Unionferrovue::props::Union
ferrovue::DateOutOfRangeferrovue::date::DateOutOfRangechrono
ferrovue::JsDateferrovue::date::JsDate
ferrovue::JsTimeferrovue::date::JsTime
ferrovue::Headferrovue::head::Head
ferrovue::HeadHtmlferrovue::head::HeadHtml
ferrovue::HeadValueferrovue::head::HeadValue
ferrovue::Chunksferrovue::page::Chunks
ferrovue::ManifestErrorferrovue::page::ManifestError
ferrovue::Pageferrovue::page::Page
ferrovue::PageHoleferrovue::page::PageHole
ferrovue::PageRecordferrovue::page::PageRecord
ferrovue::PageScriptferrovue::page::PageScript
ferrovue::PageSlotferrovue::page::PageSlot
ferrovue::Partferrovue::page::Part
ferrovue::Preloadsferrovue::page::Preloads
ferrovue::Teleportsferrovue::page::Teleports
ferrovue::holeferrovue::page::hole
ferrovue::split_holesferrovue::page::split_holes
ferrovue::state_script_intoferrovue::page::state_script_into
ferrovue::LoadErrorferrovue::loaders::LoadError
ferrovue::Loadsferrovue::loaders::Loads
ferrovue::loadferrovue::loaders::load
ferrovue::Attrferrovue::attrs::Attr
ferrovue::Attrsferrovue::attrs::Attrs
ferrovue::attrs_intoferrovue::attrs::attrs_into
ferrovue::passed_attrs_intoferrovue::attrs::passed_attrs_into
ferrovue::HtmlStreamferrovue::web::HtmlStreamstream
ferrovue::check_fixturesferrovue::testing::check_fixtures
ferrovue::Jsferrovue::core::Js
ferrovue::escape_intoferrovue::core::escape_into
ferrovue::js_encode_uriferrovue::core::js_encode_uri
ferrovue::js_encode_uri_componentferrovue::core::js_encode_uri_component
ferrovue::js_maxferrovue::core::js_max
ferrovue::js_minferrovue::core::js_min
ferrovue::js_roundferrovue::core::js_round
ferrovue::js_signferrovue::core::js_sign
ferrovue::js_to_exponentialferrovue::core::js_to_exponential
ferrovue::js_to_fixedferrovue::core::js_to_fixed
ferrovue::js_to_precisionferrovue::core::js_to_precision
ferrovue::push_intferrovue::core::push_int
ferrovue::push_numberferrovue::core::push_number
ferrovue::Linkferrovue::router::Linkrouter
ferrovue::Queryferrovue::router::Queryrouter
ferrovue::Routeferrovue::router::Routerouter
ferrovue::RouteDefferrovue::router::RouteDefrouter
ferrovue::Routerferrovue::router::Routerrouter
ferrovue::query_intoferrovue::router::query_intorouter
ferrovue::I18nferrovue::i18n::I18ni18n

The items only generated code calls are #[doc(hidden)], where they are defined, as before. Hand-written Rust that copied generated code finds them in these modules:

0.11, at ferrovue::0.12
Fallible, Renderer, trusted_intoferrovue::html
Refusals, is_comment, rendered, scoped_slot_into, scoped_slot_into_slotted, slot_into_slotted, try_intferrovue::render
ParseUnion, UnionShape, check_union, union_propferrovue::props
DateShape, date_prop, dates_in, js_date_parse, js_date_prop, js_date_utc, js_json_date, js_time_clip, js_time_of, js_to_iso_string, js_to_json, js_to_utc_string, js_utc_date, js_utc_day, js_utc_full_year, js_utc_hours, js_utc_milliseconds, js_utc_minutes, js_utc_month, js_utc_seconds, opt_date_prop, try_date_parse, try_date_utc, try_to_iso_stringferrovue::date
HeadDeferralferrovue::head
teleport_intoferrovue::page
Load, LoadArg, LoadCall, LoadFuture, LoadKey, load_keyferrovue::loaders
class_into, class_names, class_object, merge_props, scope_attrs, style_text_intoferrovue::attrs
JsOr, js_at, js_char_at, js_char_code_at, js_cmp, js_code_point_at, js_ends_with_at, js_includes_from, js_index_of, js_index_of_from, js_item_at, js_json_number, js_json_string, js_last_index_of, js_last_index_of_from, js_length, js_number, js_order, js_pad_end, js_pad_start, js_parse_float, js_parse_int, js_reduce, js_repeat, js_replace, js_replace_all, js_slice, js_slice_items, js_slice_range, js_sorted, js_sorted_by_string, js_split, js_split_limit, js_starts_with_at, js_substr, js_substring, js_trim, js_trim_end, js_trim_start, try_pad_end, try_pad_start, try_repeatferrovue::strings

ferrovue-core, ferrovue-router and ferrovue-i18n define their items at their roots, so an application that names one of them itself keeps its paths (ferrovue_core::escape_into).

ferrovue::core is the ferrovue-core crate. A module that imports it by name, or every module of ferrovue with use ferrovue::*;, has the name core bound to it, which hides Rust's own core crate from paths written in that module: write ::core::mem::swap there, with the leading ::. Generated code and a module that names ferrovue::core::… in full are not affected.

The configuration names Rust types by their paths too. Where ferrovue.config.json names one of the crate's, it names the new path:

Key0.110.12
dateTypeferrovue::JsDate, the defaultferrovue::date::JsDate, the default
trustedHtmlferrovue::BasicHtml, ferrovue::InlineHtml, ferrovue::Sanitisedferrovue::html::BasicHtml, ferrovue::html::InlineHtml, ferrovue::html::Sanitised

A key that leaves its default needs no change. A type of the application's own that implements JsTime, TrustedHtml or Union names the trait at its module in its impl.

4. Import the npm package's items from their entries ​

Each entry of the npm package exports only what its own file defines. The items an entry gathered from other files are exported by the entry that defines them, some of them new:

0.110.12
everything from ferrovue/clientferrovue, which exports the same items, clearLoads among them
Float, InlineHtml, TrustedHtml from ferrovueferrovue/types, as components import them
CONFIG_FILE, loadConfig, TYPES_MODULE, Config, HelperSpec, RoutesSource, ScopeIdMode, TwinSpec, TypeName from ferrovue/compilerferrovue/compiler/config
GenError, GenErrors, SourceLocation, ERRORS, ErrorCode, ErrorDoc, docsUrl from ferrovue/compilerferrovue/compiler/errors
attachSsrRender from ferrovue/testingferrovue/testing/ssr
fixtureApp, readFixture, Fixture, RouterOptions, hydrateRecordedPage, renderRecordedPage, RecordedPage from ferrovue/testingferrovue/testing/browser
IslandComponent, MountOptions, PageOptions, PagePart, PageRecord, RenderPageOptions from ferrovue/testingferrovue
routeRecords, RouteEntry from ferrovue/link-router or ferrovue/testing, and RouteEntry from ferrovue/routesferrovue/route-records

The rest stay where they were: the browser API in ferrovue; generate, write, isGenerated, Alias, ResolveOptions, Written and VERSION in ferrovue/compiler; conformanceSuite and ConformanceOptions in ferrovue/testing; linkRouter and LinkRouterOptions in ferrovue/link-router; and ferrovue/types, ferrovue/islands, ferrovue/routes, ferrovue/vite and ferrovue/volar, whose items they define.

ts
// 0.11
import { ClientOnly } from "ferrovue/client";
import { fixtureApp, hydrateRecordedPage, readFixture } from "ferrovue/testing";
import { linkRouter, routeRecords } from "ferrovue/link-router";

// 0.12
import { ClientOnly } from "ferrovue";
import { fixtureApp, hydrateRecordedPage, readFixture } from "ferrovue/testing/browser";
import { linkRouter } from "ferrovue/link-router";
import { routeRecords } from "ferrovue/route-records";

ferrovue/testing/browser and ferrovue/route-records load no module of Node, so a test that runs in a browser imports them as the conformance suite's browser tests do.

The compiler reads <ClientOnly> and defineLoader from ferrovue alone. A component that still imports them from ferrovue/client is refused where it uses them: <ClientOnly> as a child component that is not one of the project's, and a loader's await as a call that is not a loader's.

5. Build lists of a union from the enum ​

A prop or an interface's field typed as a list of a union of string literals (tones: Tone[]) is a list of the union's enum: Vec<Tone>, Option<Vec<Tone>> when it is optional or nullable, and Vec<Option<Tone>> for (Tone | null)[]. 0.11 made it a list of strings. Its constructor argument or setter takes impl IntoIterator<Item = Tone>, so vec!["warm".into()] becomes [Tone::Warm], and a list of strings from a request is parsed into the enum first. The JSON of an island and of a page's record are unchanged for members of the union. A fixture that gives such a list a string outside the union ({"tones": ["warm", "\"><script>"]}, often a hostile one) no longer loads in check_fixtures or conformance!, since the list deserializes into the enum: move the hostile string to a prop typed string, and record the fixture again. A string that the Rust caller holds where the render needs the union's enum (a value of a Record<string, Tone>, a store's state, a prop of a single literal) is parsed as the component renders, and one outside the union refuses the render with FV0518.

6. Name the application's own enums for unions, where it has them ​

unions in ferrovue.config.json names an enum of the application's own for a union's type alias, which then takes the place of the enum the compiler generates for it. The enum implements the new trait Union and has a variant of the name ferrovue would generate for each literal. A project that leaves unions out has nothing to change. See Unions mapped to existing enums.

7. Error codes your CI matches ​

These sources compiled with 0.11 and are refused with 0.12:

Source0.12
a computed, a ref or a constant of setup annotated as a union of string literals whose body may give another string, read where a child's prop or an object literal's field takes the unionFV0111
a lookup table whose values are members of a union, holding a value outside itFV0228

And these are new, for unions: FV0329 (an entry for an alias that is not a union of two or more string literals), FV0330 (two unions of the entry's name with other members), FV1119 (a path that is not one of a Rust type) and FV1120 (an entry no prop or field is typed with).

Behaviour that changed ​

A ref of a union holds its enum ​

A ref typed as a union of string literals (ref<Choice>(…) with type Choice = Tone | "") holds the union's enum, and a lookup table it reads is a match over the variants. 0.11 held the string, and the last arm of such a match stood for one member. The enum is written to types.rs for a union of a .ts file and named after the component and the ref for one in place, so the generated code holds more enums; the props, the island's JSON and Pinia state are unchanged.