Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update spin_sdk to spin v3 #2525

Merged
merged 2 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion leptos_reactive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
26 changes: 25 additions & 1 deletion meta/src/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ pub struct BodyContext {
#[cfg(feature = "ssr")]
class: Rc<RefCell<Option<TextProp>>>,
#[cfg(feature = "ssr")]
id: Rc<RefCell<Option<TextProp>>>,
#[cfg(feature = "ssr")]
attributes: Rc<RefCell<HashMap<&'static str, Attribute>>>,
}

Expand All @@ -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
Expand All @@ -41,7 +50,7 @@ impl BodyContext {
.join(" ")
});

let mut val = [class, attributes]
let mut val = [id, class, attributes]
.into_iter()
.flatten()
.collect::<Vec<_>>()
Expand Down Expand Up @@ -92,6 +101,9 @@ pub fn Body(
/// The `class` attribute on the `<body>`.
#[prop(optional, into)]
class: Option<TextProp>,
/// The `id` attribute on the `<body>`.
#[prop(optional, into)]
id: Option<TextProp>,
/// Arbitrary attributes to add to the `<body>`
#[prop(attrs)]
attributes: Vec<(&'static str, Attribute)>,
Expand All @@ -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)]
Expand Down
Loading