Skip to content

v0.5.0-beta

Pre-release
Pre-release
Compare
Choose a tag to compare
@gbj gbj released this 08 Aug 00:24

This beta release brings us closer to 0.5.0 proper.

The big changes are dropping cx/Scope entirely. I've copied and pasted the 0.5.0-alpha release notes below for reference, along with a few notes about other changes since the alpha release. A few other changes (#1480, #1485) will be incorporated once it's ready for release.

v0.5.0 in General

Reactive System Changes

This long-awaited release significantly changes how the reactive system works. This should solve several correctness issues/rough edges that related to the manual use of cx/Scope and could create memory leaks. (See #918 for details)

It also has the fairly large DX change (improvement?) of removing the need to pass cx or Scope variables around at all.

Migration is fairly easy. 95% of apps will migrate completely by making the following string replacements:

  1. cx: Scope, => (empty string)
  2. cx: Scope => (empty string)
  3. cx, => (empty string)
  4. (cx) => ()
  5. |cx| => ||
  6. Scope, => (empty string)
  7. Scope => (empty string) as needed
  8. You may have some |_, _| that become |_| or |_| that become ||, particularly for the fallback props on <Show/> and <ErrorBoundary/>

Basically, there is no longer a Scope type, and anything that used to take it can simply be deleted.

For the 5%: if you were doing tricky things like storing a Scope somewhere in a struct or variable and then reusing it, you should be able to achieve the same result by storing Owner::current() somewhere and then later using it in with_owner(owner, move || { /* ... */ }).

There are no other big conceptual or API changes in this update: essentially all the same reactive, templating, and component concepts should still apply, just without cx.

Other New Features

Now that we don't need an extra Scope argument to construct them, many of the signal types now implement Serialize/Deserialize directly, as well as From<T>. This should make it significantly easier to do things like "reactively serialize a nested data structure in a create_effect" — this removed literally dozens of lines of serialization/deserialization logic and a custom DTO from the todomvc example. Serializing a signal simply serializes its value, in a reactive way; deserializing into a signal creates a new signal containing that deserialized value.

Other Changes

use_navigate navigate function no longer returns a value

The navigate("path", options) call now uses request_animation_frame internally to delay a tick before navigating, which solves a few odd edge cases having to do with redirecting immediately and the timing of reactive system cleanups. This was a change that arose during 0.3 and 0.4 and is being made now to coincide with other breaking changes and a new version.

If you were relying on the Result<_, _> here and want access to it, let me know and we can bring back a version that has it. Otherwise, this shouldn't really require any changes to your app.

window_event_listener and friends now return a handle for removal

This one was just an API oversight originally, again taking advantage of the semver update. window_event_listener and its untyped version now return a WindowListenerHandle with a .remove() method that can be called explicitly to remove that event, for example in an on_cleanup.

Again, shouldn't require meaningful changes.

#[component]
fn TypingPage() -> impl IntoView {
    let handle = window_event_listener(ev::keypress, |ev| {
        /* do something */
    });
    on_cleanup(move || handle.remove());
}

Expected to Not Work

leptosfmt and cargo leptos --hot-reload, which assume that the view! needs a cx,, will probably not work as intended and will need to be updated.

Any other ecosystem libraries that depend on Leptos 0.4 won't work, of course.