dioxus_fullstack/
web.rs

1//! On the client, we use the [`WebDocument`] implementation to render the head for any elements that were not rendered on the server.
2
3use dioxus_lib::document::*;
4use dioxus_web::WebDocument;
5
6fn head_element_written_on_server() -> bool {
7    dioxus_fullstack_protocol::head_element_hydration_entry()
8        .get()
9        .ok()
10        .unwrap_or_default()
11}
12
13/// A document provider for fullstack web clients
14#[derive(Clone)]
15pub struct FullstackWebDocument;
16
17impl Document for FullstackWebDocument {
18    fn eval(&self, js: String) -> Eval {
19        WebDocument.eval(js)
20    }
21
22    /// Set the title of the document
23    fn set_title(&self, title: String) {
24        WebDocument.set_title(title);
25    }
26
27    /// Create a new meta tag in the head
28    fn create_meta(&self, props: MetaProps) {
29        WebDocument.create_meta(props);
30    }
31
32    /// Create a new script tag in the head
33    fn create_script(&self, props: ScriptProps) {
34        WebDocument.create_script(props);
35    }
36
37    /// Create a new style tag in the head
38    fn create_style(&self, props: StyleProps) {
39        WebDocument.create_style(props);
40    }
41
42    /// Create a new link tag in the head
43    fn create_link(&self, props: LinkProps) {
44        WebDocument.create_link(props);
45    }
46
47    fn create_head_component(&self) -> bool {
48        !head_element_written_on_server()
49    }
50}