From 1ff0a7176d95e006d60b26e9c11735164a82698d Mon Sep 17 00:00:00 2001 From: Ben Wishovich Date: Sun, 14 Apr 2024 14:34:38 -0700 Subject: [PATCH 1/3] Update spin_sdk to spin v3 (#2525) * Update spin_sdk to spin v3 * Add id to Body --- leptos_reactive/Cargo.toml | 2 +- meta/src/body.rs | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/leptos_reactive/Cargo.toml b/leptos_reactive/Cargo.toml index 45169e934e..35b7311e11 100644 --- a/leptos_reactive/Cargo.toml +++ b/leptos_reactive/Cargo.toml @@ -27,7 +27,7 @@ bytecheck = { version = "0.7", features = [ rustc-hash = "1" serde-wasm-bindgen = "0.6" serde_json = "1" -spin-sdk = { version = "2", optional = true } +spin-sdk = { version = "3", optional = true } base64 = "0.22" thiserror = "1" tokio = { version = "1", features = [ diff --git a/meta/src/body.rs b/meta/src/body.rs index e0a2aaf49e..f67cfa314f 100644 --- a/meta/src/body.rs +++ b/meta/src/body.rs @@ -11,6 +11,8 @@ pub struct BodyContext { #[cfg(feature = "ssr")] class: Rc>>, #[cfg(feature = "ssr")] + id: Rc>>, + #[cfg(feature = "ssr")] attributes: Rc>>, } @@ -24,6 +26,13 @@ impl BodyContext { leptos::leptos_dom::ssr::escape_attr(&val.get()) ) }); + + let id = self.id.borrow().as_ref().map(|val| { + format!( + "id=\"{}\"", + leptos::leptos_dom::ssr::escape_attr(&val.get()) + ) + }); let attributes = self.attributes.borrow(); let attributes = (!attributes.is_empty()).then(|| { attributes @@ -41,7 +50,7 @@ impl BodyContext { .join(" ") }); - let mut val = [class, attributes] + let mut val = [id, class, attributes] .into_iter() .flatten() .collect::>() @@ -92,6 +101,9 @@ pub fn Body( /// The `class` attribute on the ``. #[prop(optional, into)] class: Option, + /// The `id` attribute on the ``. + #[prop(optional, into)] + id: Option, /// Arbitrary attributes to add to the `` #[prop(attrs)] attributes: Vec<(&'static str, Attribute)>, @@ -112,15 +124,27 @@ pub fn Body( }); } + + if let Some(id) = id { + create_render_effect({ + let el = el.clone(); + move |_| { + let value = id.get(); + _ = el.set_attribute("id", &value); + } + }); + } for (name, value) in attributes { leptos::leptos_dom::attribute_helper(el.unchecked_ref(), name.into(), value); } } else if #[cfg(feature = "ssr")] { let meta = crate::use_head(); *meta.body.class.borrow_mut() = class; + *meta.body.id.borrow_mut() = id; meta.body.attributes.borrow_mut().extend(attributes); } else { _ = class; + _ = id; _ = attributes; #[cfg(debug_assertions)] From 35a8ca1f3973fc4d4a935d02ef24550e84de4418 Mon Sep 17 00:00:00 2001 From: Sam Judelson <64875465+sjud@users.noreply.github.com> Date: Sun, 14 Apr 2024 17:38:08 -0400 Subject: [PATCH 2/3] Add beginner tip to ErrorBoundary (#2385) * Add beginner tip to ErrorBoundary This might seem simple, but the nuances of types and traits confuse many people learning the language. * edit * Update error_boundary.rs * edits * ignore error block --- leptos/src/error_boundary.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/leptos/src/error_boundary.rs b/leptos/src/error_boundary.rs index 4c187a7087..c5a682f90e 100644 --- a/leptos/src/error_boundary.rs +++ b/leptos/src/error_boundary.rs @@ -48,6 +48,28 @@ use leptos_reactive::{provide_context, run_as_child, signal_prelude::*}; /// {move || { /// /* etc. */ /// ``` +/// +/// ## Beginner's Tip: ErrorBoundary Requires Your Error To Implement std::error::Error. +/// `ErrorBoundary` requires your `Result` to implement [IntoView](https://docs.rs/leptos/latest/leptos/trait.IntoView.html). +/// `Result` only implements `IntoView` if `E` implements [std::error::Error](https://doc.rust-lang.org/std/error/trait.Error.html). +/// So, for instance, if you pass a `Result` where `T` implements [IntoView](https://docs.rs/leptos/latest/leptos/trait.IntoView.html) +/// and attempt to render the error for the purposes of `ErrorBoundary` you'll get a compiler error like this. +/// +/// ```rust,ignore +/// error[E0599]: the method `into_view` exists for enum `Result`, but its trait bounds were not satisfied +/// --> src/login.rs:229:32 +/// | +/// 229 | err => err.into_view(), +/// | ^^^^^^^^^ method cannot be called on `Result` due to unsatisfied trait bounds +/// | +/// = note: the following trait bounds were not satisfied: +/// `<&Result as FnOnce<()>>::Output = _` +/// which is required by `&Result: leptos::IntoView` +/// ... more notes here ... +/// ``` +/// +/// For more information about how to easily implement `Error` see +/// [thiserror](https://docs.rs/thiserror/latest/thiserror/) #[component] pub fn ErrorBoundary( /// The components inside the tag which will get rendered From 9a51fb17fceed86e501e6a950952bf41b70c6889 Mon Sep 17 00:00:00 2001 From: martin frances Date: Sun, 14 Apr 2024 22:39:44 +0100 Subject: [PATCH 3/3] Minor: Bumped serde_qs to 0.13. (#2512) --- router/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/router/Cargo.toml b/router/Cargo.toml index 984a99528d..441a81ff01 100644 --- a/router/Cargo.toml +++ b/router/Cargo.toml @@ -23,7 +23,7 @@ regex = { version = "1", optional = true } url = { version = "2", optional = true } percent-encoding = "2" thiserror = "1" -serde_qs = "0.12" +serde_qs = "0.13" serde = "1" tracing = "0.1" js-sys = { version = "0.3" }