ソースを参照

fix test failures

Evan Almloff 1 年間 前
コミット
e43bdd815f

+ 4 - 1
packages/router/src/history/mod.rs

@@ -88,15 +88,18 @@ pub trait HistoryProvider<R: Routable> {
     /// # use dioxus::prelude::*;   
     /// # #[inline_props]
     /// # fn Index(cx: Scope) -> Element { todo!() }
+    /// # fn Other(cx: Scope) -> Element { todo!() }
     /// #[derive(Clone, Routable, Debug, PartialEq)]
     /// enum Route {
     ///     #[route("/")]
     ///     Index {},
+    ///     #[route("/other")]
+    ///     Other {},
     /// }
     /// let mut history = MemoryHistory::<Route>::default();
     /// assert_eq!(history.can_go_back(), false);
     ///
-    /// history.push(Route::Index {});
+    /// history.push(Route::Other {});
     /// assert_eq!(history.can_go_back(), true);
     /// ```
     #[must_use]

+ 1 - 1
packages/router/src/hooks/use_route.rs

@@ -34,7 +34,7 @@ use crate::utils::use_router_internal::use_router_internal;
 ///
 /// #[inline_props]
 /// fn Index(cx: Scope) -> Element {
-///     let path = use_route(&cx).unwrap();
+///     let path: Route = use_route(&cx).unwrap();
 ///     render! {
 ///         h2 { "Current Path" }
 ///         p { "{path}" }

+ 2 - 2
packages/router/src/routable.rs

@@ -162,9 +162,9 @@ pub trait Routable: std::fmt::Display + std::str::FromStr + Clone + 'static {
     ///
     /// #[derive(Routable, Clone, PartialEq, Debug)]
     /// enum Route {
-    ///     #[route("/")]
+    ///     #[route("/home")]
     ///     Home {},
-    ///     #[route("/about")]
+    ///     #[route("/home/about")]
     ///     About {},
     /// }
     ///

+ 13 - 2
packages/ssr/src/renderer.rs

@@ -1,6 +1,7 @@
 use super::cache::Segment;
 use crate::cache::StringCache;
 
+use dioxus_core::Attribute;
 use dioxus_core::{prelude::*, AttributeValue, DynamicNode, RenderReturn};
 use std::collections::HashMap;
 use std::fmt::Write;
@@ -90,8 +91,7 @@ impl Renderer {
                             write_value(buf, &attr.value)?;
                         }
                     } else {
-                        write!(buf, " {}=", attr.name)?;
-                        write_value(buf, &attr.value)?;
+                        write_attribute(buf, &attr)?;
                     }
                 }
                 Segment::Node(idx) => match &template.dynamic_nodes[*idx] {
@@ -282,6 +282,17 @@ pub(crate) fn truthy(value: &AttributeValue) -> bool {
     }
 }
 
+pub(crate) fn write_attribute(buf: &mut impl Write, attr: &Attribute) -> std::fmt::Result {
+    let name = &attr.name;
+    match attr.value {
+        AttributeValue::Text(value) => write!(buf, " {name}=\"{value}\""),
+        AttributeValue::Bool(value) => write!(buf, " {name}={value}"),
+        AttributeValue::Int(value) => write!(buf, " {name}={value}"),
+        AttributeValue::Float(value) => write!(buf, " {name}={value}"),
+        _ => Ok(()),
+    }
+}
+
 pub(crate) fn write_value(buf: &mut impl Write, value: &AttributeValue) -> std::fmt::Result {
     match value {
         AttributeValue::Text(value) => write!(buf, "\"{}\"", value),

+ 0 - 1
packages/ssr/tests/bool_attr.rs

@@ -21,7 +21,6 @@ fn static_boolean_attributs() {
 #[test]
 fn dynamic_boolean_attributs() {
     fn app(cx: Scope) -> Element {
-        let inner_html = "<div>1234</div>";
         render! {
             div { hidden: false }
             div { hidden: true }