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:
@@ -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<ThemeChoice> {
|
||||
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<ThemeChoice> {
|
||||
}
|
||||
|
||||
// Applies `data-theme` attribute to <html> 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;
|
||||
|
||||
Reference in New Issue
Block a user