dioxus icon indicating copy to clipboard operation
dioxus copied to clipboard

Null function or function signature mismatch when adding closure in event handler

Open taybart opened this issue 3 months ago • 5 comments

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:
[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
//...
#[derive(Clone, Copy, Default, PartialEq)]
pub struct AppContext {
    test: Signal<String>,
}

#[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
#[post("/api/future")]
async fn test_future(input: String) -> Result<String, ServerFnError> {
    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::<AppContext>();
    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

Image Image

Environment:

  • Dioxus version: v0.7.1 (dioxus_sdk v0.7.0)
  • Rust version: 1.90.0
  • OS info: macOS
  • App platform: web, fullstack

Questionnaire

taybart avatar Nov 11 '25 03:11 taybart

Can you reproduce the issue without hot patching enabled? The error you posted could be caused by hot patching changing function signatures.

ealmloff avatar Nov 12 '25 14:11 ealmloff

I cannot reproduce it without hot patching, however, I was not able to figure out how to get the exact same error as my app. When I remove hot patching in the full app I get errors like this: ERROR /Users/taybart/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/dioxus-core-0.7.1/src/arena.rs:65 cannot reclaim ElementId(22). Not sure if that is related at all

taybart avatar Nov 12 '25 14:11 taybart

That is likely an unrelated error

ealmloff avatar Nov 12 '25 15:11 ealmloff

I was finally able to get the behavior I saw previously (again super hard to get a reproducible error) but last night I saw the error here:

Image

This causes the closure to not mount on the component (without hot patching). I could just be running into two different issues but they seem related. Its very inconsistent though, I was able to get here by submitting the form and then reloading the page.

taybart avatar Nov 19 '25 16:11 taybart

I was finally able to get the behavior I saw previously (again super hard to get a reproducible error) but last night I saw the error here:

Image This causes the closure to not mount on the component (without hot patching). I could just be running into two different issues but they seem related. Its very inconsistent though, I was able to get here by submitting the form and then reloading the page.

My guess is that is a different error. Errors like that can be caused by hydration issues which could be timing dependent. Make sure your server and client produce the same rsx the first render

ealmloff avatar Nov 19 '25 18:11 ealmloff