Skip to content

v0.7.6

Latest

Choose a tag to compare

@schell schell released this 14 Jul 22:30

mogwai 0.7.6

Released 2026-07-15.

Breaking changes

  • mogwai-macros bumped from 0.2.0 to 0.2.2. The mogwai-macros dependency
    in mogwai/Cargo.toml now requires >= 0.2.1.
  • web-sys feature: "console" added to the required web-sys features
    list. If your downstream Cargo.toml pins web-sys features explicitly,
    add "console".

New features

Listener and Callback — a generic JS callback bridge

(mogwai::web::event)

A new low-level event primitive that generalizes the existing EventListener
pattern beyond DOM events. Listener<I, O> and Callback<Params> let you
wrap any JavaScript callback — not just addEventListener-style DOM events
— and await it as a Rust future. The input type I is a tuple matching the JS
callback's arity (0 through 8):

let (callback, listener) = Listener::new(|(v,): (JsValue,)| v.as_f64().unwrap_or(0.0));
// Give callback.function() to any JS API that expects a function.
some_js_obj.set_on_event(Some(callback.function()));
let value: f64 = listener.next().await;

Multiple calls to listener.next() before the next callback invocation all
resolve simultaneously (fan-out). Each next() call returns a fresh,
independent future. Callback is Clone and must be kept alive for as long
as JS might invoke it.

EventListener is now a thin convenience wrapper around
Listener<(JsValue,), web_sys::Event>.

#[derive(ViewProperties)]

(mogwai-macros)

A new derive macro that proxies all ViewProperties trait methods to a field
annotated with #[properties]. Works alongside the existing
#[derive(ViewChild)] with #[child]:

#[derive(ViewChild, ViewProperties)]
struct MyComponent<V: View> {
    #[child]
    #[properties]
    wrapper: V::Element,
}
// component.set_property("class", "active") now delegates to wrapper.

The #[child] and #[properties] annotations can be on the same field or
separate fields.

ViewProperties::add_class / remove_class

(mogwai::view)

Convenience methods on the ViewProperties trait for adding/removing CSS
classes by string. Idempotent — adding a class that already exists is a no-op,
removing a class that isn't present is a no-op.

mogwai::future::merge_all

(mogwai::future)

Run all futures concurrently and collect their outputs into a Vec<T>.
Companion to the existing race_all (which returns the first to resolve):

let results = merge_all([run(10), run(100), run(200)]).await;
assert_eq!(results.len(), 3);

Bug fixes

  • SSR output no longer contains stray whitespace or println! output.
    Removed debug println!("appending node...") and
    println!("setting proxy") / println!("proxy is unchanged") /
    println!("modifying proxy") from ssr.rs and proxy.rs. Added a test
    (ssr::tests::no_whitespace) verifying SSR output has no extraneous
    whitespace between elements.
  • DOM operations no longer panic on error. web_sys::Node::append_child,
    remove_child, replace_child, and insert_before in web.rs now
    silently discard errors (let _ = ...) instead of unwrap_throw(). This
    prevents panics when, e.g., a node is moved between documents or the DOM is
    in an unexpected state.
  • SSR style merging: the let ... else pattern is now used for the
    style-merge logic in SsrElement::set_style, fixing a clippy lint and making
    the control flow clearer.

Improvements

  • Documentation overhaul for mogwai::web::event: new module-level docs
    with architecture diagram, "when to use which" guidance (EventListener vs
    Listener/Callback), lifecycle warnings for Callback, arity table, and
    usage examples.
  • Doc comment line wrapping across web.rs, view.rs, time.rs,
    ssr.rs, and macro docs for consistent rendering on docs.rs.
  • mogwai-macros Cargo.toml: added license, description,
    documentation, repository, readme, keywords, and categories fields
    for crates.io metadata.

Internal

  • Cookbook build commented out until ported to the new API.
  • Dependency updates.
  • New impl_parameters_tuples! proc macro in mogwai-macros that generates
    Parameters trait impls for tuple arities 2 through 8, used by the new
    Listener/Callback system.

Migration guide

  1. If you were using EventListener directly, no changes needed — it's the
    same API, now built on Listener internally.
  2. If you have custom components that manually implement ViewProperties by
    delegating to an inner V::Element, you can replace the manual impl with
    #[derive(ViewProperties)] and a #[properties] field annotation.
  3. If you pin web-sys features in your downstream crate, add "console" to
    the features list.
  4. If you were working around stray println! output in SSR, those are now
    gone — remove any whitespace-stripping workarounds.