From 46dec4a6605ca0d8e4cbf3769ba47405d53cb75b Mon Sep 17 00:00:00 2001 From: Alexey Date: Sat, 17 Oct 2026 17:56:25 +0200 Subject: [PATCH] fix(wasm): avoid std services that panic on wasm32-unknown-unknown at startup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit recovery::instance_id() mixed std::process::id() into the instance hash — on wasm32-unknown-unknown that panics (``no pids on this platform``, and SystemTime is missing too), so the web app died before its first frame. On wasm the browser clock (js_sys::Date::now(), already an engine dep for comment timestamps) stands in. --- crates/engine/src/recovery.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/engine/src/recovery.rs b/crates/engine/src/recovery.rs index 6996cda7..646a1434 100644 --- a/crates/engine/src/recovery.rs +++ b/crates/engine/src/recovery.rs @@ -44,6 +44,11 @@ pub fn instance_id() -> u64 { *ID.get_or_init(|| { use std::hash::{BuildHasher, Hasher}; let mut h = std::collections::hash_map::RandomState::new().build_hasher(); + // No PIDs and no std::time on wasm (`std::process::id()` and + // `SystemTime::now()` panic there): the browser clock stands in. + #[cfg(target_arch = "wasm32")] + h.write_u64(js_sys::Date::now() as u64); + #[cfg(not(target_arch = "wasm32"))] h.write_u32(std::process::id()); #[cfg(not(target_arch = "wasm32"))] if let Ok(d) = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH) {