DioxusLabs / dioxus

Fullstack app framework for web, desktop, mobile, and more.
https://dioxuslabs.com
Apache License 2.0
20.32k stars 779 forks source link

Allow Fragment to take dangerous_inner_html #608

Closed tv42 closed 1 year ago

tv42 commented 1 year ago

Specific Demand

I'm trying to add a <!DOCTYPE html> to the beginning of a SSR response.

It seems the easiest way to make that happen would to be allow rsx! Fragment to take dangerous_inner_html.

This doesn't seem to exist at this time:

error[E0599]: no method named `dangerous_inner_html` found for struct `core::properties::FragmentBuilder` in the current scope
  --> src/bin/demo.rs:15:9
   |
15 |         dangerous_inner_html: "FOO",
   |         ^^^^^^^^^^^^^^^^^^^^ method not found in `core::properties::FragmentBuilder<'_, false>`
ealmloff commented 1 year ago

The SSR renderer only outputs what should rendered inside of the main div. If you want to add <!DOCTYPE html> you can add it to the front of the output of the output of ssr.

use dioxus::prelude::*;

fn main() {
    let mut vdom = VirtualDom::new(app);
    let _ = vdom.rebuild();
    let full_html = format!("<!DOCTYPE html>{}", dioxus_ssr::pre_render(&vdom));
    println!("{}", full_html);
}

fn app(cx: Scope) -> Element {
    cx.render(rsx!(
        div {
            h1 { "Title" }
            p { "Body" }
        }
    ))
}
ealmloff commented 1 year ago

Closing this for the same reason as https://github.com/DioxusLabs/dioxus/issues/311. It is difficult to implement with templates