DioxusLabs / DioxusLabs/dioxus
`get_client_rect().await` never completes on Ubuntu/Desktop
- Dominant language
- Rust
- Stars
- 39.1k
- Forks
- 1.9k
- Avg merge
- 4d 10h
- Merged PRs (30d)
- 4
Description
**Problem**
`get_client_rect().await` never completes.
May be related to issues #2293 and/or #2240 (?)
I need to access the viewport (which I think is equivalent to its client_rect) of an SVG component in order to handle scaling and translating between world drawing coordinates and screen coordinates. This is for responding to mouse drag and mouse wheel events for zooming and panning.
I am calling `handle.get_client_rect().await`, where `handle` is a handle to the element and is of type `Rc`
I have tried a number of different approaches to triggering the retrieval of the client rect and caching it's size in a signal including
- spawning a separate thread to retrieve it
- calling a helper retrieval function
- enclosing it in a `use_future` as shown below.
In all cases there is always a call to `get_client_rect().await` which never resolves.
**Steps To Reproduce**
This is just a snippet of one approach I used that failed:
```rust
// This runs continuously and automatically checks layout metrics whenever `this_element` changes.
let _layout_fetcher = use_future(move || async move {
// Look for the node handle to become available
if let Some(handle) = this_element.read().clone() {
info!("use_future: Found element handle. Querying layout dimensions...");
// This will now unblock and execute perfectly on Linux Desktop!
if let Ok(rect) = handle.get_client_rect().await {
info!("use_future: Successfully retrieved rect: {:?}", rect); // <-- Never reaches this point
let w = rect.width();
let h = rect.height();
cached_viewport_size.set(Size2D::::new(w, h));
}
}
});
```
This was another approach that failed:
```rust
// --- REUSABLE MEASUREMENT FUNCTION ---
let mut update_viewport_size = move || {
if let Some(handle) = this_element.read().clone() {
spawn(async move {
if let Ok(rect) = handle.get_client_rect().await { // <- Never gets past this line
let w = rect.width();
let h = rect.height();
cached_viewport_size.set(Size2D::::new(w, h));
}
});
}
};
```
**Comments from Google AI (for whatever its worth)**
> "Since get_client_rect().await causes thread deadlocks on Linux under dioxus-desktop, you cannot use it. However, because Dioxus desktop operates inside a system webview, you can completely bypass the broken native Rust bridge by executing a synchronous snippet of JavaScript using the eval feature."
> "Since the native cross-platform get_client_rect().await continues to hang indefinitely due to how WebKitGTK registers asynchronous queries on Linux desktop builds, you should bypass that function entirely."
**Environment:**
- Dioxus version: 0.7.1
- Rust version: rustc 1.97.1
- OS info: Ubuntu 24.04.4 LTS
- App platform: Desktop
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the get_client_rect().await call in a Dioxus desktop app on Ubuntu 24.04. Compare the use_future and spawn approaches shown in the issue, then trace the desktop implementation of this entry point. Done means the awaited client rectangle resolves on Ubuntu Desktop, with behavior matching the working Linux Desktop case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, ubuntu
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100