Skip to content
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

Go back one page freezes the WASM runtime #10328

Open
carrascomj opened this issue Oct 31, 2023 · 3 comments
Open

Go back one page freezes the WASM runtime #10328

carrascomj opened this issue Oct 31, 2023 · 3 comments
Labels
C-Bug An unexpected or incorrect behavior O-Web Specific to web (WASM) builds

Comments

@carrascomj
Copy link

Bevy version

0.11.3

Relevant system information

Running WASM on firefox on WASM: wasm-bindgen v0.2.87, web-sys v0.3.64. Chromium also reproduces this issue.

What went wrong

Clicking on a link and then "Go back one page" in the browser returns to a frozen bevy app on WASM.

This does not happen with, for instance, egui, so I think it is not an upstream wasm-bindgen bug (?).

The issue can be reproduced:

  1. Go to https://bevyengine.org/examples/2D%20Rendering/2d-gizmos/
  2. The shapes should move.
  3. Click on the "here" link.
  4. Press "Go back one page" in your browser (left arrow, I am using the firefox term).
  5. The app is frozen.

Workaround

I am making my links open in a new tab but the workaround is not desirable since I have to implement a specialized Hyperlink struct for egui which is a lot of boilerplate for a link :(.

@carrascomj carrascomj added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Oct 31, 2023
@mockersf
Copy link
Member

This is due to a browser feature called "bfcache": https://web.dev/articles/bfcache

When going back, the browser is not actually reloading the previous page but reuse directly an in memory cache of the page with "frozen" javascript callback / promises.

This is not supported by Bevy, I'll try to look into what can be done (short task list: check js events are forwarded by winit, and try to react to them in Bevy, maybe like for Android suspend / resume. help is welcome!).

In the meantime, you can set js event listeners on your page destroying the canvas and recreating it when the page is reloaded from the bfcache, it should restart Bevy

@mockersf mockersf added O-Web Specific to web (WASM) builds and removed S-Needs-Triage This issue needs to be labelled labels Oct 31, 2023
@carrascomj
Copy link
Author

Thanks for the useful pointers and the link! I'll study the event listeners route.

carrascomj added a commit to biosustain/shu that referenced this issue Oct 31, 2023
This is a workaround for the app freezing because of
bfcache (see bevyengine/bevy#10328).
@daxpedda
Copy link
Contributor

daxpedda commented Nov 1, 2023

This was addressed by Winit in rust-windowing/winit#2851 and rust-windowing/winit#2912 and should just work for Bevy after #8745. Correct handling of the Suspended/Resumed events required of course.
Let me know if there are any remaining issues though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Bug An unexpected or incorrect behavior O-Web Specific to web (WASM) builds
Projects
None yet
Development

No branches or pull requests

3 participants