Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains the following updates:
0.7.0-rc2
->0.7.0
Release Notes
leptos-rs/leptos (leptos)
v0.7.0
Compare Source
At long last, as the culmination of more than a year of work, the 0.7 release has arrived!
0.7 is a nearly-complete rewrite of the internals of the framework, with the following goals:
Getting Started
0.7 works with the current
cargo-leptos
version. If you want to start exploring, there are starter templates for Axum and Actix. Each template is only three files. They show some of the boilerplate differences; for more details, see below.Axum:
cargo leptos new --git https://github.com/leptos-rs/start-axum
(repo)Actix:
cargo leptos new --git https://github.com/leptos-rs/start-actix
(repo)New Features
.await
on resources andasync
in<Suspense/>
Currently,
create_resource
allows you to synchronously access the value of some async data as eitherNone
orSome(_)
. However, it requires that you always access it this way. This has some drawbacks:Now, you can
.await
a resource, and you can useasync
blocks within a<Suspense/>
via theSuspend
wrapper, which makes it easier to chain two resources:Reference-counted signal types
One of the awkward edge cases of current Leptos is that our
Copy
arena for signals makes it possible to leak memory if you have a collection of nested signals and do not dispose them. (See 0.6 example.) 0.7 exposesArcRwSignal
,ArcReadSignal
, etc., which areClone
but notCopy
and manage their memory via reference counting, but can easily be converted into the copyableRwSignal
etc. This makes working with nested signal correctly much easier, without sacrificing ergonomics meaningfully. See the 0.7counters
example for more..read()
and.write()
on signalsYou can now use
.read()
and.write()
to get immutable and mutable guards for the value of a signal, which will track/update appropriately: these work like.with()
and.update()
but without the extra closure, or like.get()
but without cloning.Custom HTML shell
The HTML document "shell" for server rendering is currently hardcoded as part of the server integrations, limiting your ability to customize it. Now you simply include it as part of your application, which also means that you can customize things like teh
<title>
without needing to useleptos_meta
.Enhanced attribute spreading
Any valid attribute can now be spread onto any component, allowing you to extend the UI created by a component however you want. This works through multiple components: for example, if you spread attributes onto a
Suspense
they will be passed through to whatever it returns.Improved
<ProtectedRoute/>
The current
ProtectedRoute
component is not great: it checks the condition once, synchronously, on navigation, and so it doesn't respond to changes and can't easily be used with async data. The newProtectedRoute
is reactive and uses Suspense so you can use resources or reactive data. There are examples of this now inrouter
andssr_modes_axum
.Two-way binding with
bind:
syntaxTwo-way binding allows you to pass signals directly to inputs, rather than separately managing
prop:value
andon:input
to sync the signals to the inputs.Reactive Stores
Stores are a new reactive primitive that allow you to reactively access deeply-nested fields in a struct without needing to create signals inside signals; rather, you can use plain data types, annotated with
#[derive(Store)]
, and then access fields with reactive getters/setters.Updating one subfield of a
Store
does not trigger effects only listening to a sibling field; listening to one field of a store does not track the sibling fields.Stores are most useful for nested data structures, so a succinct example is difficult, but the
stores
example shows a complete use case.Support the View Transition API for router animations
The
Routes
/FlatRoutes
component now have atransition
prop. Setting this totrue
will cause the router to use the browser's View Transition API during navigation. You can control animations during navigation using CSS classes. Which animations are used can be controlled using classes that the router will set on the<html>
element:.routing-progress
while navigating,.router-back
during a back navigation, and.router-outlet-{n}
for the depth of the outlet that is being changed (0
for the root page changing,1
for the firstOutlet
, etc.) Therouter
example uses this API.Breaking Changes
Imports
I'm reorganizing the module structure to improve docs and discoverability. We will still have a prelude that can be used for glob imports of almost everything that's currently exported from the root.
Likewise, the router exposes things via
leptos_router::components
andleptos_router::hooks
. rust-analyzer can help fix imports fairly well.I'm hoping for feedback on the new module structure, whether it makes sense, and any improvements. I have not done too much work to sort through the reexports, look at how docs look, etc. yet.
Naming
We're migrating away from
create_
naming toward more idiomatic Rust naming patterns:create_signal
tosignal
(likechannel
)create_rw_signal
toRwSignal::new()
I've left some of the current functions in, marked deprecated; others may have been missed, but should be easy to find via docs.rs.
Type erasure and view types
One of the major changes in this release is replacing the
View
enum with statically-typed views, which is where most of the binary size savings come from. If you need to branch and return one of several types, you can either use one of theEither
enums inleptos::either
, or you can use.into_any()
to erase the type. Generally speaking the compiler can do its job better if you maintain more type information so theEither
types should be preferred, butAnyView
is not bad to use when needed.Boilerplate
There have been changes to the SSR and hydration boilerplate, which include (but aren't limited to)
get_configuration
is sync (remove the.await
).leptos_routes
no longer takesLeptosOptions
as an argumentleptos::mount::hydrate_body
(hydration) instead ofleptos::mount::mount_to_body
(which is now CSR-specific)Check the starter templates for a good setup.
Route definitions
The patterns for route definition have changed in several ways.
fallback
is now a required prop on<Routes/>
, rather than an optional prop on<Router/>
<FlatRoutes/>
component that optimizes for this case<ParentRoute/>
path="foo"
becomespath=StaticSegment("foo")
, and there arepath=":id"
becomespath=ParamSegment("id")
,path="posts/:id"
becomespath=(StaticSegment("posts"), ParamSegment("id"))
, and so on. There is apath!()
macro that will do this for you: i.e., it will expandpath!("/foo/:id")
topath=(StaticSegment("foo"), ParamSegment("id"))
.See the
router
andhackernews
examples.Send
/Sync
signalsBy default, the data held in reactive primitives (signals, memos, effects) must be safe to send across threads. For non-threadsafe types, there is a "storage" generic on signal types. This defaults to
SyncStorage
, but you can optionally specifyLocalStorage
instead. Many APIs have_local()
alternatives to enable this.Custom
IntoView
andIntoAttribute
implementationsIf you currently have implementations of
IntoView
orIntoAttribute
for custom data types, in a way that allows you to use them directly in the view, you should replace those with implementations ofIntoRender
andIntoAttributeValue
, respectively. See this PR for examples.Minor Breaking Changes
Await
component now takes a plainFuture
for itsfuture
prop rather than aFn() -> Future
, because it uses an optimized resource implementationIntoRender
rather thanIntoView
(see discussion in #3062)ParamsMap
supports multiple values per key (which is supported by query strings), so the API now differentiates between inserting a new value for the same key and replacing the value, and between getting one value and getting all values for a keyStylesheet
component no longer automatically works with the file hashing feature ofcargo-leptos
. You can useHashedStylesheet
and pass it the appropriate props instead.<A>
component with aclass
prop that set theclass
on the<a>
element.) These have been replaced by the new attribute-spreading API, to reduce complexity of the components themselves.LeptosOptions
now usesArc<str>
for its fields that were formerlyString
, so that it is less expensive to clone. In practice, this usually only means using&field
orfield.as_ref()
in a few places that require&str
, and so on.experimental-islands
feature renamed toislands
batch
function no longer exists: all updates now exhibit the batching behavior that was previously opt-in viabatch
.into_any()
at the end of the component that you are going to use recursively.Miscellaneous
I'm sure there are a bunch of small and larger changes I have not mentioned above. By the time of final release, help compiling a total list of breaking changes/migration guide would be much appreciated. At present, the starter templates and the
examples
directory in the PR can provide a pretty comprehensive set of changes.On storing views in signals...
There's a pattern I've seen many use that I do not particularly like, but accidentally enabled through the way APIs happened to be (or needed to be) designed in Leptos 0.1-0.6, in which a user stores some view in a signal and then reads it somewhere else. This was possible because
View
needed to beClone
for internal reasons. Some users used this to create custom control flow: for example, you could create a global "header view" signal, and then update it from leaf components by storing a new view in it.I'd consider this a bit of an antipattern, for a couple reasons:
Clone
but in a surprising way: you can clone the reference to a DOM node, but that is a shallow, not a deep clone, and if you use it in multiple places by.get()
ing the signal more than once, it will only appear in the last locationIn the statically-typed view tree, views are not necessarily cloneable (including the
AnyView
type), so they can't easily be stored in a signal.However, it is possible to achieve a similar goal by using a "reactive channel" pattern instead:
Send the views through a channel means they do not need to be cloned, and won't be used in more than once place (avoiding the edge cases of 2 above.) Each time you send a view through the channel, simply trigger the trigger.
v0.7.0-rc3
Compare Source
A very minor release to facilitate leptos-wasi, a new base integration crate used by the Spin and new WasmCloud integrations!
What's Changed
view!
macro by @gbj in https://github.com/leptos-rs/leptos/pull/3293Full Changelog: leptos-rs/leptos@v0.7.0-rc2...v0.7.0-rc3
Configuration
📅 Schedule: Branch creation - "* 0-3 * * 1" (UTC), Automerge - At any time (no schedule defined).
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR was generated by Mend Renovate. View the repository job log.