NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
crates.io
crates.io, #4685 most downloaded on crates.io
view macro for the Leptos web framework.
Latest stable
0.8.20
Last release 22 days ago
31 Oct 2026
Ships fairly regularly
a new release about every 4 weeks
Most releases are documented
notes for 52 of the last 60 stable releases
6 versions withdrawn
withdrawn after publishing
4 years old
136 releases · first in 2022
Drag across the ruler to compare, or tap a release to open it.
A wide variety of semver-breaking changes that probably won't affect user code.
This release candidate for 0.9.0. 0.9 should be mostly compatible with most user application code. i.e., the migration path should be to upgrade from 0.8 to 0.9 and, in most cases, not need to make any changes. However, note the following changes
lazy feature: Lazy-loading/code-splitting is now gated behind a lazy flag on the leptos crate. This saves binary size for anyone who's not using lazy-loading; if you are, just enable the feature.serde_qs 1.0: we've migrated to the 1.0 series of releases for our default server-function input encoding (form URL data). This should reduce the requirement for #[server(default)] and similar workarounds for empty collections.on:toggle is now typed as a ToggleEvent rather than plain Eventlet (foo, set_foo) = signal(42); set_foo(13); foo() should work on both stable and nightly)impl Fn() -> T and you pass it a Signal<T> you may need to dereference it (foo=*signal rather than foo=signal). Let us know if there are any more noticeable breakages here. There are some awkward tradeoffs with inference and #[prop(into)] and in some cases we've had to make the choice we think will be best for the most use cases. Let me know if there are things that seem obviously wrong or unhelpful.v0.9.0-rc0tracing is enabled (see #4949) by @gbj in https://github.com/leptos-rs/leptos/pull/4950hydrate_lazy async under routes so pending Suspends don… by @adrianncovaci in https://github.com/leptos-rs/leptos/pull/4945Owner::new by @kittyandrew in https://github.com/leptos-rs/leptos/pull/4966<Title/> (closes #4968) by @gbj in https://github.com/leptos-rs/leptos/pull/4969requestIdleCallback in island script by @gbj in https://github.com/leptos-rs/leptos/pull/4978<ErrorBoundary/> (closes #4980) by @gbj in https://github.com/leptos-rs/leptos/pull/4982Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.9.0-rc0...v0.9.0-rc1
Your coding agent can read these notes before it upgrades. Set up the MCP server →
A wide variety of semver-breaking changes that probably won't affect user code.
This is the first release candidate for 0.9.0. 0.9 should be mostly compatible with most user application code. i.e., the migration path should be to upgrade from 0.8 to 0.9 and, in most cases, not need to make any changes. However, note the following:
Notable changes:
lazy feature: Lazy-loading/code-splitting is now gated behind a lazy flag on the leptos crate. This saves binary size for anyone who's not using lazy-loading; if you are, just enable the feature.serde_qs 1.0: we've migrated to the 1.0 series of releases for our default server-function input encoding (form URL data). This should reduce the requirement for #[server(default)] and similar workarounds for empty collections.on:toggle is now typed as a ToggleEvent rather than plain Eventlet (foo, set_foo) = signal(42); set_foo(13); foo() should work on both stable and nightly)impl Fn() -> T and you pass it a Signal<T> you may need to dereference it (foo=*signal rather than foo=signal). Let us know if there are any more noticeable breakages here. There are some awkward tradeoffs with inference and #[prop(into)] and in some cases we've had to make the choice we think will be best for the most use cases. Let me know if there are things that seem obviously wrong or unhelpful.0.9.0-beta"" and "/" static segments as pass-through parents by @sabify in https://github.com/leptos-rs/leptos/pull/4839default feature by @sabify in https://github.com/leptos-rs/leptos/pull/4842<Form> submission fidelity, initial route build race by @sabify in https://github.com/leptos-rs/leptos/pull/4861<For> children in the same order we SSR them (closes #4881) by @gbj in https://github.com/leptos-rs/leptos/pull/4882const_str_slice_concat by @sabify in https://github.com/leptos-rs/leptos/pull/4745RustEmbed. by @metatoaster in https://github.com/leptos-rs/leptos/pull/4715defer option to HydrationScripts (closes #4869) by @GauravPawar101 in https://github.com/leptos-rs/leptos/pull/4889erase-components tests, and various flakiness issues by @gbj in https://github.com/leptos-rs/leptos/pull/4924<For/> when using islands router (closes #4937) by @gbj in https://github.com/leptos-rs/leptos/pull/4939Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.9.0-beta...v0.9.0-rc0
Nothing published for this version
A wide variety of semver-breaking changes that probably won't affect user code.
This is a beta release from the leptos_0.9 branch, to give people an opportunity to start playing around.
I have not yet written up a full changelog but you can find the PR at https://github.com/leptos-rs/leptos/pull/4522
Notable changes:
lazy feature: Lazy-loading/code-splitting is now gated behind a lazy flag on the leptos crate. This saves binary size for anyone who's not using lazy-loading; if you are, just enable the feature.serde_qs 1.0: we've migrated to the 1.0 series of releases for our default server-function input encoding (form URL data). This should reduce the requirement for #[server(default)] and similar workarounds for empty collections.on:toggle is now typed as a ToggleEvent rather than plain Eventlet (foo, set_foo) = signal(42); set_foo(13); foo() should work on both stable and nightly)Fn() traits directly on nightly; instead, on both stable and nightly, they deref to a dyn Fn(). This means that you can call signals as functions on either nightly or stable. If you had props that took impl Fn() -> T previously (and could receive a signal or a closure on nightly), you can now take impl SignalOrFn<Output = T>. This is probably the biggest change in 0.9, so let me know if you encounter any issues.Many of the changes in this release are intended to smooth out various APIs and don't seem to cause significant breakage, but please let me know if they do. This is not intended to require meaningful migration; if you find that it's causing you to need to make significant changes to your code, please share some examples and we'll see if we can minimize the breakage.
ToggleEvent for on:toggle. by @azriel91 in https://github.com/leptos-rs/leptos/pull/4362_with_handle suffix from functions by @mondeja in https://github.com/leptos-rs/leptos/pull/4388render_app_async_stream_with_context method by @alexisfontaine in https://github.com/leptos-rs/leptos/pull/4309serde_qs 1.0 (see #4014) by @gbj in https://github.com/leptos-rs/leptos/pull/4237main into leptos_0.9 by @metatoaster in https://github.com/leptos-rs/leptos/pull/4624.into_reactive_value conversion for signal-function types on nightly (closes #4608) by @gbj in https://github.com/leptos-rs/leptos/pull/4617(). by @metatoaster in https://github.com/leptos-rs/leptos/pull/4653server_fn_macro to specify a default client type by @darakreqo in https://github.com/leptos-rs/leptos/pull/4594reactive_graph by @sabify in https://github.com/leptos-rs/leptos/pull/4734router by @sabify in https://github.com/leptos-rs/leptos/pull/4731router_macro by @sabify in https://github.com/leptos-rs/leptos/pull/4732leptos_macro by @sabify in https://github.com/leptos-rs/leptos/pull/4738oco_ref performance bugs by @sabify in https://github.com/leptos-rs/leptos/pull/4744hydration_context by @sabify in https://github.com/leptos-rs/leptos/pull/4747leptos_server correctness bugs by @sabify in https://github.com/leptos-rs/leptos/pull/4753any_error by @sabify in https://github.com/leptos-rs/leptos/pull/4756any_spawner correctness bugs by @sabify in https://github.com/leptos-rs/leptos/pull/4757Url::origin() returns the real request origin by @sabify in https://github.com/leptos-rs/leptos/pull/4760auto live reload protocol option by @veigaribo in https://github.com/leptos-rs/leptos/pull/4265leptos by @sabify in https://github.com/leptos-rs/leptos/pull/4763server_fn by @sabify in https://github.com/leptos-rs/leptos/pull/4770OwnedView (closes #4769) by @gbj in https://github.com/leptos-rs/leptos/pull/4771reactive_stores and reactive_stores_macro by @sabify in https://github.com/leptos-rs/leptos/pull/4735server_fn by @sabify in https://github.com/leptos-rs/leptos/pull/4765MaybeProp fn deref by @gbj in https://github.com/leptos-rs/leptos/pull/4779leptos_dom correctness bugs by @sabify in https://github.com/leptos-rs/leptos/pull/4754tachys by @sabify in https://github.com/leptos-rs/leptos/pull/4764Nonce::from_value for externally-supplied CSP nonces by @anagrius in https://github.com/leptos-rs/leptos/pull/4786#[prop(marker)] option by @Baptistemontan in https://github.com/leptos-rs/leptos/pull/4774lazy_preload macro by @edmondj in https://github.com/leptos-rs/leptos/pull/4729leptos_macro docs by @gbj in https://github.com/leptos-rs/leptos/pull/4811<textarea> children to prevent XSS" by @gbj in https://github.com/leptos-rs/leptos/pull/4819<For/> keys correctly in non-async HTML rendering (see #4780, #4833) by @gbj in https://github.com/leptos-rs/leptos/pull/4834Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.9.0-alpha...v0.9.0-beta
A wide variety of semver-breaking changes that probably won't affect user code.
This is an alpha release from the leptos_0.9 branch, to give people an opportunity to start playing around.
I have not yet written up a full changelog but you can find the PR at https://github.com/leptos-rs/leptos/pull/4522
Notable changes:
lazy feature: Lazy-loading/code-splitting is now gated behind a lazy flag on the leptos crate. This saves binary size for anyone who's not using lazy-loading; if you are, just enable the feature.serde_qs 1.0: we've migrated to the 1.0 series of releases for our default server-function input encoding (form URL data). This should reduce the requirement for #[server(default)] and similar workarounds for empty collections.on:toggle is now typed as a ToggleEvent rather than plain Eventlet (foo, set_foo) = signal(42); set_foo(13); foo() should work on both stable and nightly)impl Fn() -> T and you pass it a Signal<T> you may need to dereference it (foo=*signal rather than foo=signal). Let us know if there are any more noticeable breakages here.Again, this is a bit of a "canary": many of the changes in this release are intended to smooth out various APIs and don't seem to cause significant breakage, but please let me know if they do. This is not intended to require meaningful migration; if you find that it's causing you to need to make significant changes to your code, please share some examples and we'll see if we can minimize the breakage.
Nothing published for this version
A patch release, mostly of bugfixes.
A patch release, mostly of bugfixes.
Note: one of these includes a behavior change, which is that the primary server function encodings now respect the Axum/Actix request body size limits, rather than ignoring them. If you are accustomed to sending very large data (for example, a POST request > 2mb) via server functions, you may need to increase the request body size limit via Actix PayloadConfig or Axum DefaultBodyLimit (see docs for each server framework.)
Multipart data (file uploads) are not affected.
OwnedView (closes #4769) by @gbj in https://github.com/leptos-rs/leptos/pull/4771Nonce::from_value for externally-supplied CSP nonces by @anagrius in https://github.com/leptos-rs/leptos/pull/4786#[prop(marker)] option by @Baptistemontan in https://github.com/leptos-rs/leptos/pull/4774lazy_preload macro by @edmondj in https://github.com/leptos-rs/leptos/pull/4729leptos_macro docs by @gbj in https://github.com/leptos-rs/leptos/pull/4811Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.8.18...v0.8.19
doc(leptos_config): Improve docs readability; Add # Errors sections by @DanikVitek in https://github.com/leptos-rs/leptos/pull/4593
leptos_config): Improve docs readability; Add # Errors sections by @DanikVitek in https://github.com/leptos-rs/leptos/pull/4593leptos_config): Implement LeptosOptions::css_path by @DanikVitek in https://github.com/leptos-rs/leptos/pull/4592Action by using WeakOwner (closes #4602) by @gbj in https://github.com/leptos-rs/leptos/pull/4603css_path with that moved to css_file_path to better reflect/compliment underlying use cases by @metatoaster in https://github.com/leptos-rs/leptos/pull/4615Patch for Store where store attribute is being used. by @mskorkowski in https://github.com/leptos-rs/leptos/pull/4620Store cleanup items by @gbj in https://github.com/leptos-rs/leptos/pull/4645either_of): Add Either! convenience macro by @DanikVitek in https://github.com/leptos-rs/leptos/pull/4627wasm_split_helpers version by @gbj in https://github.com/leptos-rs/leptos/pull/4684Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.8.17...v0.8.18
feat: add bitcode 's serde integration codec by @rpfontana in https://github.com/leptos-rs/leptos/pull/4585
bitcode 's serde integration codec by @rpfontana in https://github.com/leptos-rs/leptos/pull/4585::std in either_of by @DanikVitek in https://github.com/leptos-rs/leptos/pull/4583Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.8.16...v0.8.17
fix: do not show Transition fallback on 2nd change if 1st change resolved synchronously (closes #4492) by @gbj in https://github.com/leptos-rs/leptos/
IntoAnyAttribute in macro expansion from #4481 by @gbj in https://github.com/leptos-rs/leptos/pull/4500AnyViewWithAttrs (closes #4512) by @gbj in https://github.com/leptos-rs/leptos/pull/4513reactive_stores by @gbj in https://github.com/leptos-rs/leptos/pull/4516'static return annotation for <A/> (closes #4525) by @gbj in https://github.com/leptos-rs/leptos/pull/4531docs.rs by @ahlinc in https://github.com/leptos-rs/leptos/pull/4526parking_lot (cf. #4410) by @gbj in https://github.com/leptos-rs/leptos/pull/4520Websocket protocol respect custom server URL by @adoyle0 in https://github.com/leptos-rs/leptos/pull/4538file_and_error_handler_with_context into tower services by @metatoaster in https://github.com/leptos-rs/leptos/pull/4528cargo-nextest with --locked by @gbj in https://github.com/leptos-rs/leptos/pull/4560linear-map dependency by @alexisfontaine in https://github.com/leptos-rs/leptos/pull/4563transparent to Show/ShowLet to work around #4470 by @gbj in https://github.com/leptos-rs/leptos/pull/4519_ to fix inert SVG use_ elements by @pheki in https://github.com/leptos-rs/leptos/pull/4569AttributeValue for MaybeProp by @QaidVoid in https://github.com/leptos-rs/leptos/pull/4575Deserialize for Signal<T> (closes #4533) by @gbj in https://github.com/leptos-rs/leptos/pull/4576Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.8.15...v0.8.16
ShowLet now accepts static Option values. by @maccesch in https://github.com/leptos-rs/leptos/pull/4467
ShowLet now accepts static Option values. by @maccesch in https://github.com/leptos-rs/leptos/pull/4467IntoAnyAttribute when using erase_components by @ToxicMushroom in https://github.com/leptos-rs/leptos/pull/4481Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.8.14...v0.8.15
Resupport From T> for Signal , ArcSignal , Callback and similar by @zakstucke in https://github.com/leptos-rs/leptos/pull/4273
From<Fn() -> T> for Signal<T>, ArcSignal<T>, Callback<T, _> and similar by @zakstucke in https://github.com/leptos-rs/leptos/pull/4273Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.8.13...v0.8.14
add homepage to leptos cargo metadata by @tswast in https://github.com/leptos-rs/leptos/pull/4417
Debug trait bound on tuples PossibleRouteMatch implementation by @alexisfontaine in https://github.com/leptos-rs/leptos/pull/4428SendWrapper errors on server (closes #4432, #4402) by @gbj in https://github.com/leptos-rs/leptos/pull/4433Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.8.12...v0.8.13
Replace vendored wasm-split with out-of-repository version by @WorldSEnder in https://github.com/leptos-rs/leptos/pull/4369
Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.8.11...v0.8.12
Removed excess bound on MaybeProp ReadUntracked implementation. by @Buzzec in https://github.com/leptos-rs/leptos/pull/4360
MaybeProp ReadUntracked implementation. by @Buzzec in https://github.com/leptos-rs/leptos/pull/4360scrollend event to view macro by @adoyle0 in https://github.com/leptos-rs/leptos/pull/4379NodeRef by implementing IsDisposed by @gbj in https://github.com/leptos-rs/leptos/pull/4367debug_log and debug_error in logging module by @mahdi739 in https://github.com/leptos-rs/leptos/pull/4335effect::immediate::batch by @QuartzLibrary in https://github.com/leptos-rs/leptos/pull/4344server_fn feature propagation by @arpadav in https://github.com/leptos-rs/leptos/pull/4375AtIndex (closes #4385) by @gbj in https://github.com/leptos-rs/leptos/pull/4389dry_resolve() call on Suspend (closes #4402) by @gbj in https://github.com/leptos-rs/leptos/pull/4404bitcode encoding/decoding to server fn IO by @arpadav in https://github.com/leptos-rs/leptos/pull/4376Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.8.10...v0.8.11
Locking dependencies in cargo-leptos install example by @agirorn in https://github.com/leptos-rs/leptos/pull/4295
subsecond and an example by @gbj in https://github.com/leptos-rs/leptos/pull/4307__wasm_split.*.js file (closes #4322) by @gbj in https://github.com/leptos-rs/leptos/pull/4327Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.8.9...v0.8.10
This includes patch releases to the reactive_graph, tachys, wasm_split_macros, server_fn, leptos, and router crates.
This includes patch releases to the reactive_graph, tachys, wasm_split_macros, server_fn, leptos, and router crates.
Vec<AnyAttribute> (closes #4268) by @gbj in https://github.com/leptos-rs/leptos/pull/4270referrerpolicy attribute to a element by @adoyle0 in https://github.com/leptos-rs/leptos/pull/4299Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.8.8...v0.8.9
Fixes #4193: Adding command and commandfor attributes for button by @mskorkowski in https://github.com/leptos-rs/leptos/pull/4194
command and commandfor attributes for button by @mskorkowski in https://github.com/leptos-rs/leptos/pull/4194Patch for a struct with generic arguments by @mskorkowski in https://github.com/leptos-rs/leptos/pull/4175task::spawn maintains reactive ownership (closes #4203) by @gbj in https://github.com/leptos-rs/leptos/pull/4206Vec<_> to optimize large subscriber sets (see #4138) by @gbj in https://github.com/leptos-rs/leptos/pull/4201hydrate_async through OwnedView properly (closes #4219) by @gbj in https://github.com/leptos-rs/leptos/pull/4220non_snake_case and dead_code lints to run within component functions by @yescallop in https://github.com/leptos-rs/leptos/pull/3198<ShowLet> component similar to <Show> but for Option by @maccesch in https://github.com/leptos-rs/leptos/pull/4227value property to support quirky <select> behavior by @gbj in https://github.com/leptos-rs/leptos/pull/4235<Show> accept signals in addition to closures by @maccesch in https://github.com/leptos-rs/leptos/pull/4236leptos_server by @gbj in https://github.com/leptos-rs/leptos/pull/4250Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.8.6...v0.8.8
Nothing published for this version
Just a patch release, mostly to support #[server] #[lazy] for lazy server functions.
Just a patch release, mostly to support #[server] #[lazy] for lazy server functions.
Going forward, patch releases for various crates will have version numbers that are not coupled to one another, and will only be bumped when they've actually changed; so this release is 0.8.6 for leptos, leptos_macro, and server_fn_macro, but does not arbitrarily bump other packages that haven't changed.
See 0.8.5 for notes on WASM splitting.
Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.8.5...v0.8.6
This release includes WASM code-splitting/lazy-loading support, in tandem with the latest cargo-leptos release.
This release includes WASM code-splitting/lazy-loading support, in tandem with the latest cargo-leptos release.
You can use the lazy_routes example to understand what this means!
Essentially, though, there are two patterns:
#[lazy] macro to make any given function lazy#[lazy_route] to designate a route with a lazy-loaded view, which is loaded concurrently with the route's data#[lazy] converts a (sync or async) function into a lazy-loaded async function
#[lazy]
fn deserialize_comments(data: &str) -> Vec<Comment> {
serde_json::from_str(data).unwrap()
}
#[lazy_route] lets you split routes into a "data" half and a "view" half, which will be concurrently loaded by the router. This works with nested routing: so if you have ViewD and ViewE, then the router will concurrently load D's data, D's (lazy) view, E's data, and E's (lazy) view, before navigating to the page.
struct ViewD {
data: Resource<Result<Vec<i32>, ServerFnError>>,
}
#[lazy_route]
impl LazyRoute for ViewD {
fn data() -> Self {
Self {
data: Resource::new(|| (), |_| d_data()),
}
}
fn view(this: Self) -> AnyView {
let items = move || {
Suspend::new(async move {
this.data
.await
.unwrap_or_default()
.into_iter()
.map(|item| view! { <li>{item}</li> })
.collect::<Vec<_>>()
})
};
view! {
<p id="page">"View D"</p>
<hr/>
<Suspense fallback=|| view! { <p id="loading">"Loading..."</p> }>
<ul>{items}</ul>
</Suspense>
<Outlet/>
}
.into_any()
}
}
#[server]
async fn d_data() -> Result<Vec<i32>, ServerFnError> {
tokio::time::sleep(std::time::Duration::from_millis(250)).await;
Ok(vec![1, 1, 2, 3, 5, 8, 13])
}
Our whole July stream was dedicated to the topic, if you want more in depth discussion.
Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.8.4...v0.8.5
There are some small bugfixes in here, as well as improvements to the hot-reloading code. This is mostly intended to be a sort of "last patch" before
There are some small bugfixes in here, as well as improvements to the hot-reloading code. This is mostly intended to be a sort of "last patch" before merging the code-splitting changes in #3988, so that there is a patch people can pin to in case those inadvertently introduce any regressions.
debug_log!, debug_error!, console_debug_log and console_debug_error by @mahdi739 in https://github.com/leptos-rs/leptos/pull/4160Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.8.3...v0.8.4
Fix deprecated parameters js warning by @matchish in https://github.com/leptos-rs/leptos/pull/3956
This is a minor patch release. It does include a significant re-write of how ownership/context work with nested routes (#4091). This should close a number of bugs. However, it's always possible that changes like this introduce regressions. Please test to see whether you have any issues with context and nested routing, and let me know. (We have a new regression example set up to add e2e regression tests for issues going forward.)
SsrMode::PartiallyBlocked (closes #3963) by @marcuswhybrow in https://github.com/leptos-rs/leptos/pull/3964Vec<_> before it is mounted (closes #3962) by @gbj in https://github.com/leptos-rs/leptos/pull/3966Resource::write() and similar functions (see #3959) by @gbj in https://github.com/leptos-rs/leptos/pull/3984#[component] macro by @mondeja in https://github.com/leptos-rs/leptos/pull/3989Arc::ptr_eq for string comparison (closes #3983) by @gbj in https://github.com/leptos-rs/leptos/pull/3994#[prop(default = ...)] and #[prop(name = ...)] by @mondeja in https://github.com/leptos-rs/leptos/pull/4003<select> value by ensuring HTML children are mounted before setting attributes (closes #4005) by @gbj in https://github.com/leptos-rs/leptos/pull/4008session_auth_axum example by @gbj in https://github.com/leptos-rs/leptos/pull/4033#[middleware] macros (closes #4029) by @gbj in https://github.com/leptos-rs/leptos/pull/4048<For/> that is not currently mounted (closes #3385) by @gbj in https://github.com/leptos-rs/leptos/pull/4050async block of a Resource (closes #4060) by @gbj in https://github.com/leptos-rs/leptos/pull/4061view macro. by @metatoaster in https://github.com/leptos-rs/leptos/pull/4071reactive_stores by @elias098 in https://github.com/leptos-rs/leptos/pull/4056LocalResource to an AsyncDerived (closes #4063) by @gbj in https://github.com/leptos-rs/leptos/pull/4077() attributes in template (closes #4079) by @gbj in https://github.com/leptos-rs/leptos/pull/4080IntoFragment for AnyView by @gbj in https://github.com/leptos-rs/leptos/pull/4087class and other attributes to <A/> component by @gbj in https://github.com/leptos-rs/leptos/pull/4086svg::InertElement for dom cache. by @bicarlsen in https://github.com/leptos-rs/leptos/pull/4100svg::InertElement templates in SVG namespace. by @bicarlsen in https://github.com/leptos-rs/leptos/pull/4104take for BrowserFormData by @veigaribo in https://github.com/leptos-rs/leptos/pull/4102join_contexts API by @gbj in https://github.com/leptos-rs/leptos/pull/4113Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.8.2...v0.8.3
For 0.8 release notes in general, see `0.8.0`. This patch release mostly addresses a bad issue with hydrating and other meta components. (See #3945 #3
For 0.8 release notes in general, see 0.8.0. This patch release mostly addresses a bad issue with hydrating <Stylesheet/> and other meta components. (See #3945 #3946)
Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.8.1...v0.8.2
For 0.8 release notes in general, see `0.8.0`. This patch release is mostly just a bunch of bugfixes for issues raised or fixed since then.
For 0.8 release notes in general, see 0.8.0. This patch release is mostly just a bunch of bugfixes for issues raised or fixed since then.
StaticVec::rebuild() by aligning implementation with Vec::rebuild() (closes #3906) by @gbj in https://github.com/leptos-rs/leptos/pull/3920counter_isomorphic release build with the leptos_debuginfo by @sabify in https://github.com/leptos-rs/leptos/pull/3918RenderEffect are dropped while dropped a RenderEffect (closes #3922) by @gbj in https://github.com/leptos-rs/leptos/pull/3926Either to determine how to render islands (see #3896; closes #3929) by @gbj in https://github.com/leptos-rs/leptos/pull/3938.map() and .and_then() on LocalResource by @gbj in https://github.com/leptos-rs/leptos/pull/3941islands_router improvements by @gbj in https://github.com/leptos-rs/leptos/pull/3942Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.8.0...v0.8.1
LocalResource no longer exposes a SendWrapper in the API for the types it returns. (Breaking change: this will require removing some .as_deref() and s…
*Changelog relative to 0.7.8. *
0.8 has been planned for a while, primarily to accommodate small changes that arose during the course of testing and adopting 0.7, most of which are technically semver-breaking but should not meaningfully affect user code. I think it's a significant QOL and user DX upgrade and I'm excited to properly release it.
Noteworthy features:
--cfg=erase_components, which is useful as a dev-mode optimization (thanks to @zakstucke) This is the default setting for cargo-leptos with its latest release, and can be set up manually for use with Trunk. (See docs here.)islands-router features that allow a client-side routing experience while using islands (see the islands_router example) (this one was me)FromServerFnError rather than being constrained to use ServerFnError (see #3274). (Note: This will require changes if you're using a custom error type, but should be a better experience.) (thanks to @ryo33)LocalResource no longer exposes a SendWrapper in the API for the types it returns. (Breaking change: this will require removing some .as_deref() and so on when using LocalResource, but ends up with a much better API.)As you can see this was a real team effort and, as always, I'm grateful for the contributions of everyone named above, and all those who made commits below.
The WebSocket support is particularly exciting, as it allows you to call server functions using the default Rust Stream trait from the futures crate, and have those streams send messages over websockets without you needing to know anything about that process. The API landed in a place that feels like a great extension of the "server function" abstraction in which you can make HTTP requests as if they were ordinary async calls. The websocket stuff doesn't integrate directly with Resources/SSR (which make more sense for one-shot things) but is really easy to use:
use server_fn::{codec::JsonEncoding, BoxedStream, ServerFnError, Websocket};
// The websocket protocol can be used on any server function that accepts and returns a [`BoxedStream`]
// with items that can be encoded by the input and output encoding generics.
//
// In this case, the input and output encodings are [`Json`] and [`Json`], respectively which requires
// the items to implement [`Serialize`] and [`Deserialize`].
#[server(protocol = Websocket<JsonEncoding, JsonEncoding>)]
async fn echo_websocket(
input: BoxedStream<String, ServerFnError>,
) -> Result<BoxedStream<String, ServerFnError>, ServerFnError> {
use futures::channel::mpsc;
use futures::{SinkExt, StreamExt};
let mut input = input; // FIXME :-) server fn fields should pass mut through to destructure
// create a channel of outgoing websocket messages
// we'll return rx, so sending a message to tx will send a message to the client via the websocket
let (mut tx, rx) = mpsc::channel(1);
// spawn a task to listen to the input stream of messages coming in over the websocket
tokio::spawn(async move {
while let Some(msg) = input.next().await {
// do some work on each message, and then send our responses
tx.send(msg.map(|msg| msg.to_ascii_uppercase())).await;
}
});
Ok(rx.into())
}
#[component]
pub fn App() -> impl IntoView {
use futures::channel::mpsc;
use futures::StreamExt;
let (mut tx, rx) = mpsc::channel(1);
let latest = RwSignal::new(None);
// we'll only listen for websocket messages on the client
if cfg!(feature = "hydrate") {
spawn_local(async move {
match echo_websocket(rx.into()).await {
Ok(mut messages) => {
while let Some(msg) = messages.next().await {
latest.set(Some(msg));
}
}
Err(e) => leptos::logging::warn!("{e}"),
}
});
}
view! {
<input type="text" on:input:target=move |ev| {
tx.try_send(Ok(ev.target().value()));
}/>
<p>{latest}</p>
}
}
PossibleRouteMatch dyn-safe by @gbj in https://github.com/leptos-rs/leptos/pull/3421axum to v0.8 by @sabify in https://github.com/leptos-rs/leptos/pull/3439IntoFuture for Suspend::new() (closes #3509) by @gbj in https://github.com/leptos-rs/leptos/pull/3532Default impl for LeptosOptions and ConfFile by @chrisp60 in https://github.com/leptos-rs/leptos/pull/3522AddAnyAttr logic contained by @gbj in https://github.com/leptos-rs/leptos/pull/3562Option<_> in style: (closes #3568) by @gbj in https://github.com/leptos-rs/leptos/pull/3618Result alias by @gbj in https://github.com/leptos-rs/leptos/pull/3543IntoSplitSignal for (Signal<T>, SignalSetter<T>) (closes #3634) by @gbj in https://github.com/leptos-rs/leptos/pull/3643HashedStylesheet (closes #3633) by @gbj in https://github.com/leptos-rs/leptos/pull/3654IntoClass for store fields by @mahdi739 in https://github.com/leptos-rs/leptos/pull/3670TextProp are kept reactive (closes: #3689) by @mahdi739 in https://github.com/leptos-rs/leptos/pull/3690Action::new_unsync (closes #3328) by @gbj in https://github.com/leptos-rs/leptos/pull/3705AsRef bound of StoreFieldIterator blanket impl with Len bound by @DanikVitek in https://github.com/leptos-rs/leptos/pull/3701shell parameter in file_and_error_handler* generic by @tversteeg in https://github.com/leptos-rs/leptos/pull/3711Action::new_local() (closes #3746) by @gbj in https://github.com/leptos-rs/leptos/pull/3749extract() helper to use ServerFnErrorErr (closes #3745) by @ilyvion in https://github.com/leptos-rs/leptos/pull/3750Effect::watch): refer to dependency_fn and handler args by @jmevel in https://github.com/leptos-rs/leptos/pull/3731rust-toolchain.toml (closes #3717) by @gbj in https://github.com/leptos-rs/leptos/pull/3752SignalSetter to prelude (closes #3547) by @gbj in https://github.com/leptos-rs/leptos/pull/3753IntoFragment for single element (closes #3757) by @gbj in https://github.com/leptos-rs/leptos/pull/3759Action::new_local and similar primitives by @gbj in https://github.com/leptos-rs/leptos/pull/3762MaybeSendWrapperOption<_> by @gbj in https://github.com/leptos-rs/leptos/pull/3781ParentRoute by @gbj in https://github.com/leptos-rs/leptos/pull/3784class= for all tuples, not only static ones (closes #3794) by @gbj in https://github.com/leptos-rs/leptos/pull/3801<Title/> by @gbj in https://github.com/leptos-rs/leptos/pull/3793SendOption from public API of actions by @gbj in https://github.com/leptos-rs/leptos/pull/3812Result return types for server_fn by @ifiokjr in https://github.com/leptos-rs/leptos/pull/3755Selector::selected by @flisky in https://github.com/leptos-rs/leptos/pull/3694cargo all-features clippy|nextest part of build process by @sabify in https://github.com/leptos-rs/leptos/pull/3767additional_context after providing other server context in all cases by @gbj in https://github.com/leptos-rs/leptos/pull/3841ByteStream error handling by @sabify in https://github.com/leptos-rs/leptos/pull/3869TextProp in the prelude (closes #3877) by @huuff in https://github.com/leptos-rs/leptos/pull/3879Stylesheet docs by @gbj in https://github.com/leptos-rs/leptos/pull/3898children (closes #3904) by @gbj in https://github.com/leptos-rs/leptos/pull/3905impl From<MappedSignal<T>> for Signal<T> (closes #3889) by @gbj in https://github.com/leptos-rs/leptos/pull/3897Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.7.8...v0.8.0
LocalResource no longer exposes a SendWrapper in the API for the types it returns. (Breaking change: this will require removing some .as_deref() and s…
Release notes copied from 0.8.0-alpha/beta/rc1/. Changelog relative to 0.8.0-rc2. This release includes some bugfixes that required one additional release.
0.8 has been planned for a while, primarily to accommodate small changes that arose during the course of testing and adopting 0.7, most of which are technically semver-breaking but should not meaningfully affect user code.
If we don't hear any feedback about issues with this rc2 release, we will plan to release it as 0.8.0 in the next week or so.
Noteworthy features:
--cfg=erase_components, which is useful as a dev-mode optimization (thanks to @zakstucke) This is the default setting for debug mode in future releases of cargo-leptos, and can be set up manually for use with Trunk. (See docs here.)islands-router features that allow a client-side routing experience while using islands (see the islands_router example) (this one was me)FromServerFnError rather than being constrained to use ServerFnError (see #3274). (Note: This will require changes if you're using a custom error type, but should be a better experience.) (thanks to @ryo33)LocalResource no longer exposes a SendWrapper in the API for the types it returns. (Breaking change: this will require removing some .as_deref() and so on when using LocalResource, but ends up with a much better API.)As you can see this was a real team effort and, as always, I'm grateful for the contributions of everyone named above, and all those who made commits below.
The WebSocket support is particularly exciting, as it allows you to call server functions using the default Rust Stream trait from the futures crate, and have those streams send messages over websockets without you needing to know anything about that process. The API landed in a place that feels like a great extension of the "server function" abstraction in which you can make HTTP requests as if they were ordinary async calls. The websocket stuff doesn't integrate directly with Resources/SSR (which make more sense for one-shot things) but is really easy to use:
use server_fn::{codec::JsonEncoding, BoxedStream, ServerFnError, Websocket};
// The websocket protocol can be used on any server function that accepts and returns a [`BoxedStream`]
// with items that can be encoded by the input and output encoding generics.
//
// In this case, the input and output encodings are [`Json`] and [`Json`], respectively which requires
// the items to implement [`Serialize`] and [`Deserialize`].
#[server(protocol = Websocket<JsonEncoding, JsonEncoding>)]
async fn echo_websocket(
input: BoxedStream<String, ServerFnError>,
) -> Result<BoxedStream<String, ServerFnError>, ServerFnError> {
use futures::channel::mpsc;
use futures::{SinkExt, StreamExt};
let mut input = input; // FIXME :-) server fn fields should pass mut through to destructure
// create a channel of outgoing websocket messages
// we'll return rx, so sending a message to tx will send a message to the client via the websocket
let (mut tx, rx) = mpsc::channel(1);
// spawn a task to listen to the input stream of messages coming in over the websocket
tokio::spawn(async move {
while let Some(msg) = input.next().await {
// do some work on each message, and then send our responses
tx.send(msg.map(|msg| msg.to_ascii_uppercase())).await;
}
});
Ok(rx.into())
}
#[component]
pub fn App() -> impl IntoView {
use futures::channel::mpsc;
use futures::StreamExt;
let (mut tx, rx) = mpsc::channel(1);
let latest = RwSignal::new(None);
// we'll only listen for websocket messages on the client
if cfg!(feature = "hydrate") {
spawn_local(async move {
match echo_websocket(rx.into()).await {
Ok(mut messages) => {
while let Some(msg) = messages.next().await {
latest.set(Some(msg));
}
}
Err(e) => leptos::logging::warn!("{e}"),
}
});
}
view! {
<input type="text" on:input:target=move |ev| {
tx.try_send(Ok(ev.target().value()));
}/>
<p>{latest}</p>
}
}
ByteStream error handling by @sabify in https://github.com/leptos-rs/leptos/pull/3869TextProp in the prelude (closes #3877) by @huuff in https://github.com/leptos-rs/leptos/pull/3879Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.8.0-rc2...v0.8.0-rc3
*Release notes copied from 0.8.0-alpha/beta/rc1. Changelog relative to 0.8.0-rc1. This release includes some bugfixes, but is mostly intended to fix c
Release notes copied from 0.8.0-alpha/beta/rc1. Changelog relative to 0.8.0-rc1. This release includes some bugfixes, but is mostly intended to fix compilation on the latest nightly release.
0.8 has been planned for a while, primarily to accommodate small changes that arose during the course of testing and adopting 0.7, most of which are technically semver-breaking but should not meaningfully affect user code.
If we don't hear any feedback about issues with this rc2 release, we will plan to release it as 0.8.0 in the next week or so.
Noteworthy features:
--cfg=erase_components, which is useful as a dev-mode optimization (thanks to @zakstucke) This is the default setting for debug mode in future releases of cargo-leptos, and can be set up manually for use with Trunk. (See docs here.)islands-router features that allow a client-side routing experience while using islands (see the islands_router example) (this one was me)FromServerFnError rather than being constrained to use ServerFnError (see #3274). (Note: This will require changes if you're using a custom error type, but should be a better experience.) (thanks to @ryo33)As you can see this was a real team effort and, as always, I'm grateful for the contributions of everyone named above, and all those who made commits below.
The WebSocket support is particularly exciting, as it allows you to call server functions using the default Rust Stream trait from the futures crate, and have those streams send messages over websockets without you needing to know anything about that process. The API landed in a place that feels like a great extension of the "server function" abstraction in which you can make HTTP requests as if they were ordinary async calls. The websocket stuff doesn't integrate directly with Resources/SSR (which make more sense for one-shot things) but is really easy to use:
use server_fn::{codec::JsonEncoding, BoxedStream, ServerFnError, Websocket};
// The websocket protocol can be used on any server function that accepts and returns a [`BoxedStream`]
// with items that can be encoded by the input and output encoding generics.
//
// In this case, the input and output encodings are [`Json`] and [`Json`], respectively which requires
// the items to implement [`Serialize`] and [`Deserialize`].
#[server(protocol = Websocket<JsonEncoding, JsonEncoding>)]
async fn echo_websocket(
input: BoxedStream<String, ServerFnError>,
) -> Result<BoxedStream<String, ServerFnError>, ServerFnError> {
use futures::channel::mpsc;
use futures::{SinkExt, StreamExt};
let mut input = input; // FIXME :-) server fn fields should pass mut through to destructure
// create a channel of outgoing websocket messages
// we'll return rx, so sending a message to tx will send a message to the client via the websocket
let (mut tx, rx) = mpsc::channel(1);
// spawn a task to listen to the input stream of messages coming in over the websocket
tokio::spawn(async move {
while let Some(msg) = input.next().await {
// do some work on each message, and then send our responses
tx.send(msg.map(|msg| msg.to_ascii_uppercase())).await;
}
});
Ok(rx.into())
}
#[component]
pub fn App() -> impl IntoView {
use futures::channel::mpsc;
use futures::StreamExt;
let (mut tx, rx) = mpsc::channel(1);
let latest = RwSignal::new(None);
// we'll only listen for websocket messages on the client
if cfg!(feature = "hydrate") {
spawn_local(async move {
match echo_websocket(rx.into()).await {
Ok(mut messages) => {
while let Some(msg) = messages.next().await {
latest.set(Some(msg));
}
}
Err(e) => leptos::logging::warn!("{e}"),
}
});
}
view! {
<input type="text" on:input:target=move |ev| {
tx.try_send(Ok(ev.target().value()));
}/>
<p>{latest}</p>
}
}
additional_context after providing other server context in all cases by @gbj in https://github.com/leptos-rs/leptos/pull/3841Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.8.0-rc1...v0.8.0-rc2
*Release notes copied from 0.8.0-alpha/beta. Changelog relative to 0.8.0-beta.*
Release notes copied from 0.8.0-alpha/beta. Changelog relative to 0.8.0-beta.
0.8 has been planned for a while, primarily to accommodate small changes that arose during the course of testing and adopting 0.7, most of which are technically semver-breaking but should not meaningfully affect user code.
If we don't hear any feedback about issues with this rc1 release, we will plan to release it as 0.8.0 in the next week or so.
Noteworthy features:
--cfg=erase_components, which is useful as a dev-mode optimization (thanks to @zakstucke) This is the default setting for debug mode in future releases of cargo-leptos, and can be set up manually for use with Trunk. (See docs here.)islands-router features that allow a client-side routing experience while using islands (see the islands_router example) (this one was me)FromServerFnError rather than being constrained to use ServerFnError (see #3274). (Note: This will require changes if you're using a custom error type, but should be a better experience.) (thanks to @ryo33)As you can see this was a real team effort and, as always, I'm grateful for the contributions of everyone named above, and all those who made commits below.
The WebSocket support is particularly exciting, as it allows you to call server functions using the default Rust Stream trait from the futures crate, and have those streams send messages over websockets without you needing to know anything about that process. The API landed in a place that feels like a great extension of the "server function" abstraction in which you can make HTTP requests as if they were ordinary async calls. The websocket stuff doesn't integrate directly with Resources/SSR (which make more sense for one-shot things) but is really easy to use:
use server_fn::{codec::JsonEncoding, BoxedStream, ServerFnError, Websocket};
// The websocket protocol can be used on any server function that accepts and returns a [`BoxedStream`]
// with items that can be encoded by the input and output encoding generics.
//
// In this case, the input and output encodings are [`Json`] and [`Json`], respectively which requires
// the items to implement [`Serialize`] and [`Deserialize`].
#[server(protocol = Websocket<JsonEncoding, JsonEncoding>)]
async fn echo_websocket(
input: BoxedStream<String, ServerFnError>,
) -> Result<BoxedStream<String, ServerFnError>, ServerFnError> {
use futures::channel::mpsc;
use futures::{SinkExt, StreamExt};
let mut input = input; // FIXME :-) server fn fields should pass mut through to destructure
// create a channel of outgoing websocket messages
// we'll return rx, so sending a message to tx will send a message to the client via the websocket
let (mut tx, rx) = mpsc::channel(1);
// spawn a task to listen to the input stream of messages coming in over the websocket
tokio::spawn(async move {
while let Some(msg) = input.next().await {
// do some work on each message, and then send our responses
tx.send(msg.map(|msg| msg.to_ascii_uppercase())).await;
}
});
Ok(rx.into())
}
#[component]
pub fn App() -> impl IntoView {
use futures::channel::mpsc;
use futures::StreamExt;
let (mut tx, rx) = mpsc::channel(1);
let latest = RwSignal::new(None);
// we'll only listen for websocket messages on the client
if cfg!(feature = "hydrate") {
spawn_local(async move {
match echo_websocket(rx.into()).await {
Ok(mut messages) => {
while let Some(msg) = messages.next().await {
latest.set(Some(msg));
}
}
Err(e) => leptos::logging::warn!("{e}"),
}
});
}
view! {
<input type="text" on:input:target=move |ev| {
tx.try_send(Ok(ev.target().value()));
}/>
<p>{latest}</p>
}
}
Action::new_local() (closes #3746) by @gbj in https://github.com/leptos-rs/leptos/pull/3749extract() helper to use ServerFnErrorErr (closes #3745) by @ilyvion in https://github.com/leptos-rs/leptos/pull/3750Effect::watch): refer to dependency_fn and handler args by @jmevel in https://github.com/leptos-rs/leptos/pull/3731rust-toolchain.toml (closes #3717) by @gbj in https://github.com/leptos-rs/leptos/pull/3752SignalSetter to prelude (closes #3547) by @gbj in https://github.com/leptos-rs/leptos/pull/3753IntoFragment for single element (closes #3757) by @gbj in https://github.com/leptos-rs/leptos/pull/3759Action::new_local and similar primitives by @gbj in https://github.com/leptos-rs/leptos/pull/3762MaybeSendWrapperOption<_> by @gbj in https://github.com/leptos-rs/leptos/pull/3781ParentRoute by @gbj in https://github.com/leptos-rs/leptos/pull/3784class= for all tuples, not only static ones (closes #3794) by @gbj in https://github.com/leptos-rs/leptos/pull/3801<Title/> by @gbj in https://github.com/leptos-rs/leptos/pull/3793SendOption from public API of actions by @gbj in https://github.com/leptos-rs/leptos/pull/3812Result return types for server_fn by @ifiokjr in https://github.com/leptos-rs/leptos/pull/3755Selector::selected by @flisky in https://github.com/leptos-rs/leptos/pull/3694cargo all-features clippy|nextest part of build process by @sabify in https://github.com/leptos-rs/leptos/pull/3767Full Changelog: https://github.com/leptos-rs/leptos/compare/0.8.0-beta...v0.8.0-rc1
*Release notes copied from 0.8.0-alpha. Changelog relative to 0.8.0-alpha.*
Release notes copied from 0.8.0-alpha. Changelog relative to 0.8.0-alpha.
0.8 has been planned for a while, primarily to accommodate small changes that arose during the course of testing and adopting 0.7, most of which are technically semver-breaking but should not meaningfully affect user code.
Noteworthy features:
--cfg=erase_components, which is useful as a dev-mode optimization (thanks to @zakstucke)islands-router features that allow a client-side routing experience while using islands (see the islands_router example) (this one was me)FromServerFnError rather than being constrained to use ServerFnError (see #3274). (Note: This will require changes if you're using a custom error type, but should be a better experience.) (thanks to @ryo33)As you can see this was a real team effort and, as always, I'm grateful for the contributions of everyone named above, and all those who made commits below. (Apologies if I missed any big features! I will add missing things to release notes as release nears.)
The WebSocket support is particularly exciting, as it allows you to call server functions using the default Rust Stream trait from the futures crate, and have those streams send messages over websockets without you needing to know anything about that process. The API landed in a place that feels like a great extension of the "server function" abstraction in which you can make HTTP requests as if they were ordinary async calls. The websocket stuff doesn't integrate directly with Resources/SSR (which make more sense for one-shot things) but is really easy to use:
use server_fn::{codec::JsonEncoding, BoxedStream, ServerFnError, Websocket};
// The websocket protocol can be used on any server function that accepts and returns a [`BoxedStream`]
// with items that can be encoded by the input and output encoding generics.
//
// In this case, the input and output encodings are [`Json`] and [`Json`], respectively which requires
// the items to implement [`Serialize`] and [`Deserialize`].
#[server(protocol = Websocket<JsonEncoding, JsonEncoding>)]
async fn echo_websocket(
input: BoxedStream<String, ServerFnError>,
) -> Result<BoxedStream<String, ServerFnError>, ServerFnError> {
use futures::channel::mpsc;
use futures::{SinkExt, StreamExt};
let mut input = input; // FIXME :-) server fn fields should pass mut through to destructure
// create a channel of outgoing websocket messages
// we'll return rx, so sending a message to tx will send a message to the client via the websocket
let (mut tx, rx) = mpsc::channel(1);
// spawn a task to listen to the input stream of messages coming in over the websocket
tokio::spawn(async move {
while let Some(msg) = input.next().await {
// do some work on each message, and then send our responses
tx.send(msg.map(|msg| msg.to_ascii_uppercase())).await;
}
});
Ok(rx.into())
}
#[component]
pub fn App() -> impl IntoView {
use futures::channel::mpsc;
use futures::StreamExt;
let (mut tx, rx) = mpsc::channel(1);
let latest = RwSignal::new(None);
// we'll only listen for websocket messages on the client
if cfg!(feature = "hydrate") {
spawn_local(async move {
match echo_websocket(rx.into()).await {
Ok(mut messages) => {
while let Some(msg) = messages.next().await {
latest.set(Some(msg));
}
}
Err(e) => leptos::logging::warn!("{e}"),
}
});
}
view! {
<input type="text" on:input:target=move |ev| {
tx.try_send(Ok(ev.target().value()));
}/>
<p>{latest}</p>
}
}
impl Patch be syn::Index instead of usize by @DanikVitek in https://github.com/leptos-rs/leptos/pull/3700AsRef bound of StoreFieldIterator blanket impl with Len bound by @DanikVitek in https://github.com/leptos-rs/leptos/pull/3701shell parameter in file_and_error_handler* generic by @tversteeg in https://github.com/leptos-rs/leptos/pull/3711Full Changelog: https://github.com/leptos-rs/leptos/compare/0.8.0-alpha...0.8.0-beta
0.8 has been planned for a while, primarily to accommodate small changes that arose during the course of testing and adopting 0.7, most of which are t
0.8 has been planned for a while, primarily to accommodate small changes that arose during the course of testing and adopting 0.7, most of which are technically semver-breaking but should not meaningfully affect user code.
Noteworthy features:
--cfg=erase_components, which is useful as a dev-mode optimization (thanks to @zakstucke)islands-router features that allow a client-side routing experience while using islands (see the islands_router example) (this one was me)FromServerFnError rather than being constrained to use ServerFnError (see #3274). (Note: This will require changes if you're using a custom error type, but should be a better experience.) (thanks to @ryo33)As you can see this was a real team effort and, as always, I'm grateful for the contributions of everyone named above, and all those who made commits below. (Apologies if I missed any big features! I will add missing things to release notes as release nears.)
The WebSocket support is particularly exciting, as it allows you to call server functions using the default Rust Stream trait from the futures crate, and have those streams send messages over websockets without you needing to know anything about that process. The API landed in a place that feels like a great extension of the "server function" abstraction in which you can make HTTP requests as if they were ordinary async calls. The websocket stuff doesn't integrate directly with Resources/SSR (which make more sense for one-shot things) but is really easy to use:
use server_fn::{codec::JsonEncoding, BoxedStream, ServerFnError, Websocket};
// The websocket protocol can be used on any server function that accepts and returns a [`BoxedStream`]
// with items that can be encoded by the input and output encoding generics.
//
// In this case, the input and output encodings are [`Json`] and [`Json`], respectively which requires
// the items to implement [`Serialize`] and [`Deserialize`].
#[server(protocol = Websocket<JsonEncoding, JsonEncoding>)]
async fn echo_websocket(
input: BoxedStream<String, ServerFnError>,
) -> Result<BoxedStream<String, ServerFnError>, ServerFnError> {
use futures::channel::mpsc;
use futures::{SinkExt, StreamExt};
let mut input = input; // FIXME :-) server fn fields should pass mut through to destructure
// create a channel of outgoing websocket messages
// we'll return rx, so sending a message to tx will send a message to the client via the websocket
let (mut tx, rx) = mpsc::channel(1);
// spawn a task to listen to the input stream of messages coming in over the websocket
tokio::spawn(async move {
while let Some(msg) = input.next().await {
// do some work on each message, and then send our responses
tx.send(msg.map(|msg| msg.to_ascii_uppercase())).await;
}
});
Ok(rx.into())
}
#[component]
pub fn App() -> impl IntoView {
use futures::channel::mpsc;
use futures::StreamExt;
let (mut tx, rx) = mpsc::channel(1);
let latest = RwSignal::new(None);
// we'll only listen for websocket messages on the client
if cfg!(feature = "hydrate") {
spawn_local(async move {
match echo_websocket(rx.into()).await {
Ok(mut messages) => {
while let Some(msg) = messages.next().await {
latest.set(Some(msg));
}
}
Err(e) => leptos::logging::warn!("{e}"),
}
});
}
view! {
<input type="text" on:input:target=move |ev| {
tx.try_send(Ok(ev.target().value()));
}/>
<p>{latest}</p>
}
}
PossibleRouteMatch dyn-safe by @gbj in https://github.com/leptos-rs/leptos/pull/3421axum to v0.8 by @sabify in https://github.com/leptos-rs/leptos/pull/3439IntoFuture for Suspend::new() (closes #3509) by @gbj in https://github.com/leptos-rs/leptos/pull/3532Default impl for LeptosOptions and ConfFile by @chrisp60 in https://github.com/leptos-rs/leptos/pull/3522AddAnyAttr logic contained by @gbj in https://github.com/leptos-rs/leptos/pull/3562invert to OptionStoreExt by @mahdi739 in https://github.com/leptos-rs/leptos/pull/3534either_of minimum version in workspace by @gbj in https://github.com/leptos-rs/leptos/pull/3612() by @gbj in https://github.com/leptos-rs/leptos/pull/3615Option<_> in style: (closes #3568) by @gbj in https://github.com/leptos-rs/leptos/pull/3618Result alias by @gbj in https://github.com/leptos-rs/leptos/pull/3543IntoSplitSignal for (Signal<T>, SignalSetter<T>) (closes #3634) by @gbj in https://github.com/leptos-rs/leptos/pull/3643HashedStylesheet (closes #3633) by @gbj in https://github.com/leptos-rs/leptos/pull/3654Debug for ArcField and Field by @mahdi739 in https://github.com/leptos-rs/leptos/pull/3660/ separator (closes #3527) by @gbj in https://github.com/leptos-rs/leptos/pull/3662bind:group to correct location (closes #3678) by @gbj in https://github.com/leptos-rs/leptos/pull/3680IntoClass for store fields by @mahdi739 in https://github.com/leptos-rs/leptos/pull/3670NodeRef::on_load() to avoid re-triggering it if you read something reactively (closes #3684) by @gbj in https://github.com/leptos-rs/leptos/pull/3686ImmediateEffect by @QuartzLibrary in https://github.com/leptos-rs/leptos/pull/3650ImmediateEffect follow up by @QuartzLibrary in https://github.com/leptos-rs/leptos/pull/3692TextProp are kept reactive (closes: #3689) by @mahdi739 in https://github.com/leptos-rs/leptos/pull/3690Action::new_unsync (closes #3328) by @gbj in https://github.com/leptos-rs/leptos/pull/3705Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.7.7...0.8.0-alpha
Nothing published for this version
A minor release with some quality of life improvements and bugfixes
A minor release with some quality of life improvements and bugfixes
either_of minimum version in workspace by @gbj in https://github.com/leptos-rs/leptos/pull/3612() by @gbj in https://github.com/leptos-rs/leptos/pull/3615Debug for ArcField and Field by @mahdi739 in https://github.com/leptos-rs/leptos/pull/3660/ separator (closes #3527) by @gbj in https://github.com/leptos-rs/leptos/pull/3662bind:group to correct location (closes #3678) by @gbj in https://github.com/leptos-rs/leptos/pull/3680NodeRef::on_load() to avoid re-triggering it if you read something reactively (closes #3684) by @gbj in https://github.com/leptos-rs/leptos/pull/3686ImmediateEffect by @QuartzLibrary in https://github.com/leptos-rs/leptos/pull/3650ImmediateEffect follow up by @QuartzLibrary in https://github.com/leptos-rs/leptos/pull/3692impl Patch be syn::Index instead of usize by @DanikVitek in https://github.com/leptos-rs/leptos/pull/3700Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.7.7...v0.7.8
If you're migrating from 0.6 to 0.7, please see the 0.7.0 release notes [here](https://github.com/leptos-rs/leptos/releases/tag/v0.7.0).
If you're migrating from 0.6 to 0.7, please see the 0.7.0 release notes here.
This is a small patch release including primarily bugfixes, and some small ergonomic improvements.
From<ArcField<T>> for Field<T> by @gbj in https://github.com/leptos-rs/leptos/pull/3533Attribute for Either<A, B> by @alexisfontaine in https://github.com/leptos-rs/leptos/pull/3556cargo install --locked for cargo-leptos installation by @gbj in https://github.com/leptos-rs/leptos/pull/3559style: etc. (closes #3554) by @gbj in https://github.com/leptos-rs/leptos/pull/3558erase_components on Either<A, B> by @alexisfontaine in https://github.com/leptos-rs/leptos/pull/3572store attribute signature error message by @DanikVitek in https://github.com/leptos-rs/leptos/pull/3567:capture flag for events to handle them during capture phase (closes #3457) by @gbj in https://github.com/leptos-rs/leptos/pull/3575<fieldset> attributes by @alexisfontaine in https://github.com/leptos-rs/leptos/pull/3581Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.7.5...v0.7.7
Nothing published for this version
If you're migrating from 0.6 to 0.7, please see the 0.7.0 release notes [here](https://github.com/leptos-rs/leptos/releases/tag/v0.7.0).
If you're migrating from 0.6 to 0.7, please see the 0.7.0 release notes here.
This is a small patch release including primarily bugfixes.
ErrorBoundary through reactive views (closes #3487) by @gbj in https://github.com/leptos-rs/leptos/pull/3492#[lazy] macros to support lazy loading and code splitting by @gbj in https://github.com/leptos-rs/leptos/pull/3477leptos_0.8 branch by @gbj in https://github.com/leptos-rs/leptos/pull/3500node_ref after {..} on arbitrary components by @gbj in https://github.com/leptos-rs/leptos/pull/3503either_of): Extent API; Implement other iterator methods; Update deps by @DanikVitek in https://github.com/leptos-rs/leptos/pull/3478matches method for Callback and UnsyncCallback by @geoffreygarrett in https://github.com/leptos-rs/leptos/pull/3520Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.7.4...v0.7.5
If you're migrating from 0.6 to 0.7, please see the 0.7.0 release notes [here](https://github.com/leptos-rs/leptos/releases/tag/v0.7.0).
If you're migrating from 0.6 to 0.7, please see the 0.7.0 release notes here.
This is a small patch release including a couple of bugfixes,
leptos_meta components (closes #3482) by @gbj in https://github.com/leptos-rs/leptos/pull/3485Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.7.3...v0.7.4
If you're migrating from 0.6 to 0.7, please see the 0.7.0 release notes [here](https://github.com/leptos-rs/leptos/releases/tag/v0.7.0).
If you're migrating from 0.6 to 0.7, please see the 0.7.0 release notes here.
This is a small patch release including a couple of bugfixes, as well as the ability to destructure prop value in components with a new #[prop(name = ...)] syntax (see #3382)
#[prop(name = "data")] UserInfo { email, user_id }: UserInfo,
console feature of web-sys for reactive_graph by @alexisfontaine in https://github.com/leptos-rs/leptos/pull/3406getrandom needs js feature (used when nonce feature is active) (closes #3409) by @gbj in https://github.com/leptos-rs/leptos/pull/3410file_and_error_handler by @spencewenski in https://github.com/leptos-rs/leptos/pull/3408#[track_caller]s by @mscofield0 in https://github.com/leptos-rs/leptos/pull/3422islands mention from leptos_axum by @chrisp60 in https://github.com/leptos-rs/leptos/pull/3423Default to stores by @mscofield0 in https://github.com/leptos-rs/leptos/pull/3432Dispose for Store by @mscofield0 in https://github.com/leptos-rs/leptos/pull/3429erase_components with AttributeInterceptor by @gbj in https://github.com/leptos-rs/leptos/pull/3435Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.7.2...v0.7.3
If you're migrating from 0.6 to 0.7, please see the 0.7.0 release notes [here](https://github.com/leptos-rs/leptos/releases/tag/v0.7.0).
If you're migrating from 0.6 to 0.7, please see the 0.7.0 release notes here.
This is a small patch release including a couple of bugfixes, importantly to the hydration of static text nodes on nightly.
popovertarget and popovertargetaction for the <button> element by @Figments in https://github.com/leptos-rs/leptos/pull/3379From<ArcStore<T>> for Store<T, S> by @mscofield0 in https://github.com/leptos-rs/leptos/pull/3389let: syntax (closes #3387) by @gbj in https://github.com/leptos-rs/leptos/pull/3391nightly (closes #3395) by @gbj in https://github.com/leptos-rs/leptos/pull/3396Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.7.1...v0.7.2
If you're migrating from 0.6 to 0.7, please see the 0.7.0 release notes [here](https://github.com/leptos-rs/leptos/releases/tag/v0.7.0).
If you're migrating from 0.6 to 0.7, please see the 0.7.0 release notes here.
This is just a small patch release, two weeks after the 0.7.0 release, geared toward fixing in bugs and filling in API holes since then.
Vec<_> in the DOM (closes #3321) by @gbj in https://github.com/leptos-rs/leptos/pull/3324!Send Actix APIs in server functions by @gbj in https://github.com/leptos-rs/leptos/pull/3326scroll prop to <A/> component to control scrolling behavior (closes #2666) by @gbj in https://github.com/leptos-rs/leptos/pull/3333either! macro by @bicarlsen in https://github.com/leptos-rs/leptos/pull/3337<noscript> (closes #3360) by @gbj in https://github.com/leptos-rs/leptos/pull/3363ToChildren::to_children docs. by @bicarlsen in https://github.com/leptos-rs/leptos/pull/3352usize by @marcuswhybrow in https://github.com/leptos-rs/leptos/pull/3346Signal::derive() behavior by @gbj in https://github.com/leptos-rs/leptos/pull/3351InertElement (closes #3368) by @gbj in https://github.com/leptos-rs/leptos/pull/3370cargo-semver-checks on PRs by @gbj in https://github.com/leptos-rs/leptos/pull/3375Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.7.0...v0.7.1
By the time of final release, help compiling a total list of breaking changes/migration guide would be much appreciated. At present, the starter templ…
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:
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)
.await on resources and async in <Suspense/>Currently, create_resource allows you to synchronously access the value of some async data as either None or Some(_). However, it requires that you always access it this way. This has some drawbacks:
Now, you can .await a resource, and you can use async blocks within a <Suspense/> via the Suspend wrapper, which makes it easier to chain two resources:
let user = Resource::new(|| (), |_| user_id());
let posts = Resource::new(
// resources still manually track dependencies (necessary for hydration)
move || user.get(),
move |_| async move {
// but you can .await a resource inside another
let user = user.await?;
get_posts(user).await
},
);
view! {
<Suspense>
// you can `.await` resources to avoid dealing with the `None` state
<p>"User ID: " {move || Suspend::new(async move {
match user.await {
// ...
}
})}</p>
// or you can still use .get() to access resources in things like component props
<For
each=move || posts.get().and_then(Result::ok).unwrap_or_default()
key=|post| post.id
let:post
>
// ...
</For>
</Suspense>
}
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 exposes ArcRwSignal, ArcReadSignal, etc., which are Clone but not Copy and manage their memory via reference counting, but can easily be converted into the copyable RwSignal etc. This makes working with nested signal correctly much easier, without sacrificing ergonomics meaningfully. See the 0.7 counters 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.
let long_vec = RwSignal::new(vec![42; 1000]);
let short_vec = RwSignal::new(vec![13; 2]);
// bad: clones both Vecs
let bad_len = move || long_vec.get().len() + short_vec.get().len();
// ugly: awkward nested syntax (or a macro)
let ugly_len = move || long_vec.with(|long| short_vec.with(|short| long.len() + short.len()));
// readable but doesn't clone
let good_len = move || long_vec.read().len() + short_vec.read().len();
These should always be used for short periods of time, not stored somewhere for longer-term use, just like any guard or lock, or you can cause deadlocks or panics.
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 use leptos_meta.
pub fn shell(options: LeptosOptions) -> impl IntoView {
view! {
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<AutoReload options=options.clone() />
<HydrationScripts options/>
<MetaTags/>
</head>
<body>
<App/>
</body>
</html>
}
}
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.
// attributes that are spread onto a component will be applied to *all* elements returned as part of
// the component's view. to apply attributes to a subset of the component, pass them via a component prop
<ComponentThatTakesSpread
// the class:, style:, prop:, on: syntaxes work just as they do on elements
class:foo=true
style:font-weight="bold"
prop:cool=42
on:click=move |_| alert("clicked ComponentThatTakesSpread")
// props are passed as they usually are on components
some_prop=13
// to pass a plain HTML attribute, prefix it with attr:
attr:id="foo"
// or, if you want to include multiple attributes, rather than prefixing each with
// attr:, you can separate them from component props with the spread {..}
{..} // everything after this is treated as an HTML attribute
title="ooh, a title!"
{..spread_onto_component}
/>
<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 new ProtectedRoute is reactive and uses Suspense so you can use resources or reactive data. There are examples of this now in router and ssr_modes_axum.
bind: syntaxTwo-way binding allows you to pass signals directly to inputs, rather than separately managing prop:value and on:input to sync the signals to the inputs.
// You can use `RwSignal`s
let is_awesome = RwSignal::new(true);
let sth = RwSignal::new("one".to_string());
// And you can use split signals
let (text, set_text) = signal("Hello world".to_string());
view! {
// Use `bind:checked` and a `bool` signal for a checkbox
<input type="checkbox" bind:checked=is_awesome />
// Use `bind:group` and `String` for radio inputs
<input type="radio" value="one" bind:group=sth />
<input type="radio" value="two" bind:group=sth />
<input type="radio" value="trhee" bind:group=sth />
// Use `bind:value` and `String` for everything else
<input type="text" bind:value=(text, set_text) />
<textarea bind:value=(text, set_text) />
}
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.
The Routes/FlatRoutes component now have a transition prop. Setting this to true 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 first Outlet, etc.) The router example uses this API.
Note: View Transitions are not supported on all browsers, but have been accepted as a standard and can be polyfilled. Using a built-in browser API is much better in the long term than our bug-prone and difficult-to-maintain custom implementation.
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.
- use leptos::*;
+ use leptos::prelude::*;
Likewise, the router exposes things via leptos_router::components and leptos_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.
We're migrating away from create_ naming toward more idiomatic Rust naming patterns:
create_signal to signal (like channel)create_rw_signal to RwSignal::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.
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 the Either enums in leptos::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 the Either types should be preferred, but AnyView is not bad to use when needed.
// Either
if some_condition {
Either::Left(view! { <p>"Foo"</p> })
} else {
Either::Right("Bar")
}
// .into_any()
if some_condition {
view! { <p>"Foo"</p> }.into_any()
} else {
"Bar".into_any()
}
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 takes LeptosOptions as an argumentleptos::mount::hydrate_body (hydration) instead of leptos::mount::mount_to_body (which is now CSR-specific)Check the starter templates for a good setup.
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" becomes path=StaticSegment("foo"), and there are path=":id" becomes path=ParamSegment("id"), path="posts/:id" becomes path=(StaticSegment("posts"), ParamSegment("id")), and so on. There is a path!() macro that will do this for you: i.e., it will expand path!("/foo/:id") to path=(StaticSegment("foo"), ParamSegment("id")).See the router and hackernews 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 specify LocalStorage instead. Many APIs have _local() alternatives to enable this.
let (foo, bar) = signal("baz");
// error: `std::rc::Rc<&str>` cannot be shared between threads safely
// let (foo, bar) = signal(Rc::new("baz"));
let (foo, bar) = signal_local(Rc::new("baz"));
let qux = RwSignal::new("baz");
// error: `std::rc::Rc<&str>` cannot be shared between threads safely
// let qux = RwSignal::new(Rc::new("baz"));
let qux = RwSignal::new_local(Rc::new("baz"));
IntoView and IntoAttribute implementationsIf you currently have implementations of IntoView or IntoAttribute for custom data types, in a way that allows you to use them directly in the view, you should replace those with implementations of IntoRender and IntoAttributeValue, respectively. See this PR for examples.
Await component now takes a plain Future for its future prop rather than a Fn() -> Future, because it uses an optimized resource implementationIntoRender rather than IntoView (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 of cargo-leptos. You can use HashedStylesheet and pass it the appropriate props instead.<A> component with a class prop that set the class on the <a> element.) These have been replaced by the new attribute-spreading API, to reduce complexity of the components themselves.LeptosOptions now uses Arc<str> for its fields that were formerly String, so that it is less expensive to clone. In practice, this usually only means using &field or field.as_ref() in a few places that require &str, and so on.experimental-islands feature renamed to islandsbatch function no longer exists: all updates now exhibit the batching behavior that was previously opt-in via batch.into_any() at the end of the component that you are going to use recursively.Signal<T> no longer directly implements From<Fn() -> T>, which allows it to implement From<T> and therefore to be a more useful replacement for MaybeSignal<T>, for a prop that is "some T or any signal that returns T." To convert a closure into a Signal<_> you can call Signal::derive() explicitly. I know this makes the ergonomics of using the Signal<_> wrapper slightly worse, but it adds additional expressiveness by supporting plain T. (If you want to keep the old behavior, consider taking impl Fn() -> T as a prop if you are using nightly, where all the signals as well as closures implement this trait.)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.
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 be Clone 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:
let count = RwSignal::new(0);
let trigger = ArcTrigger::new();
let (tx, rx) = std::sync::mpsc::channel();
let on_click = {
let trigger = trigger.clone();
move |_| {
leptos::logging::log!("clicked");
*count.write() += 1;
tx.send(if *count.read() % 2 == 0 {
view! { <p>"An even paragraph"</p> }.into_any()
} else {
view! { <span>"An odd span"</span> }.into_any()
})
.unwrap();
trigger.trigger();
}
};
view! {
<div>
<button on:click=on_click>"Update view"</button>
{move || {
trigger.track();
rx.try_recv().unwrap_or_else(|_| view! {
<p>"Click the button once to begin."</p>
}.into_any())
}}
</div>
}
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.
A very minor release to facilitate leptos-wasi, a new base integration crate used by the Spin and new WasmCloud integrations!
A very minor release to facilitate leptos-wasi, a new base integration crate used by the Spin and new WasmCloud integrations!
view! macro by @gbj in https://github.com/leptos-rs/leptos/pull/3293Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.7.0-rc2...v0.7.0-rc3
…during the series of release candidates require breaking changes to fix.
This is a release candidate for 0.7.0.
This means that APIs are understood to be set for 0.7.0, except to the extent that bugs found during the series of release candidates require breaking changes to fix.
Most of the release notes for this
rcare copied over from the alpha/beta/rc1, but the hope is for this to be a complete picture of changes. Please let me know with any missing breaking changes or features so that can be added.
0.7 is a nearly-complete rewrite of the internals of the framework, with the following goals:
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-0.7 (repo)
Actix: cargo leptos new --git https://github.com/leptos-rs/start-actix-0.7 (repo)
.await on resources and async in <Suspense/>Currently, create_resource allows you to synchronously access the value of some async data as either None or Some(_). However, it requires that you always access it this way. This has some drawbacks:
Now, you can .await a resource, and you can use async blocks within a <Suspense/> via the Suspend wrapper, which makes it easier to chain two resources:
let user = Resource::new(|| (), |_| user_id());
let posts = Resource::new(
// resources still manually track dependencies (necessary for hydration)
move || user.get(),
move |_| async move {
// but you can .await a resource inside another
let user = user.await?;
get_posts(user).await
},
);
view! {
<Suspense>
// you can `.await` resources to avoid dealing with the `None` state
<p>"User ID: " {move || Suspend::new(async move {
match user.await {
// ...
}
})}</p>
// or you can still use .get() to access resources in things like component props
<For
each=move || posts.get().and_then(Result::ok).unwrap_or_default()
key=|post| post.id
let:post
>
// ...
</For>
</Suspense>
}
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 exposes ArcRwSignal, ArcReadSignal, etc., which are Clone but not Copy and manage their memory via reference counting, but can easily be converted into the copyable RwSignal etc. This makes working with nested signal correctly much easier, without sacrificing ergonomics meaningfully. See the 0.7 counters 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.
let long_vec = RwSignal::new(vec![42; 1000]);
let short_vec = RwSignal::new(vec![13; 2]);
// bad: clones both Vecs
let bad_len = move || long_vec.get().len() + short_vec.get().len();
// ugly: awkward nested syntax (or a macro)
let ugly_len = move || long_vec.with(|long| short_vec.with(|short| long.len() + short.len()));
// readable but doesn't clone
let good_len = move || long_vec.read().len() + short_vec.read().len();
These should always be used for short periods of time, not stored somewhere for longer-term use, just like any guard or lock, or you can cause deadlocks or panics.
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 use leptos_meta.
pub fn shell(options: LeptosOptions) -> impl IntoView {
view! {
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<AutoReload options=options.clone() />
<HydrationScripts options/>
<MetaTags/>
</head>
<body>
<App/>
</body>
</html>
}
}
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.
// attributes that are spread onto a component will be applied to *all* elements returned as part of
// the component's view. to apply attributes to a subset of the component, pass them via a component prop
<ComponentThatTakesSpread
// the class:, style:, prop:, on: syntaxes work just as they do on elements
class:foo=true
style:font-weight="bold"
prop:cool=42
on:click=move |_| alert("clicked ComponentThatTakesSpread")
// props are passed as they usually are on components
some_prop=13
// to pass a plain HTML attribute, prefix it with attr:
attr:id="foo"
// or, if you want to include multiple attributes, rather than prefixing each with
// attr:, you can separate them from component props with the spread {..}
{..} // everything after this is treated as an HTML attribute
title="ooh, a title!"
{..spread_onto_component}
/>
<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 new ProtectedRoute is reactive and uses Suspense so you can use resources or reactive data. There are examples of this now in router and ssr_modes_axum.
bind: syntaxTwo-way binding allows you to pass signals directly to inputs, rather than separately managing prop:value and on:input to sync the signals to the inputs.
// You can use `RwSignal`s
let is_awesome = RwSignal::new(true);
let sth = RwSignal::new("one".to_string());
// And you can use split signals
let (text, set_text) = signal("Hello world".to_string());
view! {
// Use `bind:checked` and a `bool` signal for a checkbox
<input type="checkbox" bind:checked=is_awesome />
// Use `bind:group` and `String` for radio inputs
<input type="radio" value="one" bind:group=sth />
<input type="radio" value="two" bind:group=sth />
<input type="radio" value="trhee" bind:group=sth />
// Use `bind:value` and `String` for everything else
<input type="text" bind:value=(text, set_text) />
<textarea bind:value=(text, set_text) />
}
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.
The Routes/FlatRoutes component now have a transition prop. Setting this to true 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 first Outlet, etc.) The router example uses this API.
Note: View Transitions are not supported on all browsers, but have been accepted as a standard and can be polyfilled. Using a built-in browser API is much better in the long term than our bug-prone and difficult-to-maintain custom implementation.
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.
- use leptos::*;
+ use leptos::prelude::*;
Likewise, the router exposes things via leptos_router::components and leptos_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.
We're migrating away from create_ naming toward more idiomatic Rust naming patterns:
create_signal to signal (like channel)create_rw_signal to RwSignal::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.
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 the Either enums in leptos::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 the Either types should be preferred, but AnyView is not bad to use when needed.
// Either
if some_condition {
Either::Left(view! { <p>"Foo"</p> })
} else {
Either::Right("Bar")
}
// .into_any()
if some_condition {
view! { <p>"Foo"</p> }.into_any()
} else {
"Bar".into_any()
}
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 takes LeptosOptions as an argumentleptos::mount::hydrate_body (hydration) instead of leptos::mount::mount_to_body (which is now CSR-specific)Check the starter templates for a good setup.
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" becomes path=StaticSegment("foo"), and there are path=":id" becomes path=ParamSegment("id"), path="posts/:id" becomes path=(StaticSegment("posts"), ParamSegment("id")), and so on. There is a path!() macro that will do this for you: i.e., it will expand path!("/foo/:id") to path=(StaticSegment("foo"), ParamSegment("id")).See the router and hackernews 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 specify LocalStorage instead. Many APIs have _local() alternatives to enable this.
let (foo, bar) = signal("baz");
// error: `std::rc::Rc<&str>` cannot be shared between threads safely
// let (foo, bar) = signal(Rc::new("baz"));
let (foo, bar) = signal_local(Rc::new("baz"));
let qux = RwSignal::new("baz");
// error: `std::rc::Rc<&str>` cannot be shared between threads safely
// let qux = RwSignal::new(Rc::new("baz"));
let qux = RwSignal::new_local(Rc::new("baz"));
Await component now takes a plain Future for its future prop rather than a Fn() -> Future, because it uses an optimized resource implementationIntoRender rather than IntoView (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 of cargo-leptos. You can use HashedStylesheet and pass it the appropriate props instead.<A> component with a class prop that set the class on the <a> element.) These have been replaced by the new attribute-spreading API, to reduce complexity of the components themselves.LeptosOptions now uses Arc<str> for its fields that were formerly String, so that it is less expensive to clone. In practice, this usually only means using &field or field.as_ref() in a few places that require &str, and so on.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.
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 be Clone 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:
let count = RwSignal::new(0);
let trigger = ArcTrigger::new();
let (tx, rx) = std::sync::mpsc::channel();
let on_click = {
let trigger = trigger.clone();
move |_| {
leptos::logging::log!("clicked");
*count.write() += 1;
tx.send(if *count.read() % 2 == 0 {
view! { <p>"An even paragraph"</p> }.into_any()
} else {
view! { <span>"An odd span"</span> }.into_any()
})
.unwrap();
trigger.trigger();
}
};
view! {
<div>
<button on:click=on_click>"Update view"</button>
{move || {
trigger.track();
rx.try_recv().unwrap_or_else(|_| view! {
<p>"Click the button once to begin."</p>
}.into_any())
}}
</div>
}
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.
rc1Cargo.lock by @sabify in https://github.com/leptos-rs/leptos/pull/3192aria-current is set correctly (closes #3196) by @gbj in https://github.com/leptos-rs/leptos/pull/3213attr: syntax (closes #3221) by @gbj in https://github.com/leptos-rs/leptos/pull/3214___: attributes on components by @gbj in https://github.com/leptos-rs/leptos/pull/3218autofix.ci to address formatting issues and possible clippy fixes by @sabify in https://github.com/leptos-rs/leptos/pull/3235autofix.ci on pull requests only by @sabify in https://github.com/leptos-rs/leptos/pull/3238experimental-islands to islands by @gbj in https://github.com/leptos-rs/leptos/pull/3247map_untracked to OptionStoreExt by @tqwewe in https://github.com/leptos-rs/leptos/pull/3245Write implementatations for Field<T> and ArcField<T> (closes #3257) by @gbj in https://github.com/leptos-rs/leptos/pull/3262fallback prop to ProtectedRoute and ProtectedParentRoute by @tqwewe in https://github.com/leptos-rs/leptos/pull/3264Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.7.0-rc1...v0.7.0-rc2
…during the series of release candidates require breaking changes to fix.
This is a release candidate for 0.7.0.
This means that APIs are understood to be set for 0.7.0, except to the extent that bugs found during the series of release candidates require breaking changes to fix.
Most of the release notes for this
rcare copied over from the alpha/beta/rc0, but the hope is for this to be a complete picture of changes. Please let me know with any missing breaking changes or features so that can be added.
0.7 is a nearly-complete rewrite of the internals of the framework, with the following goals:
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-0.7 (repo)
Actix: cargo leptos new --git https://github.com/leptos-rs/start-actix-0.7 (repo)
.await on resources and async in <Suspense/>Currently, create_resource allows you to synchronously access the value of some async data as either None or Some(_). However, it requires that you always access it this way. This has some drawbacks:
Now, you can .await a resource, and you can use async blocks within a <Suspense/> via the Suspend wrapper, which makes it easier to chain two resources:
let user = Resource::new(|| (), |_| user_id());
let posts = Resource::new(
// resources still manually track dependencies (necessary for hydration)
move || user.get(),
move |_| async move {
// but you can .await a resource inside another
let user = user.await?;
get_posts(user).await
},
);
view! {
<Suspense>
// you can `.await` resources to avoid dealing with the `None` state
<p>"User ID: " {move || Suspend::new(async move {
match user.await {
// ...
}
})}</p>
// or you can still use .get() to access resources in things like component props
<For
each=move || posts.get().and_then(Result::ok).unwrap_or_default()
key=|post| post.id
let:post
>
// ...
</For>
</Suspense>
}
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 exposes ArcRwSignal, ArcReadSignal, etc., which are Clone but not Copy and manage their memory via reference counting, but can easily be converted into the copyable RwSignal etc. This makes working with nested signal correctly much easier, without sacrificing ergonomics meaningfully. See the 0.7 counters 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.
let long_vec = RwSignal::new(vec![42; 1000]);
let short_vec = RwSignal::new(vec![13; 2]);
// bad: clones both Vecs
let bad_len = move || long_vec.get().len() + short_vec.get().len();
// ugly: awkward nested syntax (or a macro)
let ugly_len = move || long_vec.with(|long| short_vec.with(|short| long.len() + short.len()));
// readable but doesn't clone
let good_len = move || long_vec.read().len() + short_vec.read().len();
These should always be used for short periods of time, not stored somewhere for longer-term use, just like any guard or lock, or you can cause deadlocks or panics.
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 use leptos_meta.
pub fn shell(options: LeptosOptions) -> impl IntoView {
view! {
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<AutoReload options=options.clone() />
<HydrationScripts options/>
<MetaTags/>
</head>
<body>
<App/>
</body>
</html>
}
}
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.
// attributes that are spread onto a component will be applied to *all* elements returned as part of
// the component's view. to apply attributes to a subset of the component, pass them via a component prop
<ComponentThatTakesSpread
// the class:, style:, prop:, on: syntaxes work just as they do on elements
class:foo=true
style:font-weight="bold"
prop:cool=42
on:click=move |_| alert("clicked ComponentThatTakesSpread")
// props are passed as they usually are on components
some_prop=13
// to pass a plain HTML attribute, prefix it with attr:
attr:id="foo"
// or, if you want to include multiple attributes, rather than prefixing each with
// attr:, you can separate them from component props with the spread {..}
{..} // everything after this is treated as an HTML attribute
title="ooh, a title!"
{..spread_onto_component}
/>
<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 new ProtectedRoute is reactive and uses Suspense so you can use resources or reactive data. There are examples of this now in router and ssr_modes_axum.
bind: syntaxTwo-way binding allows you to pass signals directly to inputs, rather than separately managing prop:value and on:input to sync the signals to the inputs.
// You can use `RwSignal`s
let is_awesome = RwSignal::new(true);
let sth = RwSignal::new("one".to_string());
// And you can use split signals
let (text, set_text) = signal("Hello world".to_string());
view! {
// Use `bind:checked` and a `bool` signal for a checkbox
<input type="checkbox" bind:checked=is_awesome />
// Use `bind:group` and `String` for radio inputs
<input type="radio" value="one" bind:group=sth />
<input type="radio" value="two" bind:group=sth />
<input type="radio" value="trhee" bind:group=sth />
// Use `bind:value` and `String` for everything else
<input type="text" bind:value=(text, set_text) />
<textarea bind:value=(text, set_text) />
}
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.
The Routes/FlatRoutes component now have a transition prop. Setting this to true 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 first Outlet, etc.) The router example uses this API.
Note: View Transitions are not supported on all browsers, but have been accepted as a standard and can be polyfilled. Using a built-in browser API is much better in the long term than our bug-prone and difficult-to-maintain custom implementation.
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.
- use leptos::*;
+ use leptos::prelude::*;
Likewise, the router exposes things via leptos_router::components and leptos_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.
We're migrating away from create_ naming toward more idiomatic Rust naming patterns:
create_signal to signal (like channel)create_rw_signal to RwSignal::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.
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 the Either enums in leptos::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 the Either types should be preferred, but AnyView is not bad to use when needed.
// Either
if some_condition {
Either::Left(view! { <p>"Foo"</p> })
} else {
Either::Right("Bar")
}
// .into_any()
if some_condition {
view! { <p>"Foo"</p> }.into_any()
} else {
"Bar".into_any()
}
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 takes LeptosOptions as an argumentleptos::mount::hydrate_body (hydration) instead of leptos::mount::mount_to_body (which is now CSR-specific)Check the starter templates for a good setup.
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" becomes path=StaticSegment("foo"), and there are path=":id" becomes path=ParamSegment("id"), path="posts/:id" becomes path=(StaticSegment("posts"), ParamSegment("id")), and so on. There is a path!() macro that will do this for you: i.e., it will expand path!("/foo/:id") to path=(StaticSegment("foo"), ParamSegment("id")).See the router and hackernews 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 specify LocalStorage instead. Many APIs have _local() alternatives to enable this.
let (foo, bar) = signal("baz");
// error: `std::rc::Rc<&str>` cannot be shared between threads safely
// let (foo, bar) = signal(Rc::new("baz"));
let (foo, bar) = signal_local(Rc::new("baz"));
let qux = RwSignal::new("baz");
// error: `std::rc::Rc<&str>` cannot be shared between threads safely
// let qux = RwSignal::new(Rc::new("baz"));
let qux = RwSignal::new_local(Rc::new("baz"));
Await component now takes a plain Future for its future prop rather than a Fn() -> Future, because it uses an optimized resource implementationIntoRender rather than IntoView (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 of cargo-leptos. You can use HashedStylesheet and pass it the appropriate props instead.<A> component with a class prop that set the class on the <a> element.) These have been replaced by the new attribute-spreading API, to reduce complexity of the components themselves.LeptosOptions now uses Arc<str> for its fields that were formerly String, so that it is less expensive to clone. In practice, this usually only means using &field or field.as_ref() in a few places that require &str, and so on.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.
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 be Clone 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:
let count = RwSignal::new(0);
let trigger = ArcTrigger::new();
let (tx, rx) = std::sync::mpsc::channel();
let on_click = {
let trigger = trigger.clone();
move |_| {
leptos::logging::log!("clicked");
*count.write() += 1;
tx.send(if *count.read() % 2 == 0 {
view! { <p>"An even paragraph"</p> }.into_any()
} else {
view! { <span>"An odd span"</span> }.into_any()
})
.unwrap();
trigger.trigger();
}
};
view! {
<div>
<button on:click=on_click>"Update view"</button>
{move || {
trigger.track();
rx.try_recv().unwrap_or_else(|_| view! {
<p>"Click the button once to begin."</p>
}.into_any())
}}
</div>
}
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.
impl IntoStyle for Option<impl IntoStyle & Oco by @zakstucke in https://github.com/leptos-rs/leptos/pull/3119leptos_dom reexports (closes #3166) by @gbj in https://github.com/leptos-rs/leptos/pull/3168wasm32-wasip1/2 target a first-class citizen for Leptos's Server-Side by @raskyld in https://github.com/leptos-rs/leptos/pull/3063!Send errors in Actix extract() by @gbj in https://github.com/leptos-rs/leptos/pull/3189wasm-bindgen to improve compatibility with other crates by @DanielleHuisman in https://github.com/leptos-rs/leptos/pull/3186Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.7.0-rc0...v0.7.0-rc1
…during the series of release candidates require breaking changes to fix.
This is the first release candidate for 0.7.0.
This means that APIs are understood to be set for 0.7.0, except to the extent that bugs found during the series of release candidates require breaking changes to fix.
Most of the release notes for this
rcare copied over from the alpha/beta, but the hope is for this to be a complete picture of changes. Please let me know with any missing breaking changes or features so that can be added.
0.7 is a nearly-complete rewrite of the internals of the framework, with the following goals:
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-0.7 (repo)
Actix: cargo leptos new --git https://github.com/leptos-rs/start-actix-0.7 (repo)
.await on resources and async in <Suspense/>Currently, create_resource allows you to synchronously access the value of some async data as either None or Some(_). However, it requires that you always access it this way. This has some drawbacks:
Now, you can .await a resource, and you can use async blocks within a <Suspense/> via the Suspend wrapper, which makes it easier to chain two resources:
let user = Resource::new(|| (), |_| user_id());
let posts = Resource::new(
// resources still manually track dependencies (necessary for hydration)
move || user.get(),
move |_| async move {
// but you can .await a resource inside another
let user = user.await?;
get_posts(user).await
},
);
view! {
<Suspense>
// you can `.await` resources to avoid dealing with the `None` state
<p>"User ID: " {move || Suspend::new(async move {
match user.await {
// ...
}
})}</p>
// or you can still use .get() to access resources in things like component props
<For
each=move || posts.get().and_then(Result::ok).unwrap_or_default()
key=|post| post.id
let:post
>
// ...
</For>
</Suspense>
}
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 exposes ArcRwSignal, ArcReadSignal, etc., which are Clone but not Copy and manage their memory via reference counting, but can easily be converted into the copyable RwSignal etc. This makes working with nested signal correctly much easier, without sacrificing ergonomics meaningfully. See the 0.7 counters 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.
let long_vec = RwSignal::new(vec![42; 1000]);
let short_vec = RwSignal::new(vec![13; 2]);
// bad: clones both Vecs
let bad_len = move || long_vec.get().len() + short_vec.get().len();
// ugly: awkward nested syntax (or a macro)
let ugly_len = move || long_vec.with(|long| short_vec.with(|short| long.len() + short.len()));
// readable but doesn't clone
let good_len = move || long_vec.read().len() + short_vec.read().len();
These should always be used for short periods of time, not stored somewhere for longer-term use, just like any guard or lock, or you can cause deadlocks or panics.
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 use leptos_meta.
pub fn shell(options: LeptosOptions) -> impl IntoView {
view! {
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<AutoReload options=options.clone() />
<HydrationScripts options/>
<MetaTags/>
</head>
<body>
<App/>
</body>
</html>
}
}
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.
// attributes that are spread onto a component will be applied to *all* elements returned as part of
// the component's view. to apply attributes to a subset of the component, pass them via a component prop
<ComponentThatTakesSpread
// the class:, style:, prop:, on: syntaxes work just as they do on elements
class:foo=true
style:font-weight="bold"
prop:cool=42
on:click=move |_| alert("clicked ComponentThatTakesSpread")
// props are passed as they usually are on components
some_prop=13
// to pass a plain HTML attribute, prefix it with attr:
attr:id="foo"
// or, if you want to include multiple attributes, rather than prefixing each with
// attr:, you can separate them from component props with the spread {..}
{..} // everything after this is treated as an HTML attribute
title="ooh, a title!"
{..spread_onto_component}
/>
<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 new ProtectedRoute is reactive and uses Suspense so you can use resources or reactive data. There are examples of this now in router and ssr_modes_axum.
bind: syntaxTwo-way binding allows you to pass signals directly to inputs, rather than separately managing prop:value and on:input to sync the signals to the inputs.
// You can use `RwSignal`s
let is_awesome = RwSignal::new(true);
let sth = RwSignal::new("one".to_string());
// And you can use split signals
let (text, set_text) = signal("Hello world".to_string());
view! {
// Use `bind:checked` and a `bool` signal for a checkbox
<input type="checkbox" bind:checked=is_awesome />
// Use `bind:group` and `String` for radio inputs
<input type="radio" value="one" bind:group=sth />
<input type="radio" value="two" bind:group=sth />
<input type="radio" value="trhee" bind:group=sth />
// Use `bind:value` and `String` for everything else
<input type="text" bind:value=(text, set_text) />
<textarea bind:value=(text, set_text) />
}
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.
The Routes/FlatRoutes component now have a transition prop. Setting this to true 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 first Outlet, etc.) The router example uses this API.
Note: View Transitions are not supported on all browsers, but have been accepted as a standard and can be polyfilled. Using a built-in browser API is much better in the long term than our bug-prone and difficult-to-maintain custom implementation.
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.
- use leptos::*;
+ use leptos::prelude::*;
Likewise, the router exposes things via leptos_router::components and leptos_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.
We're migrating away from create_ naming toward more idiomatic Rust naming patterns:
create_signal to signal (like channel)create_rw_signal to RwSignal::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.
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 the Either enums in leptos::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 the Either types should be preferred, but AnyView is not bad to use when needed.
// Either
if some_condition {
Either::Left(view! { <p>"Foo"</p> })
} else {
Either::Right("Bar")
}
// .into_any()
if some_condition {
view! { <p>"Foo"</p> }.into_any()
} else {
"Bar".into_any()
}
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 takes LeptosOptions as an argumentleptos::mount::hydrate_body (hydration) instead of leptos::mount::mount_to_body (which is now CSR-specific)Check the starter templates for a good setup.
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" becomes path=StaticSegment("foo"), and there are path=":id" becomes path=ParamSegment("id"), path="posts/:id" becomes path=(StaticSegment("posts"), ParamSegment("id")), and so on. There is a path!() macro that will do this for you: i.e., it will expand path!("/foo/:id") to path=(StaticSegment("foo"), ParamSegment("id")).See the router and hackernews 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 specify LocalStorage instead. Many APIs have _local() alternatives to enable this.
let (foo, bar) = signal("baz");
// error: `std::rc::Rc<&str>` cannot be shared between threads safely
// let (foo, bar) = signal(Rc::new("baz"));
let (foo, bar) = signal_local(Rc::new("baz"));
let qux = RwSignal::new("baz");
// error: `std::rc::Rc<&str>` cannot be shared between threads safely
// let qux = RwSignal::new(Rc::new("baz"));
let qux = RwSignal::new_local(Rc::new("baz"));
Await component now takes a plain Future for its future prop rather than a Fn() -> Future, because it uses an optimized resource implementationIntoRender rather than IntoView (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 of cargo-leptos. You can use HashedStylesheet and pass it the appropriate props instead.<A> component with a class prop that set the class on the <a> element.) These have been replaced by the new attribute-spreading API, to reduce complexity of the components themselves.LeptosOptions now uses Arc<str> for its fields that were formerly String, so that it is less expensive to clone. In practice, this usually only means using &field or field.as_ref() in a few places that require &str, and so on.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.
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 be Clone 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:
let count = RwSignal::new(0);
let trigger = ArcTrigger::new();
let (tx, rx) = std::sync::mpsc::channel();
let on_click = {
let trigger = trigger.clone();
move |_| {
leptos::logging::log!("clicked");
*count.write() += 1;
tx.send(if *count.read() % 2 == 0 {
view! { <p>"An even paragraph"</p> }.into_any()
} else {
view! { <span>"An odd span"</span> }.into_any()
})
.unwrap();
trigger.trigger();
}
};
view! {
<div>
<button on:click=on_click>"Update view"</button>
{move || {
trigger.track();
rx.try_recv().unwrap_or_else(|_| view! {
<p>"Click the button once to begin."</p>
}.into_any())
}}
</div>
}
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.
Params attribute params by @chrisp60 in https://github.com/leptos-rs/leptos/pull/3123From<ArcResource> for Resource & From<AsyncDerived> for ArcAsyncDerived by @zakstucke in https://github.com/leptos-rs/leptos/pull/3121use_matched() (closes #3124) by @gbj in https://github.com/leptos-rs/leptos/pull/3126nostrip: prop prefix to pass Option<T> directly when prop(optional) by @zakstucke in https://github.com/leptos-rs/leptos/pull/3105Action::clear() to clear action value (closes #2364) by @gbj in https://github.com/leptos-rs/leptos/pull/3135LeptosOptions lighter-weight to clone (closes #3036) by @gbj in https://github.com/leptos-rs/leptos/pull/3136Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.7.0-gamma3...v0.7.0-rc0
The -preview here is intended to convey: Here is a mostly-working but pre-alpha release of what I've been working on for the last six months or so. Th
The -preview here is intended to convey: Here is a mostly-working but pre-alpha release of what I've been working on for the last six months or so. This work can be found in the leptos-0.7 branch. Enough work has been done that many (but not all) of the examples in the repo are functioning. This release is a fairly complete rewrite of the internals of the entire framework. You should expect both missing APIs and bugs.
Note the following:
0.7.0-preview2 to the Cargo.toml of an existing app and expect it to workuse leptos::*; to use leptos::prelude::*; and then using modules and reexports more sanely from the main crate0.7.0-preview playground that includes the setup of a basic app with comments. You should be able to expand from there.The following examples in the repo are known to work and can be useful to learn from
countercounterserror_boundaryfetchtodomvcparent_childroutertodo_app_sqlite_axumssr_modes_axumCargo.toml setupuse leptos::prelude::* instead of use leptos::*Send/Sync. In general for values being stored in signals this means you need to use Arc on occasion instead of Rc, etc.
send_wrapper crate. Better ergonomics here are an open questionIntoView trait work quite differently from before. In general, for type-erased views (.into_view() previously) you can use .into_any() or the Either:: types. Storing a View in a signal, cloning it, etc. are not viable approaches any more: store data in signals and rendering views, rather than storing views in signals.Arc equivalents to each signal type (ArcRwSignal, ArcMemo, etc.) which manage their lifecycle via reference counting rather than the reactive ownership graph. This can be used for things like iterating over nested signals (see counters example) and pushing signals "up" in the tree, rather than using the manual .dispose() and owner manipulation patternsRwSignal::new(), signal() instead of create_signal() to match channel(), etc.)path!() macro to parse the old strings into this format but it's not implemented.on: on components (e82227aa07023855ac704c4f484a466109c3f8cc)MaybeSignalSignal::with()cargo-leptos hot reloading-alpha!Send/!Sync thread-local arena for browser-type signalsTry things out, see what breaks, see what feels good. How can we improve the module imports? What are pain points? etc. Feel free to comment here or on Discord in the #preview channel,
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
Nothing published for this version
By the time of final release, help compiling a total list of breaking changes/migration guide would be much appreciated. At present, the starter templ…
This is a release made from #2607, with updates, bugfixes, and improvements since 0.7.0-alpha.
Most of the release notes for this beta are copied over from the alpha.
0.7 is a nearly-complete rewrite of the internals of the framework, with the following goals:
I am going on vacation for a couple weeks, and my hope is to give some time over the summer for people to really test, explore, and try to migrate.
0.7 works with the current cargo-leptos version. If you want to start exploring, I've created 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-0.7 (repo)
Actix: cargo leptos new --git https://github.com/leptos-rs/start-actix-0.7 (repo)
Please use the PR (#2607) or the #07-beta channel in our Discord for feedback or questions.
Generally speaking, the leptos_0.7 branch will include the latest bug fixes, but any given commit may be broken (sorry!)
.await on resources and async in <Suspense/>Currently, create_resource allows you to synchronously access the value of some async data as either None or Some(_). However, it requires that you always access it this way. This has some drawbacks:
Now, you can .await a resource, and you can use async blocks within a <Suspense/> via the Suspend wrapper, which makes it easier to chain two resources:
let user = Resource::new(|| (), |_| user_id());
let posts = Resource::new(
// resources still manually track dependencies (necessary for hydration)
move || user.track(),
move |_| async move {
// but you can .await a resource inside another
let user = user.await?;
get_posts(user).await
},
);
view! {
<Suspense>
// you can `.await` resources to avoid dealing with the `None` state
<p>"User ID: " {move || Suspend::new(async move {
match user.await {
// ...
}
})}</p>
// or you can still use .get() to access resources in things like component props
<For
each=move || posts.get().and_then(Result::ok).unwrap_or_default()
key=|post| post.id
let:post
>
// ...
</For>
</Suspense>
}
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 current example.) 0.7 exposes ArcRwSignal, ArcReadSignal, etc., which are Clone but not Copy and manage their memory via reference counting, but can easily be converted into the copyable RwSignal etc. This makes working with nested signal correctly much easier, without sacrificing ergonomics meaningfully. See the 0.7 counters 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.
let long_vec = RwSignal::new(vec![42; 1000]);
let short_vec = RwSignal::new(vec![13; 2]);
// bad: clones both Vecs
let bad_len = move || long_vec.get().len() + short_vec.get().len();
// ugly: awkward nested syntax (or a macro)
let ugly_len = move || long_vec.with(|long| short_vec.with(|short| long.len() + short.len()));
// readable but doesn't clone
let good_len = move || long_vec.read().len() + short_vec.read().len();
These should always be used for short periods of time, not stored somewhere for longer-term use, just like any guard or lock, or you can cause deadlocks or panics.
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 use leptos_meta.
pub fn shell(options: LeptosOptions) -> impl IntoView {
view! {
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<AutoReload options=options.clone() />
<HydrationScripts options/>
<MetaTags/>
</head>
<body>
<App/>
</body>
</html>
}
}
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.
// attributes that are spread onto a component will be applied to *all* elements returned as part of
// the component's view. to apply attributes to a subset of the component, pass them via a component prop
<ComponentThatTakesSpread
// the class:, style:, prop:, on: syntaxes work just as they do on elements
class:foo=true
style:font-weight="bold"
prop:cool=42
on:click=move |_| alert("clicked ComponentThatTakesSpread")
// props are passed as they usually are on components
some_prop=13
// to pass a plain HTML attribute, prefix it with attr:
attr:id="foo"
// or, if you want to include multiple attributes, rather than prefixing each with
// attr:, you can separate them from component props with the spread {..}
{..} // everything after this is treated as an HTML attribute
title="ooh, a title!"
{..spread_onto_component}
/>
<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 new ProtectedRoute is reactive and uses Suspense so you can use resources or reactive data. There are examples of this now in router and ssr_modes_axum.
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.
- use leptos::*;
+ use leptos::prelude::*;
Likewise, the router exposes things via leptos_router::components and leptos_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.
We're migrating away from create_ naming toward more idiomatic Rust naming patterns:
create_signal to signal (like channel)create_rw_signal to RwSignal::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.
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 the Either enums in leptos::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 the Either types should be preferred, but AnyView is not bad to use when needed.
// Either
if some_condition {
Either::Left(view! { <p>"Foo"</p> })
} else {
Either::Right("Bar")
}
// .into_any()
if some_condition {
view! { <p>"Foo"</p> }.into_any()
} else {
"Bar".into_any()
}
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 takes LeptosOptions as an argumentleptos::mount::hydrate_body (hydration) instead of leptos::mount::mount_to_body (which is now CSR-specific)Check the starter templates for a good setup.
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" becomes path=StaticSegment("foo"), and there are path=":id" becomes path=ParamSegment("id"), path="posts/:id" becomes path=(StaticSegment("posts"), ParamSegment("id")), and so on. There is a path!() macro that will do this for you: i.e., it will expand path!("/foo/:id") to path=(StaticSegment("foo"), ParamSegment("id")).See the router and hackernews 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 specify LocalStorage instead. Many APIs have _local() alternatives to enable this.
let (foo, bar) = signal("baz");
// error: `std::rc::Rc<&str>` cannot be shared between threads safely
// let (foo, bar) = signal(Rc::new("baz"));
let (foo, bar) = signal_local(Rc::new("baz"));
let qux = RwSignal::new("baz");
// error: `std::rc::Rc<&str>` cannot be shared between threads safely
// let qux = RwSignal::new(Rc::new("baz"));
let qux = RwSignal::new_local(Rc::new("baz"));
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.
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 be Clone 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:
let count = RwSignal::new(0);
let trigger = ArcTrigger::new();
let (tx, rx) = std::sync::mpsc::channel();
let on_click = {
let trigger = trigger.clone();
move |_| {
leptos::logging::log!("clicked");
*count.write() += 1;
tx.send(if *count.read() % 2 == 0 {
view! { <p>"An even paragraph"</p> }.into_any()
} else {
view! { <span>"An odd span"</span> }.into_any()
})
.unwrap();
trigger.trigger();
}
};
view! {
<div>
<button on:click=on_click>"Update view"</button>
{move || {
trigger.track();
rx.try_recv().unwrap_or_else(|_| view! {
<p>"Click the button once to begin."</p>
}.into_any())
}}
</div>
}
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.
Nothing published for this version
By the time of final release, help compiling a total list of breaking changes/migration guide would be much appreciated. At present, the starter templ…
This is a release made from #2607, now that the 0.7 branch has reached a relatively stable state, and all of the examples are in working condition.
0.7 is a nearly-complete rewrite of the internals of the framework, with the following goals:
My goal between now and the end of July is to fill in the remaining missing pieces and release a beta version.
0.7 works with the current cargo-leptos version. If you want to start exploring, I've created 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-0.7 (repo)
Actix: cargo leptos new --git https://github.com/leptos-rs/start-actix-0.7 (repo)
Please use the PR (#2607) or the #preview channel in our Discord for feedback or questions.
Generally speaking, the leptos_0.7 branch will include the latest bug fixes, but any given commit may be broken (sorry!)
.await on resources and async in <Suspense/>Currently, create_resource allows you to synchronously access the value of some async data as either None or Some(_). However, it requires that you always access it this way. This has some drawbacks:
Now, you can .await a resource, and you can use async blocks within a <Suspense/> via the Suspend wrapper, which makes it easier to chain two resources:
let user = Resource::new(|| (), |_| user_id());
let posts = Resource::new(
// resources still manually track dependencies (necessary for hydration)
move || user.track(),
move |_| async move {
// but you can .await a resource inside another
let user = user.await?;
get_posts(user).await
},
);
view! {
<Suspense>
// you can `.await` resources to avoid dealing with the `None` state
<p>"User ID: " {move || Suspend(async move {
match user.await {
// ...
}
})}</p>
// or you can still use .get() to access resources in things like component props
<For
each=move || posts.get().and_then(Result::ok).unwrap_or_default()
key=|post| post.id
let:post
>
// ...
</For>
</Suspense>
}
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 current example.) 0.7 exposes ArcRwSignal, ArcReadSignal, etc., which are Clone but not Copy and manage their memory via reference counting, but can easily be converted into the copyable RwSignal etc. This makes working with nested signal correctly much easier, without sacrificing ergonomics meaningfully. See the 0.7 counters 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.
let long_vec = RwSignal::new(vec![42; 1000]);
let short_vec = RwSignal::new(vec![13; 2]);
// bad: clones both Vecs
let bad_len = move || long_vec.get().len() + short_vec.get().len();
// ugly: awkward nested syntax (or a macro)
let ugly_len = move || long_vec.with(|long| short_vec.with(|short| long.len() + short.len()));
// readable but doesn't clone
let good_len = move || long_vec.read().len() + short_vec.read().len();
These should always be used for short periods of time, not stored somewhere for longer-term use, just like any guard or lock, or you can cause deadlocks or panics.
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 use leptos_meta.
pub fn shell(options: LeptosOptions) -> impl IntoView {
view! {
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<AutoReload options=options.clone() />
<HydrationScripts options/>
<MetaTags/>
</head>
<body>
<App/>
</body>
</html>
}
}
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.
// attributes that are spread onto a component will be applied to *all* elements returned as part of
// the component's view. to apply attributes to a subset of the component, pass them via a component prop
<ComponentThatTakesSpread
// the class:, style:, prop:, on: syntaxes work just as they do on elements
class:foo=true
style:font-weight="bold"
prop:cool=42
on:click=move |_| alert("clicked ComponentThatTakesSpread")
// props are passed as they usually are on components
some_prop=13
// to pass a plain HTML attribute, prefix it with attr:
attr:id="foo"
// or, if you want to include multiple attributes, rather than prefixing each with
// attr:, you can separate them from component props with the spread {..}
{..} // everything after this is treated as an HTML attribute
title="ooh, a title!"
{..spread_onto_component}
/>
<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 new ProtectedRoute is reactive and uses Suspense so you can use resources or reactive data. There are examples of this now in router and ssr_modes_axum.
<ProtectedRoute/>Suspend(_) without a <Suspense/>set_is_routing<Body/> etc. instead of Vec<AnyAttribute>IntoView on an arbitrary structLazy routes and hydration (what do you do while hydrating if the code for the route hasn't been lazy-loaded yet?)path!() macro to make route definitions easier in routerCopy but !Send for !Send data (like browser things)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.
- use leptos::*;
+ use leptos::prelude::*;
Likewise, the router exposes things via leptos_router::components and leptos_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.
We're migrating away from create_ naming toward more idiomatic Rust naming patterns:
create_signal to signal (like channel)create_rw_signal to RwSignal::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.
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 the Either enums in leptos::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 the Either types should be preferred, but AnyView is not bad to use when needed.
// Either
if some_condition {
Either::Left(view! { <p>"Foo"</p> })
} else {
Either::Right("Bar")
}
// .into_any()
if some_condition {
view! { <p>"Foo"</p> }.into_any()
} else {
"Bar".into_any()
}
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 takes LeptosOptions as an argumentleptos::mount::hydrate_body (hydration) instead of leptos::mount::mount_to_body (which is now CSR-specific)Check the starter templates for a good setup.
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" becomes path=StaticSegment("foo"), and there are path=":id" becomes path=ParamSegment("id"), path="posts/:id" becomes path=(StaticSegment("posts"), ParamSegment("id")), and so on. I plan to create a path!() macro that will do this for you, and just haven't done it yet.See the router and hackernews examples.
Send/Sync signalsThe data held in reactive primitives (signals, memos, effects) must be safe to send across threads. Threading the needle of the type system in order to ensure thread safety on the server while allowing flexibility in the browser (where you generally don't have multiple threads and where most types are !Send) is complicated. If you have browser-only types that need to be stored in signals, you can use the send_wrapper crate to wrap them. We also have _unsync versions of several APIs that allow you to use !Send types: see example.
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.
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 be Clone 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:
let count = RwSignal::new(0);
let trigger = ArcTrigger::new();
let (tx, rx) = std::sync::mpsc::channel();
let on_click = {
let trigger = trigger.clone();
move |_| {
leptos::logging::log!("clicked");
*count.write() += 1;
tx.send(if *count.read() % 2 == 0 {
view! { <p>"An even paragraph"</p> }.into_any()
} else {
view! { <span>"An odd span"</span> }.into_any()
})
.unwrap();
trigger.trigger();
}
};
view! {
<div>
<button on:click=on_click>"Update view"</button>
{move || {
trigger.track();
rx.try_recv().unwrap_or_else(|_| view! {
<p>"Click the button once to begin."</p>
}.into_any())
}}
</div>
}
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.
Belated release notes for 0.6.15. This was a quick patch release to incorporate two changes, one to improve rust-analyzer support and the other to swi
Belated release notes for 0.6.15. This was a quick patch release to incorporate two changes, one to improve rust-analyzer support and the other to switch from the unmaintained proc-macro-error to proc-macro-error2 per RUSTSEC.
proc-macro-error2 to address unmaintained security advisory. by @azriel91 in https://github.com/leptos-rs/leptos/pull/2935Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.6.14...v0.6.15
Hello everyone, The biggest change in this update is to handle wasm-bindgen 0.2.93 and web_sys 0.3.70 Thanks to @sabify and @maccesch for those PRs. A
Hello everyone, The biggest change in this update is to handle wasm-bindgen 0.2.93 and web_sys 0.3.70 Thanks to @sabify and @maccesch for those PRs. As always, let us know if there's issues.
wasm-bindgen and web-sys for leptos 0.6 by @sabify in https://github.com/leptos-rs/leptos/pull/2830Full Changelog: https://github.com/leptos-rs/leptos/compare/v0.6.13...v0.6.14
One column per quarter.