-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
<Form> submitter is serialized out of tree order #4342
Comments
On a related note, For example, given: Probably worth lumping in to this bug report, as the root cause is the same, and the fix should be too 🤞 |
I found some more differences between how
|
There's a proposal to let you pass a In the meantime we might consider:
|
* Add failing tests for remix-run#4342: * Validate various submitter scenarios (tree order, image submit buttons) * Validate file handling in URL-encoded payloads * Rework all submission tests to run both with and without JavaScript. This way we can better detect/prevent regressions or inconsistencies between how <form> and <Form> work.
Great stuff @jenseng, thanks! |
As a workaround for non-image submitters, you can use a component like so that does some hidden input hijinks: function Button(props: DetailedHTMLProps<ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>) {
const hiddenRef = useRef<HTMLInputElement>(null);
const buttonRef = useRef<HTMLButtonElement>(null);
if ((props.type ?? "submit") === "submit" && props.name) {
return (
<>
<input ref={hiddenRef} type="hidden" name={props.name} value={props.value} disabled />
<button
ref={buttonRef}
{...props}
onClick={(e) => {
hiddenRef.current!.disabled = false;
buttonRef.current!.name = "";
setTimeout(() => {
hiddenRef.current!.disabled = true;
buttonRef.current!.name = props.name!;
});
props.onClick?.(e);
}}
/>
</>
);
} else {
return <button {...props} />;
}
} Since the hijinks are done in the |
* Add failing tests for remix-run#4342: * Validate various submitter scenarios (tree order, image submit buttons) * Validate file handling in URL-encoded payloads * Rework all submission tests to run both with and without JavaScript. This way we can better detect/prevent regressions or inconsistencies between how <form> and <Form> work.
* Add failing tests for remix-run#4342: * Validate various submitter scenarios (tree order, image submit buttons) * Validate file handling in URL-encoded payloads * Rework all submission tests to run both with and without JavaScript. This way we can better detect/prevent regressions or inconsistencies between how <form> and <Form> work.
* Rework all form tests to run both with and without JavaScript. This way we can better detect/prevent regressions or inconsistencies between how <form> and <Form> work. * Dedup and expand form method tests to ensure we cover all supported Form methods and submitter formMethods * Expand coverage around form serialization (tree order, image submit buttons, files in URL-encoded payloads) * Conditionally mark tests as failing (via test.fail): * Non-get/post <Form> methods with JavaScript disabled (remix-run#4420) * Form serialization problems with JavaScript enabled (remix-run#4342)
* Rework all form tests to run both with and without JavaScript. This way we can better detect/prevent regressions or inconsistencies between how <form> and <Form> work. * Dedupe and expand form method tests to ensure we cover all supported Form methods and submitter formMethods * Expand coverage around form serialization (tree order, image submit buttons, files in URL-encoded payloads) * Conditionally mark tests as failing (via test.fail): * Non-get/post <Form> methods with JavaScript disabled (#4420) * Form serialization problems with JavaScript enabled (#4342)
Thank you for the detailed use cases and spec references @jenseng - these are incredibly helpful 🙌 |
Bring `<Form>` submissions in line with the spec with respect to File entries in url-encoded payloads: send the `name` as the value. References: remix-run#4342 Spec: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#convert-to-a-list-of-name-value-pairs
Bring `<Form>` submissions in line with the spec with respect to how and where form submitters are serialized within the data set: 1. Ensure they are serialized in tree order (i.e. where they appear in the DOM) 2. Ensure image inputs are serialized correctly (i.e. separate x and y coordinate entries, rather than a single empty entry) 3. Don't send multiple entries in older WebKit References: remix-run#4342 Spec: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#constructing-form-data-set
Bring `<Form>` submissions in line with the spec with respect to File entries in url-encoded payloads: send the `name` as the value. References: remix-run#4342 Spec: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#convert-to-a-list-of-name-value-pairs
Bring `<Form>` submissions in line with the spec with respect to how and where form submitters are serialized within the data set. We accomplish this by temporarily tweaking the form during submission to get the right entries. Problems fixed: 1. Serialize submitters in tree order (i.e. where they appear in the DOM) 2. Serialize Image Button submitter correctly (i.e. separate x and y coordinate entries, rather than a single empty entry) 3. Stop sending multiple entries in older WebKit References: remix-run#4342 Spec: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#constructing-form-data-set
Bring `<Form>` submissions in line with the spec with respect to how and where form submitters are serialized within the data set. We accomplish this by constructing the form data set ourselves according to the spec. Problems fixed: 1. Serialize submitters in tree order (i.e. where they appear in the DOM) 2. Serialize Image Button submitter correctly (i.e. separate x and y coordinate entries, rather than a single empty entry) 3. Stop sending multiple entries in older WebKit References: remix-run#4342 Spec: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#constructing-form-data-set
Bring `<Form>` submissions in line with the spec with respect to how and where form submitters are serialized within the data set. We accomplish this by constructing the form data set ourselves according to the spec. Problems fixed: 1. Serialize submitters in tree order (i.e. where they appear in the DOM) 2. Serialize Image Button submitter correctly (i.e. separate x and y coordinate entries, rather than a single empty entry) 3. Stop sending multiple entries in older WebKit References: remix-run#4342 Spec: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#constructing-form-data-set
Bring `<Form>` submissions in line with the spec with respect to how and where form submitters are serialized within the data set. We accomplish this by constructing the form data set ourselves according to the spec. Problems fixed: 1. Serialize submitters in tree order (i.e. where they appear in the DOM) 2. Serialize Image Button submitter correctly (i.e. separate x and y coordinate entries, rather than a single empty entry) 3. Stop sending multiple entries in older WebKit References: remix-run#4342 Spec: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#constructing-form-data-set
Bring `<Form>` submissions in line with the spec with respect to how and where form submitters are serialized within the data set. We accomplish this by temporarily tweaking the form during submission to get the right entries. Problems fixed: 1. Serialize submitters in tree order (i.e. where they appear in the DOM) 2. Serialize Image Button submitter correctly (i.e. separate x and y coordinate entries, rather than a single empty entry) 3. Stop sending multiple entries in older WebKit References: remix-run#4342 Spec: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#constructing-form-data-set
Bring `<Form>` submissions in line with the spec with respect to File entries in url-encoded payloads: send the `name` as the value. References: remix-run#4342 Spec: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#convert-to-a-list-of-name-value-pairs
Bring `<Form>` submissions in line with the spec with respect to how and where form submitters are serialized within the data set. We accomplish this by temporarily tweaking the form during submission to get the right entries. Problems fixed: 1. Serialize submitters in tree order (i.e. where they appear in the DOM) 2. Serialize Image Button submitter correctly (i.e. separate x and y coordinate entries, rather than a single empty entry) 3. Stop sending multiple entries in older WebKit References: remix-run#4342 Spec: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#constructing-form-data-set
Bring `<Form>` submissions in line with the spec with respect to how and where form submitters are serialized within the data set. We accomplish this by constructing the form data set ourselves according to the spec. Problems fixed: 1. Serialize submitters in tree order (i.e. where they appear in the DOM) 2. Serialize Image Button submitter correctly (i.e. separate x and y coordinate entries, rather than a single empty entry) 3. Stop sending multiple entries in older WebKit References: remix-run#4342 Spec: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#constructing-form-data-set
Bring `<Form>` submissions in line with the spec with respect to File entries in url-encoded payloads: send the `name` as the value. References: remix-run#4342 Spec: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#convert-to-a-list-of-name-value-pairs
Bring `<Form>` submissions in line with the spec with respect to File entries in url-encoded payloads: send the `name` as the value. References: remix-run#4342 Spec: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#convert-to-a-list-of-name-value-pairs
Bring `<Form>` submissions in line with the spec with respect to File entries in url-encoded payloads: send the `name` as the value. References: remix-run#4342 Spec: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#convert-to-a-list-of-name-value-pairs
* Rework all form tests to run both with and without JavaScript. This way we can better detect/prevent regressions or inconsistencies between how <form> and <Form> work. * Dedupe and expand form method tests to ensure we cover all supported Form methods and submitter formMethods * Expand coverage around form serialization (tree order, image submit buttons, files in URL-encoded payloads) * Conditionally mark tests as failing (via test.fail): * Non-get/post <Form> methods with JavaScript disabled (#4420) * Form serialization problems with JavaScript enabled (#4342)
This is the RR port of remix-run/remix#4475 Bring `<Form>` submissions in line with the spec with respect to how and where form submitters are serialized within the data set. We accomplish this by constructing the form data set ourselves according to the spec. Problems fixed: 1. Serialize submitters in tree order (i.e. where they appear in the DOM) 2. Serialize Image Button submitter correctly (i.e. separate x and y coordinate entries, rather than a single empty entry) 3. Stop sending multiple entries in older WebKit References: remix-run/remix#4342 Spec: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#constructing-form-data-set
This is the RR port of remix-run/remix#4473 Bring FormData serialization in line with the spec with respect to File entries in url-encoded payloads: send the `name` as the value, as is the case with a vanilla `<form>` submission. Rework various 400-error tests not to rely on the old behavior, as it's no longer a bad request :) References: remix-run/remix#4342 Spec: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#convert-to-a-list-of-name-value-pairs
This is the RR port of remix-run/remix#4473 Bring FormData serialization in line with the spec with respect to File entries in url-encoded payloads: send the `name` as the value, as is the case with a vanilla `<form>` submission. Rework various 400-error tests not to rely on the old behavior, as it's no longer a bad request :) References: remix-run/remix#4342 Spec: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#convert-to-a-list-of-name-value-pairs
I think this should be resolved when we release Remix |
What version of Remix are you using?
1.7.2
Steps to Reproduce
<Form>
like so:Expected Behavior
The form fields should be serialized in tree order, i.e.
foo=override&foo=default
(as is the case with a vanilla<form>
).See Constructing the form data set in the HTML spec. Submitted fields should be sent in the order they appear in the DOM, including the
submitter
(i.e. the submit button that was clicked).Actual Behavior
The form is serialized as
foo=default&foo=override
.This is problematic on the server-side if you are relying on the order to indicate precedence.
formData.get("foo")
will yield different values, depending on whether the form was submitted by Remix or native browser behavior.See also #3611; prior to that fix it was broken in a different way (it would only serialize
foo=default
)The text was updated successfully, but these errors were encountered: