dioxus icon indicating copy to clipboard operation
dioxus copied to clipboard

RDM加密的Epub文件

Open patrik-cihal opened this issue 9 months ago • 0 comments

Problem

In dioxus when using dx serve without the --release flag, when switching route within a layout, it seems to reload the layout component always. This doesn't happen with --release flag

Environment:

  • Dioxus version: 0.6.3

  • App platform: web

Questionnaire

patrik-cihal avatar Apr 11 '25 12:04 patrik-cihal

This issue looks similar to #3235. Can you provide a reproduction of this issue? I'm unable to reproduce this with the following code adapted from the other issue:

// dioxus = { version = "0.6.3", features = ["web", "router"] }
// tracing = "0.1.41"
use dioxus::prelude::*;

fn main() {
    dioxus::launch(|| {
        rsx! {
            Router::<Route> {}
        }
    });
}

// Turn off rustfmt since we're doing layouts and routes in the same enum
#[derive(Routable, Clone, Debug, PartialEq)]
#[rustfmt::skip]
enum Route {
    // Wrap Home in a Navbar Layout
    #[layout(NavBar)]
        // The default route is always "/" unless otherwise specified
        #[route("/")]
        Home {},

        // Wrap the next routes in a layout and a nest
        #[nest("/blog")]
        #[layout(Blog)]
            // At "/blog", we want to show a list of blog posts
            #[route("/")]
            BlogList {},

            // At "/blog/:name", we want to show a specific blog post, using the name slug
            #[route("/:name")]
            BlogPost { name: String },

        // We need to end the blog layout and nest
        // Note we don't need either - we could've just done `/blog/` and `/blog/:name` without nesting,
        // but it's a bit cleaner this way
        #[end_layout]
        #[end_nest]

    // And the regular page layout
    #[end_layout]

    // Add some redirects for the `/myblog` route
    #[nest("/myblog")]
        #[redirect("/", || Route::BlogList {})]
        #[redirect("/:name", |name: String| Route::BlogPost { name })]
    #[end_nest]

    // Finally, we need to handle the 404 page
    #[route("/:..route")]
    PageNotFound {
        route: Vec<String>,
    },
}

#[component]
fn NavBar() -> Element {
    tracing::info!("This may rerun");
    use_hook(|| tracing::info!("This should only run once"));
    rsx! {
        nav { id: "navbar",
            Link { to: Route::Home {}, "Home" }
            Link { to: Route::BlogList {}, "Blog" }
        }
        Outlet::<Route> {}
    }
}

#[component]
fn Home() -> Element {
    rsx! { h1 { "Welcome to the Dioxus Blog!" } }
}

#[component]
fn Blog() -> Element {
    rsx! {
        h1 { "Blog" }
        Outlet::<Route> {}
    }
}

#[component]
fn BlogList() -> Element {
    rsx! {
        h2 { "Choose a post" }
        div { id: "blog-list",
            Link { to: Route::BlogPost { name: "Blog post 1".into() },
                "Read the first blog post"
            }
            Link { to: Route::BlogPost { name: "Blog post 2".into() },
                "Read the second blog post"
            }
        }
    }
}

// We can use the `name` slug to show a specific blog post
// In theory we could read from the filesystem or a database here
#[component]
fn BlogPost(name: String) -> Element {
    let contents = match name.as_str() {
        "Blog post 1" => "This is the first blog post. It's not very interesting.",
        "Blog post 2" => "This is the second blog post. It's not very interesting either.",
        _ => "This blog post doesn't exist.",
    };

    rsx! {
        h2 { "{name}" }
        p { "{contents}" }
    }
}

#[component]
fn PageNotFound(route: Vec<String>) -> Element {
    rsx! {
        h1 { "Page not found" }
        p { "We are terribly sorry, but the page you requested doesn't exist." }
        pre { color: "red", "log:\nattemped to navigate to: {route:?}" }
    }
}

This should only run once is only logged once at the start.

ealmloff avatar Apr 21 '25 16:04 ealmloff

Sry don't really have time to set up a full reproducible example but here is part of my layout and the thing inside the hook runs every time i change route by clicking on the link. Maybe that can help.

pub fn Navbar(session_info: Resource<SessionInfo>) -> Element {
    let current_route = use_route();
    let mut navbar_level = use_context::<Signal<NavbarLevel>>();
    use_hook(move || {
        info!("This should run only once");
    });

    rsx! {
        nav {
            class: "fixed bottom-7 left-1/2 -translate-x-1/2 z-50 bg-base-200/70 backdrop-blur-sm navbar rounded-3xl shadow-lg px-4 w-4/5 max-w-[400px] h-[50px]",
            ul {
                class: "menu menu-horizontal gap-4 w-full justify-center",
                li {
                    Link {
                        onclick: move |_| {
                            navbar_level.set(NavbarLevel::Page);
                        },
                        to: if let Route::Discover { chat_id } = current_route { Route::Discover { chat_id} } else { Route::DiscoverEmpty {} },

patrik-cihal avatar Apr 21 '25 17:04 patrik-cihal

It's just weird that in --release it works flawlessly.

patrik-cihal avatar Apr 21 '25 17:04 patrik-cihal

Here is the full Route component.

#[derive(Debug, Clone, Routable, PartialEq)]
#[rustfmt::skip]
enum Route {
    #[layout(Layout2)]
    #[route("/")]
    Home {},
    #[route("/discover")]
    DiscoverEmpty {},
    #[route("/discover/:chat_id")]
    Discover { chat_id: Uuid },
    #[route("/item/:id")]
    Inspect { id: Uuid },
    #[route("/join")]
    Join,
    #[route("/welcome")]
    Welcome,
    #[route("/favorites")]
    Favorites,
    #[route("/referral/:id")]
    Referral { id: Uuid },
    #[route("/privacy_policy")]
    PrivacyPolicy,
    #[route("/about")]
    About,
    #[route("/terms")]
    Terms,
    #[route("/account")]
    Account,
    #[route("/analytics")]
    Analytics {},
}

patrik-cihal avatar Apr 21 '25 17:04 patrik-cihal