Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using time::every displays an empty page on WASM #2604

Open
4 tasks done
0xkake opened this issue Sep 24, 2024 · 3 comments
Open
4 tasks done

Using time::every displays an empty page on WASM #2604

0xkake opened this issue Sep 24, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@0xkake
Copy link

0xkake commented Sep 24, 2024

Is your issue REALLY a bug?

  • My issue is indeed a bug!
  • 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?

  • I have searched the existing issues.

Is this issue related to iced?

  • 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
image
Commenting out the subscription, or returning Subscription::none()
image

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 "../".
@0xkake 0xkake added the bug Something isn't working label Sep 24, 2024
@0xkake
Copy link
Author

0xkake commented Sep 24, 2024

Possibly related to #352

@0xkake 0xkake changed the title Using Subscription displays an empty page on WASM Using time::every displays an empty page on WASM Sep 24, 2024
@Kulasko
Copy link

Kulasko commented Sep 25, 2024

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.

@edwloef
Copy link
Contributor

edwloef commented Nov 30, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants