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

structs containing Vec<T>, HashSet<T> and HashMap<T, T> are not working with Signal/ServerFn #2628

Open
chungwong opened this issue Jul 11, 2024 · 1 comment · May be fixed by #3602
Open
Assignees
Labels
bug Something isn't working fullstack related to the fullstack crate

Comments

@chungwong
Copy link
Contributor

Problem

Steps To Reproduce
Reproducile repo

#[component]
fn Home() -> Element {
    let global_filter: Signal<GlobalFilter> = use_signal(|| GlobalFilter::default());

    rsx! {
        button {
            onclick: move |_| {
                let filter: GlobalFilter = global_filter.read_unchecked().to_owned();
                async move {
                    get_server_data(filter).await;
                }
            },
            "Button"
        }
    }
}

#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)]
pub struct GlobalFilter {
    pub test_string: String,

    pub test_vec: Vec<String>,
    pub test_hashset: HashSet<String>,
    pub test_hashmap: HashMap<String, String>,

    // wrap them in Option to bypass the bug
    // pub test_vec: Option<Vec<String>>,
    // pub test_hashset: Option<HashSet<String>>,
    // pub test_hashmap: Option<HashMap<String, String>>,
}

#[server]
async fn get_server_data(global_filter: GlobalFilter) -> Result<(), ServerFnError> {
    Ok(())
}

After clicking the button, an error( can be observed in browser's dev tool)

Args|missing field `test_vec`

happened. This error happened both on 0.5 and the main branch.

After digging on discord, the tmp solution is to wrap those fields in an Option. Evan mentioned it should be fixed in #2288 but looks like the above case is not covered.

Expected behavior
Those fields in the struct should work without the extra Option

Environment:

  • Dioxus version: 0.5 and main
  • Rust version: 1.79
  • OS info: Debian 12
  • App platform: Fullstack
@ealmloff ealmloff added bug Something isn't working fullstack related to the fullstack crate labels Jul 12, 2024
@jkelleyrtp jkelleyrtp added this to the 0.6.0 milestone Jul 25, 2024
@ealmloff
Copy link
Member

The default server function encoding is post url which doesn't support nested types. You can set the input and output encoding manually with this syntax:

#[server(input = Json, output = Json)]
async fn get_server_data(global_filter: GlobalFilter) -> Result<(), ServerFnError> {
    Ok(())
}

Dioxus should probably choose a more capable default encoding for server functions to make this work by default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fullstack related to the fullstack crate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants