DioxusLabs / DioxusLabs/dioxus
Make it possible to `use_websocket` on web feature only
- Dominant language
- Rust
- Stars
- 39.1k
- Forks
- 1.9k
- Avg merge
- 4d 10h
- Merged PRs (30d)
- 4
Description
## Feature Request
I want to create a web only page, without server side things at all.
The websocket is coming from a different program, I have no control of.
I managed to have a small example ready, that only needs the `web` and `fullstack` feature turned on.
It will compile, but fail to run.
Code
```rust
use dioxus::{
fullstack::{
http::Extensions, reqwest::Url, use_websocket, ClientRequest, FromResponse, HeaderMap,
IntoRequest, Method, WebSocketOptions, Websocket,
},
prelude::*,
};
async fn create_ws() -> Result {
let resp = WebSocketOptions::new()
.with_automatic_reconnect()
.into_request(ClientRequest {
url: Url::parse("ws://127.0.0.1:7070").unwrap(),
headers: HeaderMap::default(),
method: Method::default(),
extensions: Extensions::default(),
})
.await?;
let r = Websocket::from_response(resp).await?;
println!("Create ws! {:?}", r.protocol());
Ok(r)
}
#[component]
fn App() -> Element {
let sock = use_websocket(create_ws);
todo!()
}
fn main() {
dioxus::launch(App);
}
```
I mean, it looks perfectly fine IMHO. The client opens a connection and upon response the websocket will be created.
Trying to run this, will emit the following error:
```
16:22:26 [server] thread 'main' (32677) panicked at /home/marcel/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wasm-bindgen-futures-0.4.55/src/task/singlethread.rs:22:1:
16:22:26 [server] cannot call wasm-bindgen imported functions on non-wasm targets
16:22:26 [server] stack backtrace:
16:22:26 [dev] Build completed successfully in 1051ms, launching app! 💫
16:22:26 [server] 0: __rustc::rust_begin_unwind
16:22:26 [server] at /rustc/bd3ac0330018c23b111bbee176f32c377be7b319/library/std/src/panicking.rs:698:5
16:22:26 [server] 1: core::panicking::panic_fmt
16:22:26 [server] at /rustc/bd3ac0330018c23b111bbee176f32c377be7b319/library/core/src/panicking.rs:80:14
16:22:26 [server] 2: wasm_bindgen_futures::task::singlethread::create_task::__wbg_createTask_9ac11a42c24ef284
16:22:26 [server] at /home/marcel/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wasm-bindgen-futures-0.4.55/src/task/singlethread.rs:22:1
16:22:26 [dev] Application [web] exited with error: exit status: 101
16:22:26 [server] 3: wasm_bindgen_futures::task::singlethread::create_task
16:22:26 [server] at /home/marcel/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wasm-bindgen-futures-0.4.55/src/task/singlethread.rs:22:1
16:22:26 [server] 4: wasm_bindgen_futures::task::singlethread::Task::spawn
16:22:26 [server] at /home/marcel/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wasm-bindgen-futures-0.4.55/src/task/singlethread.rs:53:22
16:22:26 [server] 5: wasm_bindgen_futures::spawn_local
16:22:26 [server] at /home/marcel/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wasm-bindgen-futures-0.4.55/src/lib.rs:92:5
16:22:26 [server] 6: dioxus_web::launch::launch_virtual_dom
16:22:26 [server] at /home/marcel/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/dioxus-web-0.7.0/src/launch.rs:30:5
16:22:26 [server] 7: dioxus_web::launch::launch
16:22:26 [server] at /home/marcel/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/dioxus-web-0.7.0/src/launch.rs:23:5
16:22:26 [server] 8: dioxus::launch::LaunchBuilder::launch
16:22:26 [server] at /home/marcel/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/dioxus-0.7.0/src/launch.rs:353:20
16:22:26 [server] 9: dioxus::launch::launch
16:22:26 [server] at /home/marcel/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/dioxus-0.7.0/src/launch.rs:57:26
16:22:26 [server] 10: dioxus_frontend::main
16:22:26 [server] at ./src/main.rs:47:5
16:22:26 [server] 11: core::ops::function::FnOnce::call_once
16:22:26 [server] at /home/marcel/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
16:22:26 [server] note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
```
## Implement Suggestion
Can you tell me where I went wrong?
I don't think it's currently possible to do what I want, is it?!
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.