Upgrading to 0.16
Upgrading a project from ferrovue 0.15 to 0.16: the steps to take and what behaves differently.
The CHANGELOG lists every change; this page picks out what an application notices. The steps are to bump both halves together and to generate every component again, for version 9 of generated code. A page renders in fewer instructions, and its HTML is what 0.15 wrote outside an island's data-props and two boolean attributes. The compiler checks a project's configuration more closely, and two new options close the ways a request could reach a page behind middleware and user HTML could mount an island. An upgrade to 0.15 took only the bump, so the page for the release before is upgrading_to_0_14.
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.16.0and the crate, in Cargo.toml:
ferrovue = "0.16"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.16 as well. A project that lists ferrovue@0.15.2 in pnpm's minimumReleaseAgeExclude adds ferrovue@0.16.0 beside it, and removes the 0.15.2 entry once the lockfile no longer holds it.
The 0.16 npm package compiles with @vue/compiler-sfc 3.5.45, and the vue peer range moves to ~3.5.45. The other peers keep the ranges of 0.15:
pnpm add vue@~3.5.452. Generate every component again
pnpm ferrovueThe 0.16 compiler writes version 9 of generated code, and mod.rs opens with ferrovue::__compat!(9). Version 9 writes the string a list's .join() builds straight into the page, item by item, with helpers the 0.15 crate lacks. The 0.16 crate supports versions 6 to 9, so a module generated by 0.15 still builds against it. The 0.15 crate stops a module of version 9 at its first line:
error: this module was generated as version 9 of ferrovue's generated code, and this `ferrovue` crate supports versions 6 to 8: use the `ferrovue` npm package and the `ferrovue` crate of one release, and run `ferrovue` to generate the module againMost generated files change once. A render writes the text beside a v-if or ?: inside each branch, writes text that needs no escaping without escape_into, writes formatted text into the page as it escapes it, and writes a <RouterLink> with a string or object to in place, and the modules lose their stray blank lines. A module imports std::borrow::Cow and writes Cow, and a field keeps #[serde(rename)] only where its JSON key differs from its name, so props read and write the same JSON. What a render writes is the same. A CI job that runs pnpm ferrovue --check reports each module as stale until it is generated again with 0.16 and committed. See the version check.
Behaviour that changed
Renders run fewer instructions
Outside the changes below, the HTML of every page is byte for byte what 0.15 wrote, in fewer instructions and allocations:
escape_intoescapes in one pass, which helps most on long strings, and the bench renders run up to 9% fewer instructions.- A
.join()writes into the page with no string built per item: renders that join a list run up to 25% fewer instructions. - A
<RouterLink>with a stringto, or atoof{ name, … }or{ path, … }, is resolved and written into the page with no allocation beyond a query it builds: thesmallbench, which holds two links, runs 55% fewer instructions. Head::renderborrows what it was pushed: the bench head renders in 59% fewer instructions. AHead'sDebugoutput shows unhead's defaults asDefaults.- Formatted text, such as a template literal or a number with a unit, is escaped as it is written, with no string built first, and so is a template literal passed as a fallthrough attribute: the conformance components that format text allocate 6 to 40% less often.
- A struct or a list handed to a child, and a list of strings a
computedholds, keep their strings borrowed from the props, copying no text. - Long inputs cost time in proportion to their length: a
useHeadclass of 16,000 names, 48 KB of unclosed/*in a:style, av-forover every index of a 16,000-character prop, a query of thousands of keys inRouter::atand a page of 1,000 streamed holes each take a few milliseconds, where 0.15 took up to 411 ms.
A test that counts allocations or instructions of a render sees lower numbers. See how a render writes text.
Two more boolean attributes
Vue 3.5.45 adds disablepictureinpicture and disableremoteplayback to its boolean attributes, and 0.16 writes them as Vue does. Bound, or falling through to a child's root, true writes the name alone and false leaves the attribute out; 0.15 wrote disablepictureinpicture="true" and disablepictureinpicture="false". A project whose fixtures hold such an attribute records them again. See attribute values.
An island's props are in single quotes
An island's data-props is written in single quotes, with only & and ' escaped, as data-props='{"n":1}'; 0.15 wrote data-props="{"n":1}". The browser gives dataset.props back as the same JSON, so mountIslands reads it unchanged, and the props take 7 to 28% fewer bytes. A project whose fixtures or tests hold an island's HTML records them again. See islands.
A template literal passed as an attribute formats as it is written
A template literal a parent passes as a fallthrough attribute, :title="${a}-${b}", reaches the child's Attrs as a hidden Attr value that formats itself when it is written; 0.15 passed an Attr::Str it had built. attrs_into and passed_attrs_into write it as they write a string, and it equals Attr::str of its text. A Rust twin that reads a passed value by matching Attr::Str reads it with ==. See how a render writes text.
The Vite plugin gives plugin-vue trimEdges
With "whitespace": "trim-edges", the Vite plugin adds trimEdges, with the classes of preserveWhitespace, to a plugin-vue that has no trimEdges of its own. A vite.config.ts and a Vitest config that use the Vite plugin can drop nodeTransforms: [trimEdges]. A plugin-vue given trimEdges by hand keeps it, and a Vitest config with plugin-vue alone still adds it. See whitespace.
Two warnings under trim-edges
pnpm ferrovue may print two new warnings with "whitespace": "trim-edges", and writes the modules all the same. FV0427 names a line break that renders as a space beside a class listed in the new inlineBlockClasses, which lists none until a project sets it. FV0428 names a Tailwind whitespace-pre* class on an element whose contents trim-edges renders otherwise than Vue does: list it in preserveWhitespace.classes, and the element renders as Vue spaces it, which changes its HTML. See the error codes.
Linking the stylesheets
An island's <style> goes into its chunk, and Vite links it only once the island's script has loaded, so the server's markup shows unstyled until then. Chunks now reads each chunk's css from Vite's manifest, and Stylesheets writes the <link rel="stylesheet">s of the entry, its lazily loaded islands and the islands a page renders, each once. A server that read the manifest's css itself, as the full-stack example did, can use them instead, and Chunks::script_for_entry gives the entry's script. See linking the stylesheets.
Document links the stylesheets
Document::with_entry and with_islands also write a <link rel="stylesheet"> for each stylesheet the entry and the islands need, on a line of their own before the modulepreloads. A page that linked them itself next to a Document links each twice: drop its own links. See the page shell.
The configuration is checked more closely
pnpm ferrovue refuses a ferrovue.config.json whose values would reach the generated Rust as code: a helper's rust that is not a path (FV1121), a dateType or trustedHtml that is not a Rust type (FV1122), and any string that holds a line break or another control character (FV1123). A path such as crate::helpers::plural passes as before, and so does a type such as chrono::DateTime<chrono::Utc> or crate::render::Trusted<'a>. Where out holds a file of a module's name that does not open with // @generated by ferrovue, such as a hand-written mod.rs, ferrovue leaves it alone and stops with FV1124; 0.15 wrote over it. Move such a file out of out. See the error codes.
A fractional plural count refuses the render
t() with a fractional count or n between -2 and 2 on a message of three cases refuses the render with FV1414, as vue-i18n throws there; 0.15 wrote nothing, or panicked in a debug build. A generated try_render returns the refusal, and render panics with its message. Round such a count before it reaches the template. See translating with vue-i18n.
Links to another host are refused
linkRoutes and linkRouter fail a navigation whose href a browser reads as another host, such as //evil.example/x or /\evil.example/x, with an error, and never hand it to navigate. Such an href comes from a relative link on a page whose path starts with //. The server still writes those links as vue-router resolves them, so answer such a path before resolving it, as a page from the fallback does.
The state and the page record come only from a script
hydrateState and mountPage read their JSON from the first <script> with its id, as readPage does, and pass over any other element with that id, such as one in user HTML. A page that wrote the state or the record in another element writes it with state_script_into or PageRecord::script_into. See the state script and the page record.
New options worth turning on
Matching paths exactly
ferrovue's router matches a path as vue-router does by default: case-insensitively, and with or without a trailing slash. A web framework's own routes match exactly, so /Admin or /admin/ misses a framework route and its middleware, and a page rendered from the fallback still shows it. Set "strict": true and "sensitive": true under router, and the same options in createRouter, and route_table.rs builds a router that matches as exactly as the framework does. A server can also check access where it renders the page, by the route Router::at resolves. See matching paths exactly and routes behind middleware.
Islands only the server wrote
User HTML rendered with v-html keeps data-island and data-props when the sanitiser allows data-* attributes, as DOMPurify does by default, and mountIslands would mount it as an island with the props it chose. Render each page inside a fresh IslandKey's scope and write its script, and mountIslands mounts only the islands carrying the key. A page without the script mounts every island, as 0.15 did. See islands only the server wrote.