From f3b62bcf88695bf4c67961f1b9ac6cd4ac940319 Mon Sep 17 00:00:00 2001 From: Jose Quesada Date: Wed, 28 Dec 2022 11:34:27 -0600 Subject: [PATCH] impl `HtmlElement::inner_html` for SSR --- leptos_dom/src/html.rs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/leptos_dom/src/html.rs b/leptos_dom/src/html.rs index 9231d41ed..f54846717 100644 --- a/leptos_dom/src/html.rs +++ b/leptos_dom/src/html.rs @@ -608,18 +608,33 @@ impl HtmlElement { /// Be very careful when using this method. Always remember to /// sanitize the input to avoid a cross-site scripting (XSS) /// vulnerability. - pub fn inner_html(self, html: &str) -> Self { + pub fn inner_html(self, html: impl Into>) -> Self { + let html = html.into(); + #[cfg(all(target_arch = "wasm32", feature = "web"))] { - self.element.as_ref().set_inner_html(html); + self.element.as_ref().set_inner_html(&html); + + self } #[cfg(not(all(target_arch = "wasm32", feature = "web")))] { - todo!("impl this method for SSR"); - } + let mut this = self; - self + let child = HtmlElement::from_html( + this.cx, + Custom { + name: "inner-html".into(), + id: Default::default(), + }, + html, + ); + + this.children = smallvec![child.into_view(this.cx)]; + + this + } } }