dioxus_fullstack/document/
web.rs

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