1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
///  Configuration for the WebSys renderer for the Dioxus VirtualDOM.
///
/// This struct helps configure the specifics of hydration and render destination for WebSys.
///
/// # Example
/// ```rust, ignore
/// fn main() {
///     dioxus::web::launch(App, |cfg| cfg.hydrate(true).root_name("myroot"))
/// }
/// ```
pub struct WebConfig {
    pub(crate) hydrate: bool,
    pub(crate) rootname: String,
    pub(crate) cached_strings: Vec<String>,
}

impl Default for WebConfig {
    fn default() -> Self {
        Self {
            hydrate: false,
            rootname: "main".to_string(),
            cached_strings: Vec::new(),
        }
    }
}

impl WebConfig {
    /// Enable SSR hydration
    ///
    /// This enables Dioxus to pick up work from a pre-renderd HTML file. Hydration will completely skip over any async
    /// work and suspended nodes.
    ///
    /// Dioxus will load up all the elements with the `dio_el` data attribute into memory when the page is loaded.
    pub fn hydrate(mut self, f: bool) -> Self {
        self.hydrate = f;
        self
    }

    /// Set the name of the element that Dioxus will use as the root.
    ///
    /// This is akint to calling React.render() on the element with the specified name.
    pub fn rootname(mut self, name: impl Into<String>) -> Self {
        self.rootname = name.into();
        self
    }

    /// Set the name of the element that Dioxus will use as the root.
    ///
    /// This is akint to calling React.render() on the element with the specified name.
    pub fn with_string_cache(mut self, cache: Vec<String>) -> Self {
        self.cached_strings = cache;
        self
    }
}