Repository navigation
On Web, map bfcache load/unload to suspend/resume - #2912
Conversation
There was a problem hiding this comment.
I think what we should do here is look at PageTransitionEvent.persisted.
If it's true we should send Suspended and also hook up the pageshow event with a Resumed event.
If it's false we can resume to destroy the event loop.
Thank you for looking into this!
f9f42fb to
1b8d46f
Compare
pagehide events
Thanks @daxpedda for the helpful feedback! I updated the PR according to this, could you have a look? Specifically, is it correct to just |
1b8d46f to
e5ed4d1
Compare
daxpedda
left a comment
There was a problem hiding this comment.
Great stuff, thank you!
Couple of nits.
Lifecycle management seems fine. Though I'm trying to figure out if it's necessary for us to actively ignore a request_redraw() after a Suspend event.
e5ed4d1 to
4c141af
Compare
|
@daxpedda Thanks again for the quick review! I applied your suggested code change, and answered your comments about |
CHANGELOG.mdif knowledge of this change could be valuable to usersIn #2261, the web backend was changed to use the
pagehideevent instead ofunload, to allow the bfcache to be used.See https://web.dev/bfcache/ for more information about the bfcache (back/forward cache), and https://developer.chrome.com/docs/devtools/application/back-forward-cache/ for how to test it in chrome. Summary from the first resource:
The problem with winit and the bfcache is that the event loop is destroyed in
pagehide- which happens before the snapshot is put in the bfcache. So when a user navigates back to the page running a winit program it's no longer responding.This can be seen on e.g. the web example program (
cargo run-wasm --example web) - after restoring the page from the bfcache the event log is no longer updated.This PR changes
pagehidehandling to only destroy the event loop if persisted isfalse. If persisted istrue, we now emit aSuspendedevent.It also adds a corresponding listener for
pageshowwithpersistedbeingtrue, to emit aResumedevent in that case.