all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: yew-devel@lists.proxmox.com
Subject: [yew-devel] [RFC PATCH yew-widget-toolkit] catalog loader: defer first content rendering after language is loaded
Date: Wed, 29 Oct 2025 15:36:10 +0100	[thread overview]
Message-ID: <20251029143617.18134-1-d.csapak@proxmox.com> (raw)

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


             reply	other threads:[~2025-10-29 14:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-29 14:36 Dominik Csapak [this message]
2025-10-30  7:59 ` [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=20251029143617.18134-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 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.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal