From 681792b13e9697ddac1b4f27b8712ef8eafc7c26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Tue, 12 Mar 2024 02:26:35 +0100 Subject: [PATCH] Fixed SSR detection from an url query parameter for `use_color_mode` --- CHANGELOG.md | 6 ++++++ src/core/url.rs | 11 +++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f88f8f4..51332cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fix 🍕 + +- Fixed SSR detection from an url query parameter for `use_color_mode`. + ## [0.10.4] - 2024-03-05 ### New Functions 🚀 diff --git a/src/core/url.rs b/src/core/url.rs index bddd7a9..efb4bc3 100644 --- a/src/core/url.rs +++ b/src/core/url.rs @@ -1,5 +1,6 @@ use leptos::window; +#[cfg_attr(feature = "ssr", allow(dead_code))] fn get() -> web_sys::Url { web_sys::Url::new( &window() @@ -11,10 +12,16 @@ fn get() -> web_sys::Url { } pub mod params { - use super::get as current_url; + use cfg_if::cfg_if; /// Get a URL param value from the URL of the browser pub fn get(k: &str) -> Option { - current_url().search_params().get(k) + cfg_if! { if #[cfg(feature = "ssr")] { + _ = k; + None + } else { + use super::get as current_url; + current_url().search_params().get(k) + }} } }