feat(core): add wakeup callback for external event loop integration#5430
Open
rlch wants to merge 1 commit intoDioxusLabs:mainfrom
Open
feat(core): add wakeup callback for external event loop integration#5430rlch wants to merge 1 commit intoDioxusLabs:mainfrom
rlch wants to merge 1 commit intoDioxusLabs:mainfrom
Conversation
Add `VirtualDom::set_wakeup_callback()` so external event loops (winit, GTK, etc.) can be notified when async tasks complete or scopes are marked dirty. This avoids the need for polling — the callback fires directly from the task waker when a future resolves. Without this, frameworks that drive the VirtualDom synchronously (calling `render_immediate()` in response to input events) have no way to know when async work like `use_resource` completions need processing. The UI only updates on the next user interaction, causing visual delays (e.g., images only appearing on hover). The callback is `Send + Sync` because Rust's `Waker` trait requires it — task wakers may fire from any thread. Closes #XXXX
Member
|
The dioxus/packages/desktop/src/webview.rs Line 539 in 45442af |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
VirtualDom::set_wakeup_callback()— a hook that fires when async tasks complete, allowing external event loops to schedule a repaint without polling.The problem: Frameworks that drive the VirtualDom synchronously (calling
render_immediate()in response to input events) have no way to know when async work needs processing. Ause_resourcefetch that completes while the user isn't interacting sits in the VirtualDom's queue until the next input event. This causes visible delays — e.g., images only appearing when the user hovers over the UI.The solution:
set_wakeup_callbackregisters aSend + Synccallback on the runtime that gets invoked fromArcWake::wake_by_refalongside the existing channel send. External event loops use this to schedule arender_immediatecall:This follows the universal pattern used by every major GUI framework (Flutter's
scheduleFrame, egui'srequest_repaint, Iced'sEventLoopProxy, Qt'spostEvent, GTK'sg_idle_add).Changes:
Runtime: newwakeup_callback: RefCell<Option<Arc<dyn Fn() + Send + Sync>>>fieldLocalTaskHandle: carries the callback, invokes it inwake_by_refVirtualDom::set_wakeup_callback(): public API to set the callbackpackages/core/tests/wakeup_callback.rsTest plan