[pdm-devel] [PATCH datacenter-manager 6/6] ui: top nav bar: use an abort guard for loading the version

Shannon Sterz s.sterz at proxmox.com
Thu Nov 27 16:36:09 CET 2025


so that the request gets aborted when the component is destroyed. this
avoids a potential race condition between this request and a potential
log in.

Signed-off-by: Shannon Sterz <s.sterz at proxmox.com>
---
 ui/src/top_nav_bar.rs | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/ui/src/top_nav_bar.rs b/ui/src/top_nav_bar.rs
index 7e2af71..aa6d6cb 100644
--- a/ui/src/top_nav_bar.rs
+++ b/ui/src/top_nav_bar.rs
@@ -7,6 +7,7 @@ use wasm_bindgen::UnwrapThrowExt;

 use pwt::prelude::*;
 use pwt::widget::menu::{Menu, MenuButton, MenuEntry, MenuEvent, MenuItem};
+use pwt::AsyncAbortGuard;
 use yew::html::{IntoEventCallback, IntoPropValue};
 use yew::virtual_dom::{VComp, VNode};

@@ -74,6 +75,7 @@ pub struct PdmTopNavBar {
     dark_mode: bool,
     version_info: Option<VersionInfo>,
     view_state: Option<ViewState>,
+    abort_guard: Option<AsyncAbortGuard>,
 }

 impl Component for PdmTopNavBar {
@@ -95,6 +97,7 @@ impl Component for PdmTopNavBar {
             dark_mode,
             version_info: None,
             view_state: None,
+            abort_guard: None,
         }
     }

@@ -121,8 +124,10 @@ impl Component for PdmTopNavBar {
                 true
             }
             Msg::Load => {
-                ctx.link()
-                    .send_future(async move { Msg::LoadResult(load_version().await) });
+                let link = ctx.link().clone();
+                self.abort_guard.replace(AsyncAbortGuard::spawn(async move {
+                    link.send_message(Msg::LoadResult(load_version().await))
+                }));
                 true
             }
             Msg::LoadResult(result) => {
--
2.47.3





More information about the pdm-devel mailing list