From fc595e021e3e576f231353af0fb7e37fcc0a987e Mon Sep 17 00:00:00 2001 From: Ada Werefox Date: Thu, 6 Apr 2023 20:59:19 -0500 Subject: [PATCH] Fixed rendering in Rocket with conditional compilation macros. Will raise an issue for Dioxus since this is ultimately their problem. --- rust-letter-fe/src/lib.rs | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/rust-letter-fe/src/lib.rs b/rust-letter-fe/src/lib.rs index 482a424..4bd0e3e 100644 --- a/rust-letter-fe/src/lib.rs +++ b/rust-letter-fe/src/lib.rs @@ -43,9 +43,28 @@ pub mod web_app { )) } - fn MakePoem(cx: Scope) -> Element { + #[cfg(any(target_family = "unix", target_family = "windows"))] + pub fn RenderPoemElement(cx: Scope) -> Element { let poem_str = include_str!("../../data/poem.md"); let poem = markdown::to_html(poem_str); + cx.render(rsx!(div { + class: "font-nerd flex flex-col space-y-4 mx-4 py-4", + "{poem}",})) + } + + #[cfg(target_family = "wasm")] + pub fn RenderPoemElement(cx: Scope) -> Element { + let poem_str = include_str!("../../data/poem.md"); + let poem = markdown::to_html(poem_str); + cx.render(rsx!(div { + class: "font-nerd flex flex-col space-y-4 mx-4 py-4", + dangerous_inner_html: "{poem}" + },)) + } + + fn MakePoem(cx: Scope) -> Element { + let mut vdom = VirtualDom::new(RenderPoemElement); + let _ = vdom.rebuild(); cx.render(rsx!( div { @@ -60,10 +79,7 @@ pub mod web_app { class: "flex justify-center border-4 bg-alice-werefox-grey-lightest dark:bg-alice-werefox-grey-dark border-4 border-alice-werefox-red-dark dark:border-alice-werefox-red text-alice-werefox-red-dark dark:text-alice-werefox-red-light p-4", "Tell Me More" }, - div { - class: "font-nerd flex flex-col space-y-4 mx-4 py-4", - dangerous_inner_html: "{poem}", - } + RenderPoemElement {}, } } ))