Skip to content

Make new_window asynchronous #4297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 19, 2025

Conversation

ealmloff
Copy link
Member

@ealmloff ealmloff commented Jun 19, 2025

On windows, the main webview thread handles both the IPC handler and creating the webview. We handle events inside of the IPC handler synchronously. Windows prevents the main thread from becoming re-entrant when we try to create a new window synchronously inside of that same thread. Instead we can queue the new window creation for the next time the event loop is called after the IPC handler is done.

This PR is a very similar approach to #3668 with a bit more documentation about why the method needs to be asynchronous.

Closes #3080

Relevant documentation/issues:

@ealmloff ealmloff requested a review from a team as a code owner June 19, 2025 17:01
@ealmloff ealmloff added bug Something isn't working desktop Suggestions related to the desktop renderer windows labels Jun 19, 2025
Copy link
Member

@jkelleyrtp jkelleyrtp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but I'm curious if there's any utility to having PendingDesktopContext instead of just making the method itself async. Cancellation safety?

@ealmloff
Copy link
Member Author

Looks good, but I'm curious if there's any utility to having PendingDesktopContext instead of just making the method itself async. Cancellation safety?

It is pretty common to call new_window synchronously and ignore the resulting context. That is the only way we use the API in our examples. Returning a struct that implements into future instead of using an async method means the work can start immediately even if you don't await the result. You can return impl Future<Output = DesktopContext> with the same behavior, but clippy assumes you must use the future which is not the case:

warning: unused implementer of `futures_util::Future` that must be used
  --> examples/popup.rs:24:9
   |
24 | / ...   dioxus::desktop::window().new_window(
25 | | ...       VirtualDom::new_with_props(popup, Rc::new(move |s| ...
26 | | ...       Default::default(),
27 | | ...   );
   | |_______^
   |
   = note: futures do nothing unless you `.await` or poll them
   = note: `#[warn(unused_must_use)]` on by default

@jkelleyrtp jkelleyrtp merged commit e6ca0ba into DioxusLabs:main Jun 19, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working desktop Suggestions related to the desktop renderer windows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

with “dioxus::desktop::window().new_window()” to create a new window,The program will crash and crash.
2 participants