Replies: 5 comments 11 replies
-
I'm 100% with you here. In addition, to enforce PE, we should make it so all our tests run with and without JavaScript, in order to make sure we stay as close as possible to the platform. Just like you did in your PR 👌 |
Beta Was this translation helpful? Give feedback.
-
Whilst I do see the "progressive enhancement" advantage, I'm not sure if it's Remix biggest selling point. To me, the biggest selling point is that Remix offers an amazing way of building fullstack React apps with ease. And it of course benefits from the fact that many browser defaults and standards are embraced instead of reinvented. This leads to less new APIs that must be learned and used correctly. But I think, it's always great if frameworks offer simple solutions to common problems. And having forms that should update or delete something (rather than create) is a very common problem. I personally prefer the ergonomics of I prefer having solutions like this: <Form method="delete">
<button>Delete</button>
</Form>
export async function action({request}) {
if (request.method === 'DELETE') {
// ...
}
} over solutions like this: <Form method="post">
<input type="hidden" name="_method" value="delete" />
<button>Delete</button>
</Form>
export async function action({request}) {
const data = await request.formData();
const method = data.get('_method');
if (method === 'delete') {
// ...
}
} For me, a major reason for choosing one framework over another is how easy it is to solve common problems. If "being closer to the spec" actually leads to more work or makes things more complicated, I don't see that as an advantage. After all, there is a reason why I'm using a framework instead of raw HTML, CSS & JS. |
Beta Was this translation helpful? Give feedback.
-
An alternative approach we might consider would be offer "native" support for these other methods, taking a page from Rails' form helpers. The basic idea is this:
Potential gotchas:
|
Beta Was this translation helpful? Give feedback.
-
One more wrinkle I've just discovered with the existing let el = document.createElement("button")
el.formMethod = "put"
el.formMethod
// 'get' So although put/patch/delete methods are ergonomic, that's another strike against them. |
Beta Was this translation helpful? Give feedback.
-
Opened a PR here |
Beta Was this translation helpful? Give feedback.
-
[Edited to include a second proposal]
Spawned from a discussion on this PR.
One of Remix' big selling points is progressive enhancement.
<Form>
s and<Link>
s enhance the behavior of<form>
s and<a>
s such that they can work identically without / before JavaScript. Occasionally there are discrepancies, but usually they are oversights rather than intentional departures from the spec.One exception to this is how
<Form>
'smethod
can be any HTTP verb, whereas a native<form>
is more strict. Although the docs mildly discourage it being used for values other that get/post, it's easy to miss. The risk in using it is a broken user experience if a form is submitted before/without JavaScript. A safer approach would be to use a form data entry to signal branching logic (e.g. submit buttons or hidden inputs with names likeintent
/action
/_method
/etc.)I propose we either:
Deprecate the usage of non get/post values, i.e. 1. emit a warning if they are used in dev mode and 2. discourage them more forcefully in the docs. Disallowing them entirely would be a breaking change, though perhaps that could be considered down the road for a major release.
Polyfill support for these methods for when scripts are missing/pending/disabled, via a special
_method
URL param injected into theaction
URL (details here)Beta Was this translation helpful? Give feedback.
All reactions