From 30dd1ad0b0dfef4d31c1797d0882c81bc5528904 Mon Sep 17 00:00:00 2001 From: mathieu Date: Sat, 16 May 2026 01:25:10 +0200 Subject: [PATCH] fix(config): wire cargo-leptos features and CSS source file - Add bin-features/lib-features so cargo-leptos enables ssr/hydrate correctly (server was exiting immediately with empty main otherwise) - Add style-file so the CSS bundle is no longer empty - Replace #[cfg(target_arch = "wasm32")] with #[cfg(feature = "hydrate")] in theme.rs to match when web-sys is actually available Co-Authored-By: Claude Sonnet 4.6 --- Cargo.toml | 4 ++++ src/client/theme.rs | 10 ++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a36398e..d482afa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -91,6 +91,10 @@ site-root = "target/site" # Dossier racine des fichiers compilés par trunk site-pkg-dir = "pkg" # Sous-dossier des assets WASM/JS dans site-root site-addr = "127.0.0.1:3000" # Adresse d'écoute du serveur Axum reload-port = 3001 # Port WebSocket pour le hot-reload en développement +style-file = "style/rust-ipam.css" # Source CSS compilé dans pkg/rust-ipam.css +# Features activées par cargo-leptos lors du build +bin-features = ["ssr"] # SSR binary (Axum server) +lib-features = ["hydrate"] # WASM bundle (browser) # Profil de compilation WASM optimisé pour réduire la taille du fichier .wasm # Un fichier WASM plus petit = page qui charge plus vite diff --git a/src/client/theme.rs b/src/client/theme.rs index 960578f..ff71897 100644 --- a/src/client/theme.rs +++ b/src/client/theme.rs @@ -71,7 +71,9 @@ impl ThemeChoice { // ─── DOM helpers (WASM only) ───────────────────────────────────────────────── // Reads the stored theme name from localStorage. -#[cfg(target_arch = "wasm32")] +// Guard on `hydrate` feature rather than `target_arch` because web-sys is +// only activated by that feature in Cargo.toml. +#[cfg(feature = "hydrate")] fn load_stored_theme() -> Option { let storage = web_sys::window()?.local_storage().ok()??; let value = storage.get_item(STORAGE_KEY).ok()??; @@ -79,7 +81,7 @@ fn load_stored_theme() -> Option { } // Applies `data-theme` attribute to and persists to localStorage. -#[cfg(target_arch = "wasm32")] +#[cfg(feature = "hydrate")] fn apply_and_persist(choice: &ThemeChoice) { let Some(window) = web_sys::window() else { return }; let Some(document) = window.document() else { return }; @@ -108,7 +110,7 @@ pub fn ThemeToggle() -> impl IntoView { // Does NOT track `theme`, so it never re-runs after the initial mount. // Setting the signal here triggers Effect 2 below. Effect::new(move |_| { - #[cfg(target_arch = "wasm32")] + #[cfg(feature = "hydrate")] if let Some(stored) = load_stored_theme() { theme.set(stored); } @@ -118,7 +120,7 @@ pub fn ThemeToggle() -> impl IntoView { // whenever the signal changes (both on init and after user clicks). Effect::new(move |_| { let current = theme.get(); // tracked — re-runs when theme changes - #[cfg(target_arch = "wasm32")] + #[cfg(feature = "hydrate")] apply_and_persist(¤t); // Suppress unused variable warning when compiling for SSR let _ = current;