DioxusLabs / dioxus

Fullstack GUI library for web, desktop, mobile, and more.
https://dioxuslabs.com
Apache License 2.0
18.5k stars 704 forks source link

axum-desktop failing **Run a server function** on client #2322

Closed chungwong closed 1 week ago

chungwong commented 2 weeks ago

Problem

Steps To Reproduce

cd dioxus/packages/fullstack/examples/axum-desktop
RUST_BACKTRACE=1 cargo run --features="desktop" --bin client

Click this button

Logs

thread 'main' panicked at /home/chung/.cargo/registry/src/index.crates.io-6f17d22bba15001f/js-sys-0.3.69/src/lib.rs:3394:1:
cannot call wasm-bindgen imported functions on non-wasm targets
stack backtrace:
   0: std::panicking::begin_panic
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/std/src/panicking.rs:686:12
   1: js_sys::Object::new::__wbg_new_72fb9a18b5ae2624
             at /home/chung/.cargo/registry/src/index.crates.io-6f17d22bba15001f/js-sys-0.3.69/src/lib.rs:3394:1
   2: js_sys::Object::new
             at /home/chung/.cargo/registry/src/index.crates.io-6f17d22bba15001f/js-sys-0.3.69/src/lib.rs:3394:1
   3: web_sys::features::gen_RequestInit::RequestInit::new
             at /home/chung/.cargo/registry/src/index.crates.io-6f17d22bba15001f/web-sys-0.3.69/src/features/gen_RequestInit.rs:20:68
   4: gloo_net::http::request::RequestBuilder::new
             at /home/chung/.cargo/registry/src/index.crates.io-6f17d22bba15001f/gloo-net-0.5.0/src/http/request.rs:33:22
   5: gloo_net::http::request::Request::post
             at /home/chung/.cargo/registry/src/index.crates.io-6f17d22bba15001f/gloo-net-0.5.0/src/http/request.rs:232:9
   6: <server_fn::request::browser::BrowserRequest as server_fn::request::ClientReq<CustErr>>::try_new_post
             at /home/chung/.cargo/registry/src/index.crates.io-6f17d22bba15001f/server_fn-0.6.9/src/request/browser.rs:96:13
   7: server_fn::codec::url::<impl server_fn::codec::IntoReq<server_fn::codec::url::PostUrl,Request,CustErr> for T>::into_req
             at /home/chung/.cargo/registry/src/index.crates.io-6f17d22bba15001f/server_fn-0.6.9/src/codec/url.rs:66:9
   8: server_fn::ServerFn::run_on_client::{{closure}}
             at /home/chung/.cargo/registry/src/index.crates.io-6f17d22bba15001f/server_fn-0.6.9/src/lib.rs:300:17
   9: axum_desktop::get_server_data::{{closure}}
             at ./src/lib.rs:33:1
  10: axum_desktop::app::{{closure}}::{{closure}}
             at ./src/lib.rs:14:53
  11: dioxus_core::tasks::<impl dioxus_core::runtime::Runtime>::handle_task_wakeup
             at /home/chung/repos/dioxus/packages/core/src/tasks.rs:207:27
  12: dioxus_core::virtual_dom::VirtualDom::poll_tasks
             at /home/chung/repos/dioxus/packages/core/src/virtual_dom.rs:522:25
  13: dioxus_core::virtual_dom::VirtualDom::process_events
             at /home/chung/repos/dioxus/packages/core/src/virtual_dom.rs:508:9
  14: dioxus_core::virtual_dom::VirtualDom::render_immediate
             at /home/chung/repos/dioxus/packages/core/src/virtual_dom.rs:639:9
  15: dioxus_desktop::app::App::handle_user_event_msg
             at /home/chung/repos/dioxus/packages/desktop/src/app.rs:319:9
  16: dioxus_desktop::launch::launch_virtual_dom_blocking::{{closure}}
             at /home/chung/repos/dioxus/packages/desktop/src/launch.rs:55:45
  17: tao::platform_impl::platform::event_loop::EventLoop<T>::run_return::{{closure}}
             at /home/chung/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tao-0.26.2/src/platform_impl/linux/event_loop.rs:1005:24
  18: glib::main_context::<impl glib::auto::main_context::MainContext>::with_thread_default
             at /home/chung/.cargo/registry/src/index.crates.io-6f17d22bba15001f/glib-0.18.5/src/main_context.rs:154:12
  19: tao::platform_impl::platform::event_loop::EventLoop<T>::run_return
             at /home/chung/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tao-0.26.2/src/platform_impl/linux/event_loop.rs:929:5
  20: tao::platform_impl::platform::event_loop::EventLoop<T>::run
             at /home/chung/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tao-0.26.2/src/platform_impl/linux/event_loop.rs:883:21
  21: tao::event_loop::EventLoop<T>::run
             at /home/chung/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tao-0.26.2/src/event_loop.rs:211:5
  22: dioxus_desktop::launch::launch_virtual_dom_blocking
             at /home/chung/repos/dioxus/packages/desktop/src/launch.rs:17:5
  23: dioxus_desktop::launch::launch_virtual_dom::{{closure}}
             at /home/chung/repos/dioxus/packages/desktop/src/launch.rs:76:13
  24: <tokio::task::unconstrained::Unconstrained<F> as core::future::future::Future>::poll::{{closure}}
             at /home/chung/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/task/unconstrained.rs:25:57
  25: tokio::runtime::coop::with_budget
             at /home/chung/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/coop.rs:107:5
  26: tokio::runtime::coop::with_unconstrained
             at /home/chung/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/coop.rs:80:5
  27: <tokio::task::unconstrained::Unconstrained<F> as core::future::future::Future>::poll
             at /home/chung/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/task/unconstrained.rs:25:13
  28: tokio::runtime::park::CachedParkThread::block_on::{{closure}}
             at /home/chung/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/park.rs:281:63
  29: tokio::runtime::coop::with_budget
             at /home/chung/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/coop.rs:107:5
  30: tokio::runtime::coop::budget
             at /home/chung/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/coop.rs:73:5
  31: tokio::runtime::park::CachedParkThread::block_on
             at /home/chung/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/park.rs:281:31
  32: tokio::runtime::context::blocking::BlockingRegionGuard::block_on
             at /home/chung/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/context/blocking.rs:66:9
  33: tokio::runtime::scheduler::multi_thread::MultiThread::block_on::{{closure}}
             at /home/chung/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/scheduler/multi_thread/mod.rs:87:13
  34: tokio::runtime::context::runtime::enter_runtime
             at /home/chung/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/context/runtime.rs:65:16
  35: tokio::runtime::scheduler::multi_thread::MultiThread::block_on
             at /home/chung/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/scheduler/multi_thread/mod.rs:86:9
  36: tokio::runtime::runtime::Runtime::block_on
             at /home/chung/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/runtime.rs:350:45
  37: dioxus_desktop::launch::launch_virtual_dom
             at /home/chung/repos/dioxus/packages/desktop/src/launch.rs:71:5
  38: dioxus_desktop::launch::launch
             at /home/chung/repos/dioxus/packages/desktop/src/launch.rs:95:5
  39: dioxus::launch::LaunchBuilder<Cfg,ContextFn>::launch
             at /home/chung/repos/dioxus/packages/dioxus/src/launch.rs:171:9
  40: dioxus::launch::launch_desktop
             at /home/chung/repos/dioxus/packages/dioxus/src/launch.rs:294:5
  41: client::main
             at ./src/client.rs:14:5
  42: core::ops::function::FnOnce::call_once
             at /rustc/82e1608dfa6e0b5569232559e3d385fea5a93112/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Environment: