-
-
Notifications
You must be signed in to change notification settings - Fork 797
Allow MultipartData ActionForms #4278
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
base: main
Are you sure you want to change the base?
Changes from all commits
e230647
5eed364
2a4c474
9b0dde0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -341,9 +341,10 @@ impl ServerFnCall { | |
Clone, #server_fn_path::rkyv::Archive, #server_fn_path::rkyv::Serialize, #server_fn_path::rkyv::Deserialize | ||
}, | ||
), | ||
Some("MultipartFormData") | ||
| Some("Streaming") | ||
| Some("StreamingText") => (PathInfo::None, quote! {}), | ||
Some("MultipartFormData") => (PathInfo::None, quote! { Clone }), | ||
Some("Streaming") | Some("StreamingText") => { | ||
(PathInfo::None, quote! {}) | ||
} | ||
Some("SerdeLite") => ( | ||
PathInfo::Serde, | ||
quote! { | ||
|
@@ -744,6 +745,31 @@ impl ServerFnCall { | |
} | ||
} | ||
|
||
fn impl_from_form(&self) -> TokenStream2 { | ||
if self.input_ident().as_deref() != Some("MultipartFormData") { | ||
return quote! {}; | ||
} | ||
|
||
let Some((field_name, _)) = self.single_field() else { | ||
return quote! {}; | ||
}; | ||
|
||
let server_fn_path = self.server_fn_path(); | ||
let struct_name = self.struct_name(); | ||
|
||
quote! { | ||
impl ::leptos::form::FromFormData for #struct_name { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest that this should be handled in a similar way to the |
||
fn from_form_data( | ||
form_data: &::leptos::web_sys::FormData, | ||
) -> Result<Self, ::leptos::serde_qs::Error> { | ||
Ok(Self { | ||
#field_name: #server_fn_path::codec::MultipartData::from(form_data.clone()), | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
|
||
fn func_tokens(&self) -> TokenStream2 { | ||
let body = &self.body; | ||
// default values for args | ||
|
@@ -811,6 +837,8 @@ impl ToTokens for ServerFnCall { | |
|
||
let impl_from = self.impl_from(); | ||
|
||
let impl_from_form = self.impl_from_form(); | ||
|
||
let deref_impl = self.deref_impl(); | ||
|
||
let inventory = self.submit_to_inventory(); | ||
|
@@ -826,6 +854,8 @@ impl ToTokens for ServerFnCall { | |
|
||
#impl_from | ||
|
||
#impl_from_form | ||
|
||
#deref_impl | ||
|
||
#server_fn_impl | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you that this is awkward. We should not implement
Clone
on a type that is not actually cloneable by panicking on the server. I think the piece of context I'm missing is — Why does this need to have aClone
implementation at all? (If you have aMultipartData
and need to clone it you can call.into_client_data().map(|data| data.take())
and clone that instead)