Switch the default server function codec to json (#3602)

* Switch the default server function codec to json

* test both input and output encoding
This commit is contained in:
Evan Almloff authored and GitHub committed 2025-03-04 14:20:56 -06:00
1 parent 9967118784
commit eccd75a1fe
2 files changed
+115 -1

No files matched your search

@@ -41,6 +41,7 @@ fn app() -> Element {
Errors {}
}
OnMounted {}
DefaultServerFnCodec {}
DocumentElements {}
}
}
@@ -59,6 +60,15 @@ fn OnMounted() -> Element {
}
}
#[component]
fn DefaultServerFnCodec() -> Element {
let resource = use_server_future(|| get_server_data_empty_vec(Vec::new()))?;
let empty_vec = resource.unwrap().unwrap();
assert!(empty_vec.is_empty());
rsx! {}
}
#[cfg(feature = "server")]
async fn assert_server_context_provided() {
let FromContext(i): FromContext<u32> = extract().await.unwrap();
@@ -79,6 +89,15 @@ async fn get_server_data() -> Result<String, ServerFnError> {
Ok("Hello from the server!".to_string())
}
// Make sure the default codec work with empty data structures
// Regression test for https://github.com/DioxusLabs/dioxus/issues/2628
#[server]
async fn get_server_data_empty_vec(empty_vec: Vec<String>) -> Result<Vec<String>, ServerFnError> {
assert_server_context_provided().await;
assert!(empty_vec.is_empty());
Ok(Vec::new())
}
#[server]
async fn server_error() -> Result<String, ServerFnError> {
assert_server_context_provided().await;