Using `time::every` displays an empty page on WASM
Is your issue REALLY a bug?
- [X] My issue is indeed a bug!
- [X] I am not crazy! I will not fill out this form just to ask a question or request a feature. Pinky promise.
Is there an existing issue for this?
- [X] I have searched the existing issues.
Is this issue related to iced?
- [X] My hardware is compatible and my graphics drivers are up-to-date.
What happened?
Running a program that has a subscription that runs in intervals with time::every in WASM displays a blank page
Commenting out the subscription, or returning Subscription::none()
SSCCE
src/main.rs
use iced::{widget::text, Element, Renderer, Theme};
fn main() -> iced::Result {
iced::application("Subscription Bug", App::update, App::view)
.subscription(App::subscription)
.run()
}
#[derive(Debug)]
pub enum Message {
Increment
}
#[derive(Default)]
pub struct App {
counter: usize
}
impl App {
fn subscription(&self) -> iced::Subscription<Message> {
iced::time::every(std::time::Duration::from_millis(1000)).map(|_| Message::Increment)
}
fn update(&mut self, event: Message) {
match event {
Message::Increment => {
self.counter += 1;
}
}
}
fn view(&self) -> Element<Message, Theme, Renderer> {
text(format!("Counter: {}", self.counter)).size(50).into()
}
}
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<base data-trunk-public-url />
</head>
<body>
<link data-trunk rel="rust" href="Cargo.toml" data-wasm-opt="z" />
</body>
</html>
Ran with: trunk serve
What is the expected behavior?
The page should display the counter and increment it every second
Version
crates.io release
Operating System
Windows
Do you have any log output?
DevTools console (not sure if relevant):
Uncaught TypeError: Failed to resolve module specifier "env". Relative references must start with either "/", "./", or "../".
Possibly related to #352
I have investigated a bit and it seems this is caused by the instant crate trying to pull in something that it can't. It's a transitive dependency of wasm_timer, which is used in iced-futures. This problem has been known for quite some time, but neither wasm_timer nor instant have been updated in the last 4 years. There is a fork of wasm_time called wasmtimer that also hasn't received an update in a year, but seems to have solved the problem.
Considering the instant crate has by now been marked as "unmaintained" by RUSTSEC (https://rustsec.org/advisories/RUSTSEC-2024-0384.html), replacing it in some form or another seems like something that probably should be looked into.