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 <noreply@anthropic.com>
This commit is contained in:
@@ -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-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
|
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
|
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
|
# Profil de compilation WASM optimisé pour réduire la taille du fichier .wasm
|
||||||
# Un fichier WASM plus petit = page qui charge plus vite
|
# Un fichier WASM plus petit = page qui charge plus vite
|
||||||
|
|||||||
@@ -71,7 +71,9 @@ impl ThemeChoice {
|
|||||||
// ─── DOM helpers (WASM only) ─────────────────────────────────────────────────
|
// ─── DOM helpers (WASM only) ─────────────────────────────────────────────────
|
||||||
|
|
||||||
// Reads the stored theme name from localStorage.
|
// 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<ThemeChoice> {
|
fn load_stored_theme() -> Option<ThemeChoice> {
|
||||||
let storage = web_sys::window()?.local_storage().ok()??;
|
let storage = web_sys::window()?.local_storage().ok()??;
|
||||||
let value = storage.get_item(STORAGE_KEY).ok()??;
|
let value = storage.get_item(STORAGE_KEY).ok()??;
|
||||||
@@ -79,7 +81,7 @@ fn load_stored_theme() -> Option<ThemeChoice> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Applies `data-theme` attribute to <html> and persists to localStorage.
|
// Applies `data-theme` attribute to <html> and persists to localStorage.
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(feature = "hydrate")]
|
||||||
fn apply_and_persist(choice: &ThemeChoice) {
|
fn apply_and_persist(choice: &ThemeChoice) {
|
||||||
let Some(window) = web_sys::window() else { return };
|
let Some(window) = web_sys::window() else { return };
|
||||||
let Some(document) = window.document() 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.
|
// Does NOT track `theme`, so it never re-runs after the initial mount.
|
||||||
// Setting the signal here triggers Effect 2 below.
|
// Setting the signal here triggers Effect 2 below.
|
||||||
Effect::new(move |_| {
|
Effect::new(move |_| {
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(feature = "hydrate")]
|
||||||
if let Some(stored) = load_stored_theme() {
|
if let Some(stored) = load_stored_theme() {
|
||||||
theme.set(stored);
|
theme.set(stored);
|
||||||
}
|
}
|
||||||
@@ -118,7 +120,7 @@ pub fn ThemeToggle() -> impl IntoView {
|
|||||||
// whenever the signal changes (both on init and after user clicks).
|
// whenever the signal changes (both on init and after user clicks).
|
||||||
Effect::new(move |_| {
|
Effect::new(move |_| {
|
||||||
let current = theme.get(); // tracked — re-runs when theme changes
|
let current = theme.get(); // tracked — re-runs when theme changes
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(feature = "hydrate")]
|
||||||
apply_and_persist(¤t);
|
apply_and_persist(¤t);
|
||||||
// Suppress unused variable warning when compiling for SSR
|
// Suppress unused variable warning when compiling for SSR
|
||||||
let _ = current;
|
let _ = current;
|
||||||
|
|||||||
Reference in New Issue
Block a user