From ca3aab000633dc358f5ea07d999bd133853e2109 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Thu, 25 Dec 2025 22:08:22 +0100 Subject: [PATCH 1/8] Don't re-render on hydration when discovering from URL param --- README.md | 4 -- book/src/install.md | 3 -- examples/ssr-hydrate-actix/Cargo.toml | 1 - examples/ssr-hydrate-axum/Cargo.toml | 2 +- leptos-fluent-macros/Cargo.toml | 1 - leptos-fluent-macros/src/exprpath.rs | 2 - leptos-fluent-macros/src/lib.rs | 42 +++++++------------ leptos-fluent/Cargo.toml | 1 - leptos-fluent/README.md | 3 -- leptos-fluent/src/lib.rs | 3 -- .../Cargo.toml | 2 +- .../Cargo.toml | 1 - .../Cargo.toml | 2 +- .../Cargo.toml | 1 - .../Cargo.toml | 2 +- .../Cargo.toml | 1 - 16 files changed, 19 insertions(+), 52 deletions(-) diff --git a/README.md b/README.md index 139670bf..46d14141 100644 --- a/README.md +++ b/README.md @@ -25,9 +25,6 @@ leptos-fluent = "0.2" axum = { version = "0.8", optional = true } [features] -hydrate = [ - "leptos-fluent/hydrate", -] ssr = [ "leptos-fluent/ssr", "leptos-fluent/axum", # actix and axum are supported @@ -232,7 +229,6 @@ fn LanguageSelector() -> impl IntoView { ### Features - **Server Side Rendering**: `ssr` -- **Hydration**: `hydrate` - **Actix Web integration**: `actix` - **Axum integration**: `axum` - **Nightly toolchain**: `nightly` diff --git a/book/src/install.md b/book/src/install.md index d90b457f..1ce27166 100644 --- a/book/src/install.md +++ b/book/src/install.md @@ -25,9 +25,6 @@ leptos-fluent = "0.2" axum = { version = "0.8", optional = true } [features] -hydrate = [ - "leptos-fluent/hydrate", -] ssr = [ "leptos-fluent/ssr", "leptos-fluent/axum", # actix and axum are supported diff --git a/examples/ssr-hydrate-actix/Cargo.toml b/examples/ssr-hydrate-actix/Cargo.toml index 653f68d1..9f067430 100644 --- a/examples/ssr-hydrate-actix/Cargo.toml +++ b/examples/ssr-hydrate-actix/Cargo.toml @@ -21,7 +21,6 @@ wasm-bindgen.workspace = true [features] hydrate = [ "leptos/hydrate", - "leptos-fluent/hydrate", ] ssr = [ "dep:actix-files", diff --git a/examples/ssr-hydrate-axum/Cargo.toml b/examples/ssr-hydrate-axum/Cargo.toml index 86602255..d12ff9aa 100644 --- a/examples/ssr-hydrate-axum/Cargo.toml +++ b/examples/ssr-hydrate-axum/Cargo.toml @@ -27,7 +27,7 @@ wasm-bindgen.workspace = true [features] csr = ["leptos/csr"] -hydrate = ["leptos/hydrate", "leptos-fluent/hydrate"] +hydrate = ["leptos/hydrate"] ssr = [ "dep:axum", "dep:tokio", diff --git a/leptos-fluent-macros/Cargo.toml b/leptos-fluent-macros/Cargo.toml index 23e6a4cb..28242448 100644 --- a/leptos-fluent-macros/Cargo.toml +++ b/leptos-fluent-macros/Cargo.toml @@ -51,7 +51,6 @@ leptos-fluent.workspace = true nightly = ["proc-macro2/span-locations"] system = [] tracing = ["dep:tracing"] -hydrate = [] ssr = [] actix = [] axum = [] diff --git a/leptos-fluent-macros/src/exprpath.rs b/leptos-fluent-macros/src/exprpath.rs index 197122df..36f53ae9 100644 --- a/leptos-fluent-macros/src/exprpath.rs +++ b/leptos-fluent-macros/src/exprpath.rs @@ -39,8 +39,6 @@ pub(crate) fn evaluate_exprpath( cfg!(feature = "nightly") } else if *f == "ssr" { cfg!(feature = "ssr") - } else if *f == "hydrate" { - cfg!(feature = "hydrate") } else if *f == "system" { cfg!(feature = "system") } else if *f == "tracing" { diff --git a/leptos-fluent-macros/src/lib.rs b/leptos-fluent-macros/src/lib.rs index a11fff4a..65932564 100644 --- a/leptos-fluent-macros/src/lib.rs +++ b/leptos-fluent-macros/src/lib.rs @@ -334,18 +334,19 @@ pub fn leptos_fluent( None => quote! { "" }, }; - // TODO: optimize checking if empty at compile time when literal - let effect_quote = quote! { - ::leptos::prelude::Effect::new(move |_| { - if #set_language_to_data_file_quote.is_empty() { - return; + let effect_quote = + if set_language_to_data_file_quote.to_string() == "\"\"" { + quote! {} + } else { + quote! { + ::leptos::prelude::Effect::new(move |_| { + ::leptos_fluent::data_file::set( + #set_language_to_data_file_quote, + &#get_language_quote.id.to_string(), + ); + }); } - ::leptos_fluent::data_file::set( - #set_language_to_data_file_quote, - &#get_language_quote.id.to_string(), - ); - }); - }; + }; match param.expr { Some(ref expr) => { @@ -379,10 +380,10 @@ pub fn leptos_fluent( None => quote! { "" }, }; + if initial_language_from_data_file_quote.to_string() == "\"\"" { + return quote! {}; + } let effect_quote = quote! { - if #initial_language_from_data_file_quote.is_empty() { - return; - } if let Some(l) = ::leptos_fluent::data_file::get( #initial_language_from_data_file_quote ) { @@ -831,18 +832,6 @@ pub fn leptos_fluent( let sync_language_with_session_storage_quote = quote!(); let initial_language_from_url_param_quote: proc_macro2::TokenStream = { - #[cfg(all(feature = "hydrate", not(feature = "ssr")))] - let hydrate_rerender_quote = quote! { - ::leptos::prelude::Effect::new(move |prev: Option<()>| { - if prev.is_none() { - #set_language_quote; - } - }); - }; - - #[cfg(all(not(feature = "hydrate"), not(feature = "ssr")))] - let hydrate_rerender_quote = quote! {}; - #[cfg(not(feature = "ssr"))] let set_to_local_storage_quote: proc_macro2::TokenStream = { let effect_quote = quote! { @@ -947,7 +936,6 @@ pub fn leptos_fluent( if let Some(l) = ::leptos_fluent::url::param::get(#url_param_quote) { lang = ::leptos_fluent::l(&l, &LANGUAGES); if let Some(l) = lang { - #hydrate_rerender_quote #set_to_local_storage_quote #set_to_session_storage_quote #set_to_cookie_quote diff --git a/leptos-fluent/Cargo.toml b/leptos-fluent/Cargo.toml index 5383a2e1..17539db5 100644 --- a/leptos-fluent/Cargo.toml +++ b/leptos-fluent/Cargo.toml @@ -41,7 +41,6 @@ system = [ ] nightly = ["leptos-fluent-macros/nightly"] tracing = ["leptos-fluent-macros/tracing", "dep:tracing"] -hydrate = ["leptos-fluent-macros/hydrate"] ssr = ["leptos-fluent-macros/ssr"] actix = ["leptos-fluent-macros/actix"] axum = ["leptos-fluent-macros/axum"] diff --git a/leptos-fluent/README.md b/leptos-fluent/README.md index 139670bf..c75fc655 100644 --- a/leptos-fluent/README.md +++ b/leptos-fluent/README.md @@ -25,9 +25,6 @@ leptos-fluent = "0.2" axum = { version = "0.8", optional = true } [features] -hydrate = [ - "leptos-fluent/hydrate", -] ssr = [ "leptos-fluent/ssr", "leptos-fluent/axum", # actix and axum are supported diff --git a/leptos-fluent/src/lib.rs b/leptos-fluent/src/lib.rs index 5b45d1fe..59adcefb 100644 --- a/leptos-fluent/src/lib.rs +++ b/leptos-fluent/src/lib.rs @@ -24,9 +24,6 @@ //! axum = { version = "0.8", optional = true } //! //! [features] -//! hydrate = [ -//! "leptos-fluent/hydrate", -//! ] //! ssr = [ //! "leptos-fluent/ssr", //! "leptos-fluent/axum", # actix and axum are supported diff --git a/tests/end2end/ssr/src/apps/initial_language_from_accept_language_header_actix/Cargo.toml b/tests/end2end/ssr/src/apps/initial_language_from_accept_language_header_actix/Cargo.toml index 37a87689..9f1b093f 100644 --- a/tests/end2end/ssr/src/apps/initial_language_from_accept_language_header_actix/Cargo.toml +++ b/tests/end2end/ssr/src/apps/initial_language_from_accept_language_header_actix/Cargo.toml @@ -21,7 +21,7 @@ app-helpers = { path = "../../app-helpers" } [features] csr = ["leptos/csr"] -hydrate = ["leptos/hydrate", "leptos-fluent/hydrate"] +hydrate = ["leptos/hydrate"] ssr = [ "dep:actix-files", "dep:actix-web", diff --git a/tests/end2end/ssr/src/apps/initial_language_from_accept_language_header_axum/Cargo.toml b/tests/end2end/ssr/src/apps/initial_language_from_accept_language_header_axum/Cargo.toml index 3d942a9f..e66da8c0 100644 --- a/tests/end2end/ssr/src/apps/initial_language_from_accept_language_header_axum/Cargo.toml +++ b/tests/end2end/ssr/src/apps/initial_language_from_accept_language_header_axum/Cargo.toml @@ -23,7 +23,6 @@ hydrate = [ "leptos/hydrate", "dep:console_error_panic_hook", "dep:wasm-bindgen", - "leptos-fluent/hydrate", ] ssr = [ "dep:axum", diff --git a/tests/end2end/ssr/src/apps/initial_language_from_cookie_actix/Cargo.toml b/tests/end2end/ssr/src/apps/initial_language_from_cookie_actix/Cargo.toml index 61b25009..1dca267d 100644 --- a/tests/end2end/ssr/src/apps/initial_language_from_cookie_actix/Cargo.toml +++ b/tests/end2end/ssr/src/apps/initial_language_from_cookie_actix/Cargo.toml @@ -21,7 +21,7 @@ app-helpers = { path = "../../app-helpers" } [features] csr = ["leptos/csr"] -hydrate = ["leptos/hydrate", "leptos-fluent/hydrate"] +hydrate = ["leptos/hydrate"] ssr = [ "dep:actix-files", "dep:actix-web", diff --git a/tests/end2end/ssr/src/apps/initial_language_from_cookie_axum/Cargo.toml b/tests/end2end/ssr/src/apps/initial_language_from_cookie_axum/Cargo.toml index cf765e8a..ba7e2cad 100644 --- a/tests/end2end/ssr/src/apps/initial_language_from_cookie_axum/Cargo.toml +++ b/tests/end2end/ssr/src/apps/initial_language_from_cookie_axum/Cargo.toml @@ -23,7 +23,6 @@ hydrate = [ "leptos/hydrate", "dep:console_error_panic_hook", "dep:wasm-bindgen", - "leptos-fluent/hydrate", ] ssr = [ "dep:axum", diff --git a/tests/end2end/ssr/src/apps/initial_language_from_url_param_actix/Cargo.toml b/tests/end2end/ssr/src/apps/initial_language_from_url_param_actix/Cargo.toml index 4f8a04cc..372158b4 100644 --- a/tests/end2end/ssr/src/apps/initial_language_from_url_param_actix/Cargo.toml +++ b/tests/end2end/ssr/src/apps/initial_language_from_url_param_actix/Cargo.toml @@ -21,7 +21,7 @@ app-helpers = { path = "../../app-helpers" } [features] csr = ["leptos/csr"] -hydrate = ["leptos/hydrate", "leptos-fluent/hydrate"] +hydrate = ["leptos/hydrate"] ssr = [ "dep:actix-files", "dep:actix-web", diff --git a/tests/end2end/ssr/src/apps/initial_language_from_url_param_axum/Cargo.toml b/tests/end2end/ssr/src/apps/initial_language_from_url_param_axum/Cargo.toml index 0cd2fbc3..dfda7391 100644 --- a/tests/end2end/ssr/src/apps/initial_language_from_url_param_axum/Cargo.toml +++ b/tests/end2end/ssr/src/apps/initial_language_from_url_param_axum/Cargo.toml @@ -23,7 +23,6 @@ hydrate = [ "leptos/hydrate", "dep:console_error_panic_hook", "dep:wasm-bindgen", - "leptos-fluent/hydrate", ] ssr = [ "dep:axum", From 390a9f2eed572e695954ddda76edcfc00afcd871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Thu, 25 Dec 2025 22:12:37 +0100 Subject: [PATCH 2/8] Fix test --- .../nightly/pass/check_translations_cfg_feature.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/leptos-fluent-macros/tests/ui/leptos_fluent/nightly/pass/check_translations_cfg_feature.rs b/leptos-fluent-macros/tests/ui/leptos_fluent/nightly/pass/check_translations_cfg_feature.rs index 92e23e3a..cda3236e 100644 --- a/leptos-fluent-macros/tests/ui/leptos_fluent/nightly/pass/check_translations_cfg_feature.rs +++ b/leptos-fluent-macros/tests/ui/leptos_fluent/nightly/pass/check_translations_cfg_feature.rs @@ -18,7 +18,7 @@ fn I18n(children: Children) -> impl IntoView { locales: "../../../../examples/csr-minimal/locales", #[cfg(feature = "ssr")] check_translations: "../../../../leptos-fluent-macros/tests/ui/leptos_fluent/fail/check_translations_cfg_feature.rs", - #[cfg(all(not(feature = "ssr"), feature = "hydrate"))] + #[cfg(all(not(feature = "ssr")))] check_translations: "../../../../leptos-fluent-macros/tests/ui/leptos_fluent/fail/check_translations_cfg_feature.rs", } } From 116eec8946749bc98797d3bfcc35cd5ed3828fca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Thu, 25 Dec 2025 22:32:14 +0100 Subject: [PATCH 3/8] Update docs --- book/src/install.md | 4 +--- leptos-fluent/README.md | 1 - leptos-fluent/src/lib.rs | 1 - 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/book/src/install.md b/book/src/install.md index 1ce27166..c7d8d53c 100644 --- a/book/src/install.md +++ b/book/src/install.md @@ -16,8 +16,7 @@ leptos-fluent = "0.2" ## SSR For server side rendering apps install **leptos-fluent** and enable -the `hydrate`, `ssr` and `actix`/`axum` features in their respective -features set. +`ssr` and `actix` / `axum` features in their respective features set. ```toml [dependencies] @@ -50,7 +49,6 @@ leptos-fluent = { version = "0.2", features = ["system"] } ## Features - **Server Side Rendering**: `ssr` -- **Hydration**: `hydrate` - **Actix Web integration**: `actix` - **Axum integration**: `axum` - **Nightly toolchain**: `nightly` diff --git a/leptos-fluent/README.md b/leptos-fluent/README.md index c75fc655..46d14141 100644 --- a/leptos-fluent/README.md +++ b/leptos-fluent/README.md @@ -229,7 +229,6 @@ fn LanguageSelector() -> impl IntoView { ### Features - **Server Side Rendering**: `ssr` -- **Hydration**: `hydrate` - **Actix Web integration**: `actix` - **Axum integration**: `axum` - **Nightly toolchain**: `nightly` diff --git a/leptos-fluent/src/lib.rs b/leptos-fluent/src/lib.rs index 59adcefb..8dc300d6 100644 --- a/leptos-fluent/src/lib.rs +++ b/leptos-fluent/src/lib.rs @@ -228,7 +228,6 @@ //! ## Features //! //! - **Server Side Rendering**: `ssr` -//! - **Hydration**: `hydrate` //! - **Actix Web integration**: `actix` //! - **Axum integration**: `axum` //! - **Nightly toolchain**: `nightly` From 52935dbf4cc3dffcbfeb8a6f34084f5d6ee4ca2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Thu, 25 Dec 2025 22:36:22 +0100 Subject: [PATCH 4/8] Fix test --- .../nightly/pass/check_translations_cfg_feature.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/leptos-fluent-macros/tests/ui/leptos_fluent/nightly/pass/check_translations_cfg_feature.rs b/leptos-fluent-macros/tests/ui/leptos_fluent/nightly/pass/check_translations_cfg_feature.rs index cda3236e..7b24ddd6 100644 --- a/leptos-fluent-macros/tests/ui/leptos_fluent/nightly/pass/check_translations_cfg_feature.rs +++ b/leptos-fluent-macros/tests/ui/leptos_fluent/nightly/pass/check_translations_cfg_feature.rs @@ -18,7 +18,7 @@ fn I18n(children: Children) -> impl IntoView { locales: "../../../../examples/csr-minimal/locales", #[cfg(feature = "ssr")] check_translations: "../../../../leptos-fluent-macros/tests/ui/leptos_fluent/fail/check_translations_cfg_feature.rs", - #[cfg(all(not(feature = "ssr")))] + #[cfg(all(not(feature = "ssr"), debug_assertions))] check_translations: "../../../../leptos-fluent-macros/tests/ui/leptos_fluent/fail/check_translations_cfg_feature.rs", } } From d73d6bc0f57717fdcd351d3c40e84112b487a052 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Thu, 25 Dec 2025 22:41:59 +0100 Subject: [PATCH 5/8] Try fix --- .../nightly/pass/check_translations_cfg_feature.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/leptos-fluent-macros/tests/ui/leptos_fluent/nightly/pass/check_translations_cfg_feature.rs b/leptos-fluent-macros/tests/ui/leptos_fluent/nightly/pass/check_translations_cfg_feature.rs index 7b24ddd6..cc437faf 100644 --- a/leptos-fluent-macros/tests/ui/leptos_fluent/nightly/pass/check_translations_cfg_feature.rs +++ b/leptos-fluent-macros/tests/ui/leptos_fluent/nightly/pass/check_translations_cfg_feature.rs @@ -18,7 +18,7 @@ fn I18n(children: Children) -> impl IntoView { locales: "../../../../examples/csr-minimal/locales", #[cfg(feature = "ssr")] check_translations: "../../../../leptos-fluent-macros/tests/ui/leptos_fluent/fail/check_translations_cfg_feature.rs", - #[cfg(all(not(feature = "ssr"), debug_assertions))] + #[cfg(all(not(feature = "ssr"), not(debug_assertions)))] check_translations: "../../../../leptos-fluent-macros/tests/ui/leptos_fluent/fail/check_translations_cfg_feature.rs", } } From 34625e11f13af1a89c7b89be2c87319fba97865b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Thu, 25 Dec 2025 22:42:42 +0100 Subject: [PATCH 6/8] Remove hook --- .pre-commit-config.yaml | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8367fd8c..2441095c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -55,30 +55,6 @@ repos: -A, deprecated, ] - - id: clippy - alias: clippy-hydrate - name: clippy-hydrate - args: - [ - --features=hydrate, - --exclude=leptos-fluent-ssr-hydrate-axum-example, - --workspace, - --, - -D, - warnings, - -D, - clippy::perf, - -D, - clippy::print_stdout, - -D, - clippy::explicit_iter_loop, - -D, - clippy::uninlined_format_args, - -D, - clippy::semicolon_if_nothing_returned, - -A, - deprecated, - ] - repo: https://github.com/mondeja/rust-pc-hooks rev: v1.3.0 hooks: From c807153eb069ede66c0eccb18456177c790bd48f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Thu, 25 Dec 2025 22:48:10 +0100 Subject: [PATCH 7/8] Fix error --- leptos-fluent-macros/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/leptos-fluent-macros/src/lib.rs b/leptos-fluent-macros/src/lib.rs index 7fca665e..548a1313 100644 --- a/leptos-fluent-macros/src/lib.rs +++ b/leptos-fluent-macros/src/lib.rs @@ -2172,7 +2172,6 @@ pub fn leptos_fluent( #customise_quote }; } - #warnings_quote }, quote!(vec![&TRS]), ) From e5b64ef841eea1ce2a3453e096a023c50fa9fc9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar=20Rubio?= Date: Thu, 25 Dec 2025 23:02:19 +0100 Subject: [PATCH 8/8] Fix error --- leptos-fluent-macros/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/leptos-fluent-macros/Cargo.toml b/leptos-fluent-macros/Cargo.toml index f2196e90..9d46a7cd 100644 --- a/leptos-fluent-macros/Cargo.toml +++ b/leptos-fluent-macros/Cargo.toml @@ -40,7 +40,6 @@ serde_json = { version = "1", optional = true } serde_yaml = { version = "0.9", optional = true } json5 = { version = "0.4", optional = true } tracing = { version = "0.1", optional = true } -proc-macro-warning = "1" [dev-dependencies] trybuild = "1"