1
0
Эх сурвалжийг харах

fix the incremental feature on the router

Evan Almloff 1 жил өмнө
parent
commit
2034591ab3

+ 1 - 1
packages/router/Cargo.toml

@@ -32,7 +32,7 @@ dioxus-cli-config = { workspace = true }
 
 [features]
 default = []
-ssr = ["dioxus-ssr", "tokio"]
+ssr = ["dioxus-ssr/incremental", "tokio", "dioxus-fullstack?/ssr"]
 liveview = ["dioxus-liveview", "tokio", "dep:serde", "serde_json"]
 wasm_test = []
 serde = ["dep:serde", "gloo-utils?/serde"]

+ 14 - 7
packages/router/src/incremental.rs

@@ -3,7 +3,7 @@ use core::pin::Pin;
 use std::future::Future;
 use std::str::FromStr;
 
-use dioxus::prelude::*;
+use dioxus_lib::prelude::*;
 use dioxus_ssr::incremental::{
     IncrementalRenderer, IncrementalRendererError, RenderFreshness, WrapBody,
 };
@@ -50,7 +50,7 @@ where
                         &mut tokio::io::sink(),
                         |vdom| {
                             Box::pin(async move {
-                                let _ = vdom.rebuild();
+                                vdom.rebuild_in_place();
                                 vdom.wait_for_suspense().await;
                             })
                         },
@@ -87,13 +87,21 @@ where
     <Rt as FromStr>::Err: std::fmt::Display,
     W: tokio::io::AsyncWrite + Unpin + Send,
 {
-    #[component]
-    fn RenderPath<R>(path: R) -> Element
+    #[derive(Clone)]
+    struct RootProps<Rt>(Rt);
+
+    impl<Rt> PartialEq for RootProps<Rt> {
+        fn eq(&self, _: &Self) -> bool {
+            true
+        }
+    }
+
+    fn RenderPath<R>(props: RootProps<R>) -> Element
     where
         R: Routable,
         <R as FromStr>::Err: std::fmt::Display,
     {
-        let path = path.clone();
+        let path = props.0;
         rsx! {
             Router::<R> {
                 config: || RouterConfig::default().history(MemoryHistory::with_initial_path(path))
@@ -104,8 +112,7 @@ where
     renderer
         .render(
             route.to_string(),
-            RenderPath,
-            RenderPathProps { path: route },
+            || VirtualDom::new_with_props(RenderPath, RootProps(route)),
             writer,
             modify_vdom,
             wrapper,

+ 1 - 1
packages/router/src/router_cfg.rs

@@ -54,7 +54,7 @@ macro_rules! default_history {
             return Box::new(AnyHistoryProviderImplWrapper::new(WebHistory::<R>::default()));
             // If we are using dioxus fullstack and the ssr feature is enabled, use the memory history with the initial path set to the current path in fullstack
             #[cfg(all(feature = "fullstack", feature = "ssr"))]
-            return dioxus_router::prelude::MemoryHistory::with_initial_path(
+            return MemoryHistory::with_initial_path(
                 dioxus_fullstack::prelude::server_context()
                     .request_parts()
                     .unwrap()