From db3ce0703001b496abf725c518a4273ee41670fa Mon Sep 17 00:00:00 2001 From: Marc Espin Date: Thu, 19 Jun 2025 01:40:07 +0200 Subject: [PATCH] feat: Opt-out `html` in `dioxus-router` (#4217) * feat: Opt-out `html` in `dioxus-router` * typo: Enable html by default * Fix cargo doc on html --------- Co-authored-by: Jonathan Kelley --- Cargo.toml | 2 +- packages/router/Cargo.toml | 5 +++-- packages/router/src/lib.rs | 11 +++++++++-- packages/router/src/router_cfg.rs | 20 +++++++++++++++++--- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9020ebfd0..a3a04b7fc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -136,7 +136,7 @@ version = "0.7.0-alpha.1" # dependencies that are shared across packages [workspace.dependencies] dioxus = { path = "packages/dioxus", version = "0.7.0-alpha.1" } -dioxus-lib = { path = "packages/dioxus-lib", version = "0.7.0-alpha.1" } +dioxus-lib = { path = "packages/dioxus-lib", version = "0.7.0-alpha.1", default-features = false } dioxus-core = { path = "packages/core", version = "0.7.0-alpha.1" } dioxus-core-types = { path = "packages/core-types", version = "0.7.0-alpha.1" } dioxus-core-macro = { path = "packages/core-macro", version = "0.7.0-alpha.1" } diff --git a/packages/router/Cargo.toml b/packages/router/Cargo.toml index de9f55591..32e8613dd 100644 --- a/packages/router/Cargo.toml +++ b/packages/router/Cargo.toml @@ -10,7 +10,7 @@ homepage = "https://dioxuslabs.com" keywords = ["dom", "ui", "gui", "react", "wasm"] [dependencies] -dioxus-lib = { workspace = true } +dioxus-lib = { workspace = true, default-features = false, features = ["signals", "macro", "hooks"] } dioxus-history = { workspace = true } dioxus-router-macro = { workspace = true } dioxus-fullstack-hooks = { workspace = true, optional = true } @@ -21,9 +21,10 @@ dioxus-cli-config = { workspace = true } rustversion = { workspace = true } [features] -default = [] +default = ["html"] streaming = ["dep:dioxus-fullstack-hooks"] wasm-split = [] +html = ["dioxus-lib/html"] [dev-dependencies] axum = { workspace = true, features = ["ws"] } diff --git a/packages/router/src/lib.rs b/packages/router/src/lib.rs index 470a57939..4a18ade2a 100644 --- a/packages/router/src/lib.rs +++ b/packages/router/src/lib.rs @@ -10,13 +10,19 @@ pub mod routable; /// Components interacting with the router. pub mod components { + #[cfg(feature = "html")] mod default_errors; + #[cfg(feature = "html")] pub use default_errors::*; + #[cfg(feature = "html")] mod history_buttons; + #[cfg(feature = "html")] pub use history_buttons::*; + #[cfg(feature = "html")] mod link; + #[cfg(feature = "html")] pub use link::*; mod outlet; @@ -60,10 +66,11 @@ pub use hooks::router; /// A collection of useful items most applications might need. pub mod prelude { + #[cfg(feature = "html")] pub use crate::components::{ - GoBackButton, GoForwardButton, HistoryButtonProps, Link, LinkProps, Outlet, Router, - RouterProps, + GoBackButton, GoForwardButton, HistoryButtonProps, Link, LinkProps, }; + pub use crate::components::{Outlet, Router, RouterProps}; pub use crate::contexts::*; pub use crate::hooks::*; pub use crate::navigation::*; diff --git a/packages/router/src/router_cfg.rs b/packages/router/src/router_cfg.rs index 78c5a3825..7bf380d9b 100644 --- a/packages/router/src/router_cfg.rs +++ b/packages/router/src/router_cfg.rs @@ -1,4 +1,4 @@ -use crate::{components::FailureExternalNavigation, prelude::*}; +use crate::prelude::*; use dioxus_lib::prelude::*; use std::sync::Arc; @@ -31,10 +31,21 @@ pub struct RouterConfig { pub(crate) on_update: Option>, } +#[cfg(not(feature = "html"))] impl Default for RouterConfig { fn default() -> Self { Self { - failure_external_navigation: FailureExternalNavigation, + failure_external_navigation: || VNode::empty(), + on_update: None, + } + } +} + +#[cfg(feature = "html")] +impl Default for RouterConfig { + fn default() -> Self { + Self { + failure_external_navigation: crate::components::FailureExternalNavigation, on_update: None, } } @@ -69,7 +80,10 @@ where /// A component to render when an external navigation fails. /// - /// Defaults to a router-internal component called [`FailureExternalNavigation`] + #[cfg_attr( + feature = "html", + doc = "Defaults to [`crate::components::FailureExternalNavigation`]." + )] pub fn failure_external_navigation(self, component: fn() -> Element) -> Self { Self { failure_external_navigation: component,