-
-
Notifications
You must be signed in to change notification settings - Fork 655
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
Added support for generics in server fns #3008
base: main
Are you sure you want to change the base?
Added support for generics in server fns #3008
Conversation
I am aware of the bad example namings and the debug prints that are currently present. Once I am able to get this working, I'll remove those and mark this PR as ready to review |
Oh my god I'm so stupid. I think I found the issue. Serde derives add a where clause of their own. Let me fix it and put an update to this PR. |
Okay, almost everything works now. The only part that's left is the |
@rakshith-ravi Are you trying to enable having generics as inputs to a server function? |
Yes, sir. Basically, trying to enable this:
In my work (the parts that I haven't pushed yet) I also have made the code a bit more flexible to eventually allow us to implement #2938 |
I added a commit that fixes the middleware-related issues on the examples here. One small note: this is broken with one-argument server functions right now. EDIT: I just added this in e2f096d because it was a one-liner If I do something like this #[server]
pub async fn test_fn<S>(input: S) -> Result<String, ServerFnError>
where
S: Display,
{
// insert a simulated wait
tokio::time::sleep(std::time::Duration::from_millis(250)).await;
Ok(input.to_string())
} I get the error:
Expanding the macro, I see that this is the issue: impl<S> From<TestFn<S>> for S
where
S: Display
+ ::leptos::server_fn::serde::Serialize
+ for<'leptos_param_lifetime> ::leptos::server_fn::serde::Deserialize<
'leptos_param_lifetime,
> + Send
+ 'static,
{
fn from(value: TestFn<S>) -> Self {
let TestFn::<S> { input } = value;
input
}
} We add a |
Okay, weirdly I now get a linker error with my generic example. Could someone else try building |
Yeah I'm getting the same error too. Not sure what's going on. Will look into this further |
Slept on this and had an idea: The |
@rakshith-ravi Any update on this? |
No update yet. There seems to be this odd linker issue. If that is figured out then we're pretty much good to go |
f9731e3
to
2d8466f
Compare
I have no clue why CI is green now. All I did was a rebase. Programming at it's peak: My code doesn't work and I don't know why; My code works and I don't know why |
The autofix CI fixed some spacing too. Is this ready now? |
Speaking of, it seems like the caveat here is that endpoint and prefix won't work here due to the multiple endpoints? |
I'm still getting the following error when compiling
server_fn_axum
:For context,
test_fn
expands to this:Not sure why this is happening. Any help on this would be appreciated