日本語

Upgrading

Each change of a public signature from 0.5 to 0.16, shown as the code after it, with the line it replaces.

The releases that changed a public signature, 0.5 through 0.16, each raised the minor version, so hypersig = "0.7" in Cargo.toml stays on 0.7 until you change it. Every crate of the workspace is released at one version, so raise hypersig, hypersig_ui, hypersig_i18n, hypersig_desktop, and cargo install hypersig_cli together. The samples below are the code after each change: a line marked - is what the older release accepted, and the line marked + replaces it. The compiler stops at each line that still has the old form, so work through its errors from the top. CHANGELOG.md lists every change of every release, including the ones that need nothing from you.

From 0.15 to 0.16

Only hypersig_desktop changed a signature. App::updates turns the App into an App<Updates>, whose run hands the setup the Updater beside the Os, and Updater::check replaces Os::updates, which an application without updates had too and which failed when it was called. Name the constant's type App<Updates>, take the second argument in the setup, and call check on the Updater:

use hypersig_desktop::{App, Updater, Updates}; const APP: App = App::new("dev.example.notes").updates(Updates::new(const APP: App<Updates> = App::new("dev.example.notes").updates(Updates::new(    env!("CARGO_PKG_VERSION"),    "https://updates.example.com/notes/{{target}}/{{arch}}/{{current_version}}",    PUBLIC_KEY,)); async fn update(updater: Updater, (): ()) -> Patches<About> {    let found = state.os.updates().await;    let found = updater.check().await;    let _ = found;    Patches::new()} fn main() -> Result<(), hypersig_desktop::Error> {    APP.run(&ABOUT.url(()), |os| async move {    APP.run(&ABOUT.url(()), |_os, updater| async move {        pages(Router::new()).hypersig_runtime().with_state(updater)    })}

FakeOs::dialogs replaces FakeOs::dialogs_shown and returns a ShownDialog for each dialog the test answered, so dialogs_shown() becomes dialogs().len(). open_file, pick_folder, and save_file under FakeOs panic when the test answers with no path or with several, where they returned None or took the first path. On Windows, Downloaded::install returns Ok(()) and the installer starts after App::run has stopped the server, where the process ended inside install.

From 0.14 to 0.15

The enums the crates export are #[non_exhaustive], so a later release can add a variant without breaking your code. A match on one of them in your crate needs a _ arm, and the compiler names each match without one (E0004). They are RequestKind, Framing, Candidate, DateStyle, TimeStyle, TimeZone, and PluralCategory in hypersig, Condition, Selector, and value::CssWideKeyword in hypersig::style, and SortOrder in hypersig_ui.

fn signed_out(kind: RequestKind) -> Response {    match kind {        RequestKind::Navigation => PageResponse::redirect(LOGIN.url(())).into_response(),        RequestKind::Runtime => (StatusCode::UNAUTHORIZED, "Sign in again.").into_response(),        _ => (StatusCode::UNAUTHORIZED, "Sign in again.").into_response(),    }}

From 0.13 to 0.14

Style::line_height takes a multiplier as an f64 and no longer takes an integer. line_height(16) wrote 16 times the font size where a length of 16px was most likely meant, so it is now a compile error: write line_height(2.0) for a multiplier, or line_height(px(16)) for a length. Color::hex takes six hex digits, and a translucent color goes through the new Color::hex_alpha, which writes all eight.

let body = Style::new().line_height(2);let body = Style::new().line_height(2.0);let overlay = Style::new().background_color(Color::hex(0x2563_eb80));let overlay = Style::new().background_color(Color::hex_alpha(0x2563_eb80));

These mistakes compiled before and wrote a style or an attribute the browser ignored. They now panic where the page is built:

  • Two Keyframes with one name and different steps on one page, including one used by a Global rule. Only the first was written, so the other animation played the wrong steps. Give each its own name.
  • Color::hex with more than six hex digits, such as 0x2563_eb80. It dropped the top byte and wrote #63eb80.
  • FontFace::weights with a value outside 1 to 1000, or with the larger value first.
  • A second call of El::aria_describedby, El::aria_activedescendant, or El::popover_target on one element. The browser read only the first attribute.

From 0.12 to 0.13

Style::scrollbar_color takes the thumb's color and the track's color as a pair. It took one color before, and wrote scrollbar-color:red, which the browser drops, because the property needs both.

let style = Style::new().scrollbar_color(Color::GRAY);let style = Style::new().scrollbar_color((Color::GRAY, Color::TRANSPARENT));

These mistakes compiled and did nothing visible before, and panic now where the page is built:

  • An element inside a p at which the HTML parser ends the paragraph, such as a div, a ul, or another p. The parser moved it after the paragraph, so a condition or a list in it was drawn twice.
  • A NaN or an infinite number given to a style property, such as flex_grow(f64::INFINITY). The stylesheet held inf, which the browser drops.

From 0.11 to 0.12

hypersig_ui's Dialog::dialog and Dialog::sheet take a DialogText as their last argument, and Combobox::render a ComboboxText, as pagination takes a PaginationText. They hold the words the components wrote in English before: the name of the close button, the name of the list of options, and the text shown when no option matches. Pass &Default::default() to keep the English words, or the words of the page's language.

let cart = CART.dialog("Cart", "Two items.", p().text("Tea, cups"));let english = CART.dialog("Cart", "Two items.", p().text("Tea, cups"), &DialogText::default());let japanese = DialogText { close: "閉じる".into() };let cart = CART.dialog("カート", "2 点あります。", p().text("お茶、湯のみ"), &japanese);

These mistakes compiled before and fail to compile now:

  • A Route or Base path with a byte the browser percent-encodes, such as "/café" or "/a b". Every link to such a route got 404, because the router compares the path as the browser encoded it. Write the segment in ASCII, or take it as a parameter.
  • An action, stream, or upload path with { or }, whose handler takes no path parameters.
  • Two variants of a #[derive(Segment)] enum that serde writes as one segment.

From 0.10 to 0.11

url, the value a stylesheet loads a file from, takes a &'static str and is a const fn, as Asset::new is. It refuses an empty URL, a space or a control character, and a scheme other than http or https, so url("javascript:...") in a const fails to compile. A URL built with format! or held in a String no longer compiles: write each file's URL as a constant.

let paper = url(format!("/{}", "paper.png"));const PAPER: Url = url("/paper.png");const INTER: Url = url("/fonts/inter.woff2"); let inter = FontFace::new("Inter", url("/fonts/inter.woff2".to_owned()));let inter = FontFace::new("Inter", INTER);let style = Style::new().background_image(paper);let style = Style::new().background_image(PAPER);

These changes need no edit and may change what a page does:

  • A root path in url(..), such as /fonts/inter.woff2, goes under the routes' Base, in the page and in the patches its actions send, so an application served under /app loads /app/fonts/inter.woff2.
  • Page::render panics where an expression reads the item of one list inside another list at the same depth, which rendered the other list's item before.
  • In a debug build, Page::render panics where Page::lang names the language of an IntlLocale and the page formats its plurals and dates only with other ones.

From 0.9 to 0.10

A route parameter that holds any text is a PathSegment in place of a String. It refuses an empty value, ., and .., which a link cannot carry. PathSegment::new refuses one at compile time in a const, and PathSegment::parse returns an error for text read from data. A handler takes the PathSegment, and as_str gives its text.

hypersig::routes! {    fn pages(Router<()>);    const ORG: Route<String> = "/orgs/{org}" => org;    const ORG: Route<PathSegment> = "/orgs/{org}" => org;} let url = ORG.url(name.to_owned());let url = ORG.url(PathSegment::parse(name)?);

The other changes that need an edit:

  • Rest::new takes a &'static str. Build a Rest from text read at run time with Rest::parse, which refuses an empty rest and a . or .. part.
  • A signal field that a link reads as a segment becomes a PathSegment, and so does a String sort key of hypersig_ui's Table.
  • A #[derive(Segment)] variant renamed to an empty name, ., or .. fails to compile.

From 0.8 to 0.9

The URLs a page loads and its language are typed values now. Page::script, stylesheet, icon, and runtime_src take an Asset, and Page::lang and the hreflang of Page::alternate take a LanguageTag. Both check their text when the constant is built, and an Asset path starting with / is written under the page's Base.

const MAP_JS: Asset = Asset::new("/map.js");const JAPANESE: LanguageTag = LanguageTag::new("ja"); let page = Page::new("Map", Map {})    .lang("ja")    .lang(JAPANESE)    .script("/map.js");    .script(MAP_JS);

The other changes that need an edit:

  • Locale::ALL is gone. Locale requires Variants, which #[derive(Segment)] already writes, and the first variant is the default.
  • hypersig_ui::Tabs::new and Listbox::new take one closure over every variant in place of .tab(..) and .option(..), and Accordion::exclusive takes an Id.
  • UploadedFile::file_name and StreamedFile::file_name return Option<FileName>. Call base_name for a name to store a file under.
  • hypersig_ui::Chart has two type parameters. Code that named the third drops it.
  • A test that builds a GET action request by hand adds the hypersig-call header, or uses Action::request, which adds it.
  • Two elements with one Id::with_key id, a Page::computed signal named twice or read before it is computed, a form rule that reads Expr::now, and a list item read outside its list now panic while the page is built.

From 0.7 to 0.8

One Page::framing call sets which sites may show the page in a frame, in place of framed_by and framed_anywhere. The attributes that hold URLs or CSS left html::attr, so each has a method that takes the checked type: El::srcset a SafeUrl and a Candidate per image, El::poster a SafeUrl, and El::css or El::bind_style the style. el(tag!("link")) no longer compiles, and Page::stylesheet and Page::icon write the page's <link> elements.

const PORTAL: Origin = Origin::new("https://portal.example"); let page = Page::new("Widget", Widget {})    .framed_by(PORTAL)    .framing(Framing::Origins(vec![PORTAL]))    .child(        img()            .src(SafeUrl::new("/a-480.png"))            .attr(attr::SRCSET, "/a-480.png 480w, /a-960.png 960w")            .srcset([                (SafeUrl::new("/a-480.png"), Candidate::Width(480)),                (SafeUrl::new("/a-960.png"), Candidate::Width(960)),            ])            .attr(attr::STYLE, "max-width: 100%"),            .css(Style::new().max_width(pct(100))),    )    .child(video().attr(attr::POSTER, "/intro.jpg"));    .child(video().poster(SafeUrl::new("/intro.jpg")));

0.8.2 changes no signature, but several mistakes that used to do nothing visible now panic while the page is built, so a page that panics after the upgrade had one of them:

  • A second show, bind_text, id, node_ref, foreign, or binding on one element, which used to replace the first.
  • One static attribute set twice, through attr or a method such as role. The browser keeps only the first.
  • A binding on an element the runtime does not bind, such as bind on a <div>.
  • An on_interval of 0, or an on_interval, on_timeout, or on_debounced longer than 2^31 - 1 ms, which the browser runs at once.

From 0.6 to 0.7

A field that Page::computed keeps equal to an expression is marked #[signals(computed)] in the struct, and its Sig has no set, toggle, list statement, bind, or patch. In 0.6 a write to it compiled, and the written value stayed on screen until a signal the expression reads changed. Write one of those signals instead, as the button below now empties quantity.

#[derive(Signals, Serialize, Deserialize)]struct Cart {    price: f64,    quantity: i32,    #[signals(computed)]    total: f64,} let page = Page::new("Cart", Cart { price: 2.5, quantity: 3, total: 0.0 })    .computed(Cart::total(), Cart::price() * Cart::quantity().to_f64())    .child(span().bind_text(Cart::total().to_text()))    .child(button().on_click(Cart::total().set(0.0)).text("Clear"));    .child(button().on_click(Cart::quantity().set(0)).text("Clear"));

From 0.5 to 0.6

An action, a stream, and an upload are lines of routes!, each with its handler, so Action::post, StreamAction::new, Upload::post, and the router's .action(ADD, add) are gone. Move each constant into the block that serves its page and delete the registration. A NodeRef or DialogRef is declared with node_ref! or dialog_ref! at module level, which names it after the constant's path. The methods of Expr take &self, so a .clone() written to call one can go, and a method passed as a function, such as Expr::and, becomes a closure.

const ADD: Action<Todos, String> = Action::post("/todos");hypersig::routes! {    fn pages(Router<()>);    const INDEX: Route = "/" => index;    action ADD: Action<Todos, String> = post "/todos" => add;} const DRAFT: NodeRef<Todos> = NodeRef::new("draft");hypersig::node_ref!(const DRAFT: NodeRef<Todos>); async fn index((): (), (): ()) -> Page<Todos> {    let left = Todos::total() - Todos::done();    Page::new("Todos", Todos { draft: String::new(), total: 0, done: 0 }).child(        div()            .child(input().node_ref(DRAFT).bind(Todos::draft()))            .child(button().on_click(ADD.call_with(Todos::draft())).text("Add"))            .child(span().show(left.clone().gt(0)).bind_text(left.to_text())),            .child(span().show(left.gt(0)).bind_text(left.to_text())),    )} async fn add((): (), _draft: String) -> Patches<Todos> {    Todos::draft().patch(String::new()).into()} let app: Router = pages(Router::new()).action(ADD, add).hypersig_runtime();let app: Router = pages(Router::new()).hypersig_runtime();

hypersig_ui's Tooltip::new, Menu::new, Dialog::new, and Combobox::new take the NodeRef or DialogRef in place of a name.

From 0.4 to 0.5

Attribute names, roles, ids, and tag names are types. attr, bind_attr, and attr_when take an Attr: a constant of html::attr, or attr! for a name the list lacks, such as a data- attribute. The role is El::role. El::id takes an Id, and an attribute that points at an element, such as for or aria-describedby, has a method that takes the same Id, so the two cannot be spelled apart. el takes the Tag that tag! checks at compile time. Code that cargo hypersig elements wrote for 0.4 is written again by the 0.5 command.

const QUERY: &str = "query";const QUERY: Id = Id::new("query"); let form = div::<Search>()    .attr("role", "search")    .role(Role::Search)    .attr("aria-label", "Docs")    .attr(attr::ARIA_LABEL, "Docs")    .attr("data-lat", "35.68")    .attr(hypersig::attr!("data-lat"), "35.68")    .child(label().attr("for", QUERY).text("Search"))    .child(label().label_for(&QUERY).text("Search"))    .child(input().id(QUERY).bind(Search::query()))    .child(el("sl-rating"));    .child(el(hypersig::tag!("sl-rating")));