DioxusLabs / DioxusLabs/dioxus
Null function or function signature mismatch when adding closure in event handler
- Dominant language
- Rust
- Stars
- 39.1k
- Forks
- 1.9k
- Avg merge
- 4d 10h
- Merged PRs (30d)
- 4
Description
**Problem**
I think this is related to `use_persistent` and `use_server_future`. When I have a global context that uses persistent signals I get these panics. They are kind of inconsistent, however, they seem to be more consistent when i have some event handler in the component or components child. I have kind of a janky set up below to try to replicate what I am seeing in my app. (the closure in this case is in the Echo component).
I wish I had a better smoking gun but this is the best I have been able to come up with. I also will get different types of errors, in the screenshot, it happened to be upset with the storage sdk. I have also seen that it will panic creating FnMut contexts (in the component event handler). If I remove the Echo component the panics will stop.
**Steps To Reproduce**
Steps to reproduce the behavior:
- `dx init` with full stack and routing
- Deps:
```toml
[dependencies]
dioxus = { version = "0.7.1", features = ["router", "fullstack"] }
dioxus-sdk = { version = "0.7.0", features = ["storage"] }
```
- Add a context with persistence in `main.rs`
```rust
//...
#[derive(Clone, Copy, Default, PartialEq)]
pub struct AppContext {
test: Signal,
}
#[component]
fn App() -> Element {
let test = use_persistent("test", || "whats up".to_string());
use_context_provider(|| AppContext { test });
//...
```
- Add a server future and context read
```rust
#[post("/api/future")]
async fn test_future(input: String) -> Result {
if input == "error please" {
return Err(ServerFnError::ServerError {
message: "idk".into(),
code: StatusCode::NOT_FOUND.into(),
details: None,
});
}
Ok("back from the server".to_string())
}
/// The Home page component that will be rendered when the current route is `[Route::Home]`
#[component]
pub fn Home() -> Element {
let context = use_context::();
info!("context: {}", context.test);
let result =
use_server_future(move || async move { test_future("Hello, world!".to_string()).await })?;
info!("result: {:?}", result.unwrap());
rsx! {
Hero {}
Echo {}
}
}
```
**Expected behavior**
No panics _or_ a handled error to show me I was doing something i shouldn't be doing (or something from `dx check`).
**Screenshots**
**Environment:**
- Dioxus version: v0.7.1 (dioxus_sdk v0.7.0)
- Rust version: 1.90.0
- OS info: macOS
- App platform: web, fullstack
**Questionnaire**
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.