fix(wasm): avoid std services that panic on wasm32-unknown-unknown at startup

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.
This commit is contained in:
Alexey
2026-10-18 15:27:59 +02:00
committed by Alexey Volkov
parent 22db9261f9
commit 46dec4a660
+5
View File
@@ -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) {