From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 0BE341FF179 for ; Wed, 29 Oct 2025 15:36:18 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 771E8E043; Wed, 29 Oct 2025 15:36:51 +0100 (CET) From: Dominik Csapak To: yew-devel@lists.proxmox.com Date: Wed, 29 Oct 2025 15:36:10 +0100 Message-ID: <20251029143617.18134-1-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.028 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [yew-devel] [RFC PATCH yew-widget-toolkit] catalog loader: defer first content rendering after language is loaded X-BeenThere: yew-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Yew framework devel list at Proxmox List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Yew framework devel list at Proxmox Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: yew-devel-bounces@lists.proxmox.com Sender: "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 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 --- 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) -> 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