diff --git a/CHANGELOG.md b/CHANGELOG.md index dd286764..ecfe9442 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,7 @@ And please only add new entries to the top of this list, right below the `# Unre - On Web, use the correct canvas size when calculating the new size during scale factor change, instead of using the output bitmap size. - On Web, scale factor and dark mode detection are now more robust. +- On Web, fix the bfcache by not using the `beforeunload` event. # 0.28.6 diff --git a/Cargo.toml b/Cargo.toml index 11245bbd..fc364dd1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -133,7 +133,6 @@ version = "0.3.22" features = [ 'console', 'CssStyleDeclaration', - 'BeforeUnloadEvent', 'Document', 'DomRect', 'Element', diff --git a/src/platform_impl/web/web_sys/mod.rs b/src/platform_impl/web/web_sys/mod.rs index a7b9443f..611fcd78 100644 --- a/src/platform_impl/web/web_sys/mod.rs +++ b/src/platform_impl/web/web_sys/mod.rs @@ -15,7 +15,7 @@ use crate::dpi::{LogicalSize, Size}; use crate::platform::web::WindowExtWebSys; use crate::window::Window; use wasm_bindgen::closure::Closure; -use web_sys::{BeforeUnloadEvent, Element, HtmlCanvasElement}; +use web_sys::{Element, HtmlCanvasElement}; pub fn throw(msg: &str) { wasm_bindgen::throw_str(msg); @@ -28,18 +28,13 @@ pub fn exit_fullscreen(window: &web_sys::Window) { } pub struct UnloadEventHandle { - _listener: event_handle::EventListenerHandle, + _listener: event_handle::EventListenerHandle, } -pub fn on_unload( - window: &web_sys::Window, - mut handler: impl FnMut() + 'static, -) -> UnloadEventHandle { - let closure = Closure::wrap( - Box::new(move |_: BeforeUnloadEvent| handler()) as Box - ); +pub fn on_unload(window: &web_sys::Window, handler: impl FnMut() + 'static) -> UnloadEventHandle { + let closure = Closure::new(handler); - let listener = event_handle::EventListenerHandle::new(window, "beforeunload", closure); + let listener = event_handle::EventListenerHandle::new(window, "pagehide", closure); UnloadEventHandle { _listener: listener, }