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:
pnpm add -D ferrovue@^0.12.0and the crate, in Cargo.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
pnpm ferrovueThe 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:
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 againThe 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:
| Module | What it holds |
|---|---|
html | A component's HTML (Html, Hydrate), and the HTML a caller hands v-html (TrustedHtml, BasicHtml, InlineHtml, Sanitised) |
render | What a render takes beside its props and what it refuses: Slot, slot_into, Refused |
props | Record, Union, ParseUnionError |
date | JsDate, JsTime, DateOutOfRange |
head | Head, HeadHtml, HeadValue |
page | Page and its parts, slots, holes and record, hole, split_holes, Chunks, Teleports, state_script_into |
loaders | Loads, LoadError, load |
attrs | Attr, Attrs, attrs_into, passed_attrs_into |
web | HtmlStream, and the responses for axum, actix-web and maud (the stream, axum, actix-web and maud features) |
testing | check_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.
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.11 | 0.12 | Feature |
|---|---|---|
ferrovue::BasicHtml | ferrovue::html::BasicHtml | |
ferrovue::Html | ferrovue::html::Html | |
ferrovue::Hydrate | ferrovue::html::Hydrate | |
ferrovue::InlineHtml | ferrovue::html::InlineHtml | |
ferrovue::Sanitised | ferrovue::html::Sanitised | ammonia |
ferrovue::TrustedHtml | ferrovue::html::TrustedHtml | |
ferrovue::Refused | ferrovue::render::Refused | |
ferrovue::Slot | ferrovue::render::Slot | |
ferrovue::slot_into | ferrovue::render::slot_into | |
ferrovue::ParseUnionError | ferrovue::props::ParseUnionError | |
ferrovue::Record | ferrovue::props::Record | |
ferrovue::Union | ferrovue::props::Union | |
ferrovue::DateOutOfRange | ferrovue::date::DateOutOfRange | chrono |
ferrovue::JsDate | ferrovue::date::JsDate | |
ferrovue::JsTime | ferrovue::date::JsTime | |
ferrovue::Head | ferrovue::head::Head | |
ferrovue::HeadHtml | ferrovue::head::HeadHtml | |
ferrovue::HeadValue | ferrovue::head::HeadValue | |
ferrovue::Chunks | ferrovue::page::Chunks | |
ferrovue::ManifestError | ferrovue::page::ManifestError | |
ferrovue::Page | ferrovue::page::Page | |
ferrovue::PageHole | ferrovue::page::PageHole | |
ferrovue::PageRecord | ferrovue::page::PageRecord | |
ferrovue::PageScript | ferrovue::page::PageScript | |
ferrovue::PageSlot | ferrovue::page::PageSlot | |
ferrovue::Part | ferrovue::page::Part | |
ferrovue::Preloads | ferrovue::page::Preloads | |
ferrovue::Teleports | ferrovue::page::Teleports | |
ferrovue::hole | ferrovue::page::hole | |
ferrovue::split_holes | ferrovue::page::split_holes | |
ferrovue::state_script_into | ferrovue::page::state_script_into | |
ferrovue::LoadError | ferrovue::loaders::LoadError | |
ferrovue::Loads | ferrovue::loaders::Loads | |
ferrovue::load | ferrovue::loaders::load | |
ferrovue::Attr | ferrovue::attrs::Attr | |
ferrovue::Attrs | ferrovue::attrs::Attrs | |
ferrovue::attrs_into | ferrovue::attrs::attrs_into | |
ferrovue::passed_attrs_into | ferrovue::attrs::passed_attrs_into | |
ferrovue::HtmlStream | ferrovue::web::HtmlStream | stream |
ferrovue::check_fixtures | ferrovue::testing::check_fixtures | |
ferrovue::Js | ferrovue::core::Js | |
ferrovue::escape_into | ferrovue::core::escape_into | |
ferrovue::js_encode_uri | ferrovue::core::js_encode_uri | |
ferrovue::js_encode_uri_component | ferrovue::core::js_encode_uri_component | |
ferrovue::js_max | ferrovue::core::js_max | |
ferrovue::js_min | ferrovue::core::js_min | |
ferrovue::js_round | ferrovue::core::js_round | |
ferrovue::js_sign | ferrovue::core::js_sign | |
ferrovue::js_to_exponential | ferrovue::core::js_to_exponential | |
ferrovue::js_to_fixed | ferrovue::core::js_to_fixed | |
ferrovue::js_to_precision | ferrovue::core::js_to_precision | |
ferrovue::push_int | ferrovue::core::push_int | |
ferrovue::push_number | ferrovue::core::push_number | |
ferrovue::Link | ferrovue::router::Link | router |
ferrovue::Query | ferrovue::router::Query | router |
ferrovue::Route | ferrovue::router::Route | router |
ferrovue::RouteDef | ferrovue::router::RouteDef | router |
ferrovue::Router | ferrovue::router::Router | router |
ferrovue::query_into | ferrovue::router::query_into | router |
ferrovue::I18n | ferrovue::i18n::I18n | i18n |
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_into | ferrovue::html |
Refusals, is_comment, rendered, scoped_slot_into, scoped_slot_into_slotted, slot_into_slotted, try_int | ferrovue::render |
ParseUnion, UnionShape, check_union, union_prop | ferrovue::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_string | ferrovue::date |
HeadDeferral | ferrovue::head |
teleport_into | ferrovue::page |
Load, LoadArg, LoadCall, LoadFuture, LoadKey, load_key | ferrovue::loaders |
class_into, class_names, class_object, merge_props, scope_attrs, style_text_into | ferrovue::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_repeat | ferrovue::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:
| Key | 0.11 | 0.12 |
|---|---|---|
dateType | ferrovue::JsDate, the default | ferrovue::date::JsDate, the default |
trustedHtml | ferrovue::BasicHtml, ferrovue::InlineHtml, ferrovue::Sanitised | ferrovue::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.11 | 0.12 |
|---|---|
everything from ferrovue/client | ferrovue, which exports the same items, clearLoads among them |
Float, InlineHtml, TrustedHtml from ferrovue | ferrovue/types, as components import them |
CONFIG_FILE, loadConfig, TYPES_MODULE, Config, HelperSpec, RoutesSource, ScopeIdMode, TwinSpec, TypeName from ferrovue/compiler | ferrovue/compiler/config |
GenError, GenErrors, SourceLocation, ERRORS, ErrorCode, ErrorDoc, docsUrl from ferrovue/compiler | ferrovue/compiler/errors |
attachSsrRender from ferrovue/testing | ferrovue/testing/ssr |
fixtureApp, readFixture, Fixture, RouterOptions, hydrateRecordedPage, renderRecordedPage, RecordedPage from ferrovue/testing | ferrovue/testing/browser |
IslandComponent, MountOptions, PageOptions, PagePart, PageRecord, RenderPageOptions from ferrovue/testing | ferrovue |
routeRecords, RouteEntry from ferrovue/link-router or ferrovue/testing, and RouteEntry from ferrovue/routes | ferrovue/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.
// 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:
| Source | 0.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 union | FV0111 |
| a lookup table whose values are members of a union, holding a value outside it | FV0228 |
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.