Skip to content

Ensure WinitUserEvent::WakeUp trigger app update#23957

Draft
rmaj91 wants to merge 2 commits intobevyengine:mainfrom
rmaj91:wasm-wakeup
Draft

Ensure WinitUserEvent::WakeUp trigger app update#23957
rmaj91 wants to merge 2 commits intobevyengine:mainfrom
rmaj91:wasm-wakeup

Conversation

@rmaj91
Copy link
Copy Markdown

@rmaj91 rmaj91 commented Apr 23, 2026

Objective

This PR targets browser unfocused tab throttling issue. Currently bevy window event loop depends on the request animation frame (LINK) which doesn't work on the unfocused browser tabs.
When brower stops rendering also bevy stops calling app.update() which effectively stops all the systems and makes bevy wasm not usable in apps that require keeping networking alive or somehow requires processing in the background.

more info:
#13486
#13366

ISSUE

Actual app.update() is called here: LINK
snippet:

            if !self.ran_update_since_last_redraw || all_invisible {
                self.run_app_update();
                #[cfg(feature = "custom_cursor")]
                self.update_cursors(event_loop);
                #[cfg(not(feature = "custom_cursor"))]
                self.update_cursors();
                self.ran_update_since_last_redraw = true;
            } else {
                self.redraw_requested = true;
            }

App update depends on two variables: all_visible which is not relevant in this case.
And on ran_update_since_last_redraw which is the key here.

App.update() only happens when ran_update_since_last_redraw is set to false, false value is set HERE as reaction on WindowEvent::RedrawRequested which is emitted when The application has explicitly requested a redraw via [Window::request_redraw]. LINK.

SOLUTION

WinitUserEvent::WakeUp sets flag ran_update_since_last_redraw = false. This makes wake up event not only request redraw but also hints (WinitSettings update mode it's still respected here) event loop to call app.update()

Alternative solution

Can set this flag to false as RequestRedraw event reaction LINK

Also can consider introducing another flag to control update.

Testing

Did manual testing, I was able to wake up app and print logs in the unfocused tab.
This is only a proposal, and I would be grateful for any feedback or help.

Edit: I believe this is right solution for this problem. Final implementation details can vary but it seems it nicely integrates into winit_plugin loop.

@github-actions
Copy link
Copy Markdown
Contributor

Welcome, new contributor!

Please make sure you've read our contributing guide, as well as our policy regarding AI usage, and we look forward to reviewing your pull request shortly ✨

@alice-i-cecile alice-i-cecile added A-Windowing Platform-agnostic interface layer to run your app in O-Web Specific to web (WASM) builds S-Needs-Review Needs reviewer attention (from anyone!) to move forward C-Bug An unexpected or incorrect behavior D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes labels Apr 23, 2026
Comment thread crates/bevy_winit/src/state.rs Outdated
@rmaj91 rmaj91 changed the title WinitUserEvent::WakeUp calls app update on wasm WinitUserEvent::WakeUp trigger app update Apr 25, 2026
@rmaj91 rmaj91 changed the title WinitUserEvent::WakeUp trigger app update Ensure WinitUserEvent::WakeUp trigger app update Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Windowing Platform-agnostic interface layer to run your app in C-Bug An unexpected or incorrect behavior D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes O-Web Specific to web (WASM) builds S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants