DioxusLabs / DioxusLabs/docsite

Change `use_resource` in the HotDog tutorial to `use_server_future` to fix hydration

Open
#483 4 comments 0 reactions 0 assignees View on GitHub
documentation fullstack
Dominant language
Rust
Stars
206
Forks
208
Avg merge
1h 11m
Merged PRs (30d)
3

Description

**Problem**

When unwrapping with the question mark operator a suspended signal that is not yet available, it may be cast to a JS error and printed to the browser's console:
```
wasm-bindgen: imported JS function that was not marked as `catch` threw an error: id is undefined
```

On the contrary, if we use `signal.suspend().unwrap()`, it prints that it can't unwrap an Err value:
```
called `Result::unwrap()` on an `Err` value: Suspended(SuspendedFuture { origin: ScopeId(3, "root"), task: Task { id: DefaultKey(1v1), unsend: PhantomData<*const ()> }, placeholder: VNode { vnode: VNodeInner { key: None, template: Template { roots: [Dynamic { id: 0 }], node_paths: [[0]], attr_paths: [] }, dynamic_nodes: [Placeholder(VPlaceholder)], dynamic_attrs: [] }, mount: Cell { value: MountId(4294967295) } } })
```

**Steps To Reproduce**

Serve the following Dioxus web app and open it in Firefox (it doesn't seem to display the error in Brave):
```rust
use dioxus::prelude::*;

fn main() {
dioxus::launch(App);
}

#[component]
pub fn App() -> Element {
let mut resource = use_resource(list_dogs);
let signal_result = resource.suspend()?;

rsx! {
div {
for (id, url) in signal_result().unwrap() {
div {
onclick: move |_| async move {},
}
}
}
}
}

#[server]
pub async fn list_dogs() -> Result, ServerFnError> {
Ok(vec![(1, "https://images.dog.ceo/breeds/mountain-bernese/n02107683_3291.jpg".to_string())])
}
```

**Expected behavior**

As per my comprehension, both operands should work the same here. The preferred behavior would be that the question mark operator would throw the same exception as the `unwrap()` call: the signal is not yet available, thus an `Err` is returned as expected.

**Environment:**

- Dioxus version: 0.6.3
- Rust version: 1.85.0
- OS info: Windows 10
- App platform: web

**Questionnaire**

I'm interested in fixing this myself but don't know where to start.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.