-
-
Notifications
You must be signed in to change notification settings - Fork 797
fix: schedule ActionForm
submit handler to run after user submit handlers (closes #3872)
#4130
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?
Conversation
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.
Looks like calling prevent_default inside request_animation_frame doesn't work since request_animation_frame isn't blocking, so the on submit handler completes and calls the browser's default submit before request_animation_frame's callback is called. I tested this branch locally and confirmed it caused duplicated requests due to browser's default handler still being called and also caused a navigation to happen outside the Leptos router.
My fault for suggesting delaying the on submit without thinking through the fact that we would still need to prevent the browser's default behavior (which can't be done in a delayed way afaik) and calling prevent_default would prevent the user's handler.
I don't know of a workable solution to this at the moment. Thinking on it.
@paul-hansen Just checking, which browser were you testing this under? |
Firefox, though I just tested under chrome and I get the same thing. (Don't forget to check the "preserve log" on the network tab in chrome or it will hide the extra request because the page load resets the network log by default.) In case any of this matters: Lmk and I can try making a minimal repro if you aren't seeing the same. Currently just testing with my project so maybe something is affecting it there. |
Huh. Weird. I just tried it with this diff in the --- a/examples/server_fns_axum/src/app.rs
+++ b/examples/server_fns_axum/src/app.rs
@@ -224,7 +224,7 @@ pub fn WithActionForm() -> impl IntoView {
<code>"<form>"</code>
"to call a server function in a way that gracefully degrades."
</p>
- <ActionForm action>
+ <ActionForm action on:submit=|ev| {
+ ev.prevent_default();
+ leptos::logging::log!("did it submit?");
+ }>
<input
// the `name` of the input corresponds to the argument name
name="text" |
Looks like it's because I'm using a browser confirmation dialog. <ActionForm action on:submit=|ev| {
let success = window()
.confirm_with_message("hello world")
.unwrap_or_default();
if !success {
ev.prevent_default();
leptos::logging::log!("default prevented");
}
}> When I submit and choose "ok", I see two requests, one with a 302 status and one with 200. |
Came up with a potential alternative in #4131 feel free to use parts of it or anything if you have better ideas. |
No description provided.