Improve ergonomics of action prop in next/form to align with HTML standards
#73517
Unanswered
ChristianIvicevic
asked this question in
App Router
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Description
Earlier today, I tried out the new
next/formcomponent introduced in Next.js 15, and encountered a minor yet confusing detail regarding theactionprop. In my use case, I wanted to append search parameters to the current route, which required me to setaction="". This approach feels counterintuitive and doesn't align with the common HTML standard, where similar behavior can be achieved using<form method="GET">or even just a basic<form>without an explicitaction.Observations
Upon reviewing the implementation in Next.js, I noticed the explicit usage of the
NonNullabletype in the source code:next.js/packages/next/src/client/form.tsx
Lines 21 to 27 in 0ea736e
This choice makes the
actionprop mandatory, which is not equivalent to the default behavior of standard HTML forms. As a result, developers must explicitly setaction=""to achieve the default behavior, which seems less ergonomic and deviates from common web development conventions.Request for Feedback
I would like to understand the reasoning behind this design choice:
actionprop being mandatory in this case?actionprop optional, thereby aligningnext/formmore closely with the behavior of standard HTML forms?This adjustment could enhance developer experience by reducing confusion and making the API more intuitive.
Suggested Improvements
actionprop optional for thenext/formcomponent.actionprop is omitted, the behavior defaults to appending search parameters to the current route, similar to standard HTML form behavior.Looking forward to your thoughts and any insights from the Next.js team on this matter.
Beta Was this translation helpful? Give feedback.
All reactions