-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
ViewTransitions form submission behavior does not match browser-native behavior #9447
Comments
Aside from compatibility, the default browser behavior allows for some cool stuff with advanced forms. See this from the Remix docs: https://remix.run/docs/en/main/guides/faq#how-can-i-have-structured-data-in-a-form |
Just to say BTW, all my Vercel serverless functions that were handling forms crashed suddenly. Vercel parses request body depending on content-type and uses the default one ( Solution : add an attribute |
Thanks for raising this. When implementing this I went back and forth on whether to do formdata or urlencoded and went with formdata because:
That being said, I'm open to being wrong here. Unfortunately we can't change the default until 5.0 which is going to be a while. But I would think we should, at the least, honor the is the primary reason for wanting urlencoded so you can do the |
I wouldn't call that the primary reason, my primary concern was platform compatibility. Being able to do the
I was unaware of this. It seems like @neo7-studio-web has a similar concern though? @neo7-studio-web does that relate to astro itself being deployed on vercel or just some other functions being deployed there? All of that said I think honoring |
Yes it does relate to Astro. The moment I implemented ViewTransitions with Astro, all my Vercel serverless functions crashed because of the change of enctype of the forms. For me, explicitly removing ViewTransition for each form worked. But I struggled to understand what happened until I found your post here (thanks BTW).
I agree. And I think this case should be documented in the ViewTransition chapter as a warning, because anyone with forms could encounter a variety of problems because of the enctype. |
yes and in https://docs.astro.build/en/recipes/build-forms/ as already suggested in #9368. |
@knpwrs do you want to provide a PR for this issue? |
I'll be able to look into that tonight 👍🏻 |
Great! Thank you very much! |
I wanted to follow up on this. With Astro 5 on the horizon is the Astro team going to bring the default options to be more in alignment with the browser-standard behavior? |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
When submitting a form with
method="POST"
with the<ViewTransitions />
component, Astro submits the form asContent-Type: multipart/form-data
, whereas the browser default behavior without JavaScript is to submit asContent-Type: application/x-www-form-urlencoded
.In the linked repo, I have the server log out
await Astro.request.text()
on the server side. It looks like this:When you disable JavaScript, or just do this same thing on a non-astro project, the log looks like this:
See also the request header with JavaScript enabled:
Vs JavaScript disabled:
What's the expected result?
The
ViewTransitions
progressive enhancement should submit forms asContent-Type: application/x-www-form-urlencoded
.Here is where Remix handles this in their codebase: https://github.com/remix-run/remix/blob/e26ddc724e78b9cf48110cd4f854516a7f1a87a2/packages/remix-react/data.ts#L95
Note that it might be hard to disable JavaScript while using StackBlitz. The easiest way to reproduce this bug is to clone the repo locally: https://github.com/knpwrs/astro-view-transition-post-bug
Link to Minimal Reproducible Example
https://stackblitz.com/~/github.com/knpwrs/astro-view-transition-post-bug
Participation
The text was updated successfully, but these errors were encountered: