[react-dom] Fix HTML spec violation in useFormStatus: submitter formMethod ignored (#33361) #33387
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes a bug where the
formmethod
attribute on submit buttons was not properly overriding the parent form's method when accessed through theuseFormStatus
hook.Problem:
When a submit button has a
formMethod
attribute (e.g.,<button formMethod="post">
), it should override the parent form's method attribute. However, useFormStatus did not reflect this override and continued to return the form’s original method, even though the HTML specification states that formmethod on the submitter should take precedence — with or without formaction.Reproducible Demo:
You can reproduce the bug with this sandbox:
https://codesandbox.io/p/sandbox/react-dev-forked-ks99yw
This demonstrates that
useFormStatus
does not reflect theformMethod
override from the submit button.Solution:
createPendingFormStatus
helper functionformMethod
attribute on the submitter elementuseFormStatus
accurately reflects the overridden formmethodFormActionEventPlugin
for better maintainabilityThis change aligns React's behavior with the HTML specification for form submissions.
How did you test this change?
Added comprehensive test cases:
Test 1:
formMethod on submit button overrides form method in useFormStatus
formMethod="post"
Test 2:
submitter's formMethod overrides the form method
method="dialog"
)formMethod="post"
Test execution:
Results:
Manual verification:
Fixes #33361