From: Dominik Csapak <d.csapak@proxmox.com>
To: yew-devel@lists.proxmox.com
Subject: [yew-devel] [PATCH yew-widget-toolkit] widget: catalog loader: fix behavior when no language is set
Date: Tue, 4 Nov 2025 13:15:14 +0100 [thread overview]
Message-ID: <20251104121536.2190880-1-d.csapak@proxmox.com> (raw)
Recently, a change in the catalog loader was introduced to defer loading
of the page until after the language was loaded. This worked, except in
the case that no language was set at all, neither via a property nor via
the browser local storage.
When that occurred, there was no attempt to load the catalog but also
the indicator that we're finished with loading was not set, so the child
elements were never displayed.
To fix this, treat an empty language string the same as if it were the
'default_lang', which then triggers the initialization, etc. correctly.
Fixes: 3a437d1 (catalog loader: defer first content rendering after language is loaded)
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/widget/catalog_loader.rs | 62 +++++++++++++++++++-----------------
1 file changed, 32 insertions(+), 30 deletions(-)
diff --git a/src/widget/catalog_loader.rs b/src/widget/catalog_loader.rs
index c32619d..ef53a05 100644
--- a/src/widget/catalog_loader.rs
+++ b/src/widget/catalog_loader.rs
@@ -82,6 +82,16 @@ pub struct PwtCatalogLoader {
loaded_once: bool,
}
+impl PwtCatalogLoader {
+ fn set_language(&mut self, ctx: &yew::Context<Self>, lang: Option<String>, fallback: String) {
+ let mut lang = lang.unwrap_or(fallback);
+ if lang.is_empty() {
+ lang = ctx.props().default_lang.to_string();
+ }
+ self.lang = lang;
+ }
+}
+
impl Component for PwtCatalogLoader {
type Message = Msg;
type Properties = CatalogLoader;
@@ -91,19 +101,17 @@ impl Component for PwtCatalogLoader {
let _observer = LanguageObserver::new(ctx.link().callback(Msg::ChangeLanguage));
- let lang = props
- .lang
- .clone()
- .map(|l| l.to_string())
- .unwrap_or(Language::load());
-
- Self {
- lang,
+ let mut this = Self {
+ lang: String::new(),
last_url: String::new(),
state: LoadState::Idle,
_observer,
loaded_once: false,
- }
+ };
+
+ let lang = props.lang.clone().map(|l| l.to_string());
+ this.set_language(ctx, lang, Language::load());
+ this
}
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
@@ -126,7 +134,7 @@ impl Component for PwtCatalogLoader {
true
}
Msg::ChangeLanguage(lang) => {
- self.lang = props.lang.clone().map(|l| l.to_string()).unwrap_or(lang);
+ self.set_language(ctx, props.lang.clone().map(|l| l.to_string()), lang);
true
}
}
@@ -135,11 +143,8 @@ impl Component for PwtCatalogLoader {
fn changed(&mut self, ctx: &Context<Self>, old_props: &Self::Properties) -> bool {
let props = ctx.props();
if props.lang != old_props.lang {
- self.lang = props
- .lang
- .clone()
- .map(|l| l.to_string())
- .unwrap_or(Language::load());
+ let lang = props.lang.clone().map(|l| l.to_string());
+ self.set_language(ctx, lang, Language::load());
}
true
}
@@ -158,23 +163,20 @@ impl Component for PwtCatalogLoader {
let props = ctx.props();
match &self.state {
LoadState::Idle => {
- if !self.lang.is_empty() {
- let url = props.lang_to_url(&self.lang);
- if self.last_url != url {
- self.state = LoadState::Loading;
- let link = ctx.link().clone();
-
- if self.lang == props.default_lang {
- crate::init_i18n(Catalog::empty());
+ let url = props.lang_to_url(&self.lang);
+
+ if self.last_url != url {
+ self.state = LoadState::Loading;
+ let link = ctx.link().clone();
+
+ if self.lang == props.default_lang {
+ crate::init_i18n(Catalog::empty());
+ link.send_message(Msg::LoadFinished(url));
+ } else {
+ crate::init_i18n_from_url(&url, move |url| {
link.send_message(Msg::LoadFinished(url));
- } else {
- crate::init_i18n_from_url(&url, move |url| {
- link.send_message(Msg::LoadFinished(url));
- });
- }
+ });
}
- } else {
- crate::init_i18n(Catalog::empty());
}
}
LoadState::Loading => { /* wait until loaded */ }
--
2.47.3
_______________________________________________
yew-devel mailing list
yew-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel
next reply other threads:[~2025-11-04 12:15 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-04 12:15 Dominik Csapak [this message]
2025-11-04 12:39 ` [yew-devel] applied: " Dietmar Maurer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251104121536.2190880-1-d.csapak@proxmox.com \
--to=d.csapak@proxmox.com \
--cc=yew-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox