From 8f272f1fe8e7ffa105ef1526d651fb35f4837906 Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Tue, 1 Sep 2026 09:14:26 +0700 Subject: [PATCH] fix --- web/Cargo.toml | 2 +- web/src/lib.rs | 22 ++++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/web/Cargo.toml b/web/Cargo.toml index f63bed84..4495ef60 100644 --- a/web/Cargo.toml +++ b/web/Cargo.toml @@ -32,7 +32,7 @@ console_log = "1.0" wasm-bindgen = "0.2" wasm-bindgen-futures = "0.4" js-sys = "0.3" -web-sys = { version = "0.3", features = ["Window", "Performance"] } +web-sys = { version = "0.3", features = ["Window", "Performance", "console", "DomException"] } universal-time = { git = "https://github.com/shadowylab/universal-time" } [target.'cfg(target_arch = "wasm32")'.dependencies] diff --git a/web/src/lib.rs b/web/src/lib.rs index 973da21a..d4c0c56b 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -69,8 +69,6 @@ pub fn set_theme(dark: bool) { #[wasm_bindgen] pub async fn run() -> Result<(), JsValue> { - console_error_panic_hook::set_once(); - // Initialize logging to browser console console_log::init_with_level(log::Level::Info).expect("Failed to initialize logger"); @@ -80,6 +78,26 @@ pub async fn run() -> Result<(), JsValue> { #[cfg(target_family = "wasm")] gpui_platform::web_init(); + // Install the panic hook AFTER `web_init` (which sets the default + // `console_error_panic_hook`), so ours wins. It prints the entire + // JS/wasm stack as a single string: `console_error_panic_hook`'s default + // output is an `Error` object whose stack is collapsed in the console, + // and on wasm the frames below the panic machinery name the task that + // panicked (debug builds keep symbol names) — essential for diagnosing + // `RefCell already borrowed`. + #[cfg(target_family = "wasm")] + std::panic::set_hook(Box::new(|info| { + // Capture the JS stack (which includes the wasm frames with symbol + // names in debug builds) without constructing DOM objects. + let stack = js_sys::Reflect::get(&js_sys::Error::new(""), &"stack".into()) + .ok() + .and_then(|v| v.as_string()) + .unwrap_or_default(); + web_sys::console::error_1( + &format!("{info}\n\n==== full stack ====\n{stack}\n=====================").into(), + ); + })); + #[cfg(not(target_family = "wasm"))] let app = gpui_platform::application();