Skip to content

Leptos Application fails with Tokio runtime worker issue #3893

Open
@suraj-mandal

Description

@suraj-mandal

Describe the bug
When I run a custom Leptos application that I built, for the first time, the page loads correctly. However, when I refresh the page, I get the following error:

thread 'tokio-runtime-worker' panicked at /home/suraj-mandal/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wasm-bindgen-0.2.100/src/lib.rs:1062:1:
Function not implemented on non-Wasm32 targets
stack backtrace:
   0:     0x62b9d0558c32 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::he1cc6de51b8e3e46
   1:     0x62b9d057fd53 - core::fmt::write::h546351ef89cac2c3
   2:     0x62b9d05559b3 - std::io::Write::write_fmt::hdd0a9df47aae8e9f
   3:     0x62b9d0558a82 - std::sys::backtrace::BacktraceLock::print::h575bf1241b79e77a
   4:     0x62b9d0559ae7 - std::panicking::default_hook::{{closure}}::h9889804a123e7c5b
   5:     0x62b9d05598ea - std::panicking::default_hook::h0459a96a46f07fba
   6:     0x62b9d055a4c2 - std::panicking::rust_panic_with_hook::hb01102643345a267
   7:     0x62b9d055a216 - std::panicking::begin_panic_handler::{{closure}}::hdeb84786a6bcd0e1
   8:     0x62b9d0559139 - std::sys::backtrace::__rust_end_short_backtrace::he1635835e44d11b6
   9:     0x62b9d0559edd - __rustc[a2fe60415b7691ee]::rust_begin_unwind
  10:     0x62b9d057d660 - core::panicking::panic_fmt::hc7324b7acfa89cbe
  11:     0x62b9d0401468 - wasm_bindgen::__wbindgen_describe_closure::h49b954b4a603dd71

The following code is making the issue as per my investigation, but I am not exactly sure why it is making the issue:

use leptos::prelude::*;
use leptos_meta::Stylesheet;
use leptos_ui::clx;
use std::time::Duration;

#[component]
pub fn DemoWordRotation() -> impl IntoView {
    view! {
        <Stylesheet href="/components/word_rotation.css" />

        <div class="h-[400px] grid place-content-center font-roboto-slab">
            <WordRotationWrapper>
                <WordRotation>
                    <span>Know</span>
                    // <TransitionWordComponent />
                    <span>with no limits.</span>
                </WordRotation>
                <SimpleCounter initial_value=23 />
            </WordRotationWrapper>
        </div>

        // ----- SCRIPT -----
        <script src="/components/word_rotation.js"></script>
    }
}

#[component]
pub fn SimpleCounter(initial_value: i32) -> impl IntoView {
    // create a reactive signal with the initial value
    let (value, set_value) = signal(initial_value);

    // create event handlers for our buttons
    // note that `value` and `set_value` are `Copy`, so it's super easy to move them into closures
    let clear = move |_| set_value(0);
    let decrement = move |_| set_value.update(|value| *value -= 1);
    let increment = move |_| set_value.update(|value| *value += 1);

    // create user interfaces with the declarative `view!` macro
    view! {
        <div>
            <button on:click=clear>Clear</button>
            <button on:click=decrement>-1</button>
            // text nodes can be quoted or unquoted
            <span>"Value: " {value} "!"</span>
            <button on:click=increment>+1</button>
        </div>
    }
}

#[component]
pub fn TransitionWordComponent() -> impl IntoView {
    let (count, set_count) = signal(0);

    set_interval(
        move || set_count.update(|c| *c += 1),
        Duration::from_secs(2),
    );


    view! {
        <span style="view-transition-name: swap;">{count}</span>
    }
}

mod components {
    use super::*;
    clx! {WordRotationWrapper, main, "my-0 mx-auto py-8 px-4 w-[800px] resize text-[2.5rem] overflow-hidden"}
    clx! {WordRotation, p, "flex flex-wrap m-0 gap-[0.5ch] leading-[0.9]"}
}

pub use components::*;

// TODO. Add this to the WordRotation component.
// span:nth-of-type(2) {
//     color: hsl(64, 100%, 50%);
// }

As I can see here, I am using signals here, but still I am getting the following issue.

Leptos Dependencies

Here are the leptos dependencies:

[package]
name = "app"
version = "0.1.0"
edition = "2024"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
cfg-if.workspace = true
http.workspace = true
leptos.workspace = true
leptos_meta.workspace = true
leptos_router.workspace = true
leptos_axum = { workspace = true, optional = true }
leptos_ui.workspace = true
thiserror.workspace = true
tw_merge.workspace = true
wasm-bindgen.workspace = true


[features]
default = []
hydrate = ["leptos/hydrate"]
ssr = [
    "leptos/ssr",
    "leptos_meta/ssr",
    "leptos_router/ssr",
    "dep:leptos_axum"
]

Please copy and paste the Leptos dependencies and features from your Cargo.toml.

For example:

leptos = { version = "0.3", features = ["serde"] }
leptos_axum = { version = "0.3", optional = true }
leptos_meta = { version = "0.3"}
leptos_router = { version = "0.3"}

Kindly help me to resolve this issue?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions