Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling server function with empty vector argument causes a crash #3460

Open
patrik-cihal opened this issue Dec 27, 2024 · 0 comments
Open

Comments

@patrik-cihal
Copy link

Problem

Happens on 0.6.1. When server function that accepts vector argument is called where it is an empty vector it cause 500 error.
The issue is that the argument doesn't get passed in the http request as

arg: []

but rather ommited completely which makes the server arguments fail to deserialize.

Steps To Reproduce

Steps to reproduce the behavior:
This the minimal code:

use dioxus::prelude::*;

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

#[component]
fn App() -> Element {
    rsx! {
        button {
            onclick: move |_| {
                async move {
                    // This will fail because empty vector is not properly serialized
                    let result = s_f(vec![]).await;
                    println!("Result: {:?}", result);
                }
            },
            "Test empty vector"
        }
        button {
            onclick: move |_| {
                async move {
                    // This will work because vector has an item
                    let result = s_f(vec!["Hello world".into()]).await;
                    println!("Result: {:?}", result);
                }
            },
            "Test non-empty vector"
        }
    }
}

#[server(SF)]
async fn s_f(items: Vec<String>) -> Result<String, ServerFnError> {
    println!("Items: {:?}", items);
    Ok("Success".into())
} 

Expected behavior

Screenshots

Environment:

  • Dioxus version: 0.6.1
  • Dioxus platform: Web
  • Browser: Firefox
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant