* [yew-devel] [RFC PATCH yew-widget-toolkit] catalog loader: defer first content rendering after language is loaded
@ 2025-10-29 14:36 Dominik Csapak
0 siblings, 0 replies; only message in thread
From: Dominik Csapak @ 2025-10-29 14:36 UTC (permalink / raw)
To: yew-devel
Currently, whenever the catalog loader tries to load a language, it
will empty out the content once, iow. render an empty body and then the
actual content again. This means that all sub components are recreated
and lose their state.
When changing between languages this is necessary, since otherwise
already rendered text will not be rerendered with the new language.
On first page load on the other hand, rendering once in the default
language and then immediately in the target language (even if it's also
the default language) does not make much sense, since
* most of the time the language catalog is rather small
(e.g. pdm german mo file is ~75KiB), so the initial rendering is immediately
lost and rerendered
* even if the language would take longer to load, displaying it for a
relatively short time in the wrong language is not helpful.
* doing anything in a 'create' method of components that should only run
once, cannot be done in a way that retains some info about it. For
example the PMG mobile gui that tries to do some action from the GET
parameters, but only once (including removing the GET parameters).
That can work, but we can't show any popup/snackbar then since the
language loaded in the meantime and we have no knowledge that we did
such an action.
To fix this, render nothing until any language was at least loaded once.
On our older ExtJS GUIs, the server determines the language with a
cookie and the index has the link in the <head> section of the html.
This will block the javascript execution until that loaded, so this
solution here mimics the behavior on our ExtJS GUIs.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/widget/catalog_loader.rs | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/widget/catalog_loader.rs b/src/widget/catalog_loader.rs
index b346838..c32619d 100644
--- a/src/widget/catalog_loader.rs
+++ b/src/widget/catalog_loader.rs
@@ -79,6 +79,7 @@ pub struct PwtCatalogLoader {
lang: String,
last_url: String,
state: LoadState,
+ loaded_once: bool,
}
impl Component for PwtCatalogLoader {
@@ -101,6 +102,7 @@ impl Component for PwtCatalogLoader {
last_url: String::new(),
state: LoadState::Idle,
_observer,
+ loaded_once: false,
}
}
@@ -115,6 +117,7 @@ impl Component for PwtCatalogLoader {
} else {
log::warn!("could not load language info for '{}'", self.lang);
}
+ self.loaded_once = true;
self.state = LoadState::Idle;
true
}
@@ -144,7 +147,7 @@ impl Component for PwtCatalogLoader {
fn view(&self, ctx: &yew::Context<Self>) -> yew::Html {
let props = ctx.props();
- if matches!(self.state, LoadState::LoadFinished(_)) {
+ if !self.loaded_once || matches!(self.state, LoadState::LoadFinished(_)) {
html! {}
} else {
html! {props.body.clone()}
--
2.47.3
_______________________________________________
yew-devel mailing list
yew-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-10-29 14:36 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-29 14:36 [yew-devel] [RFC PATCH yew-widget-toolkit] catalog loader: defer first content rendering after language is loaded Dominik Csapak
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.