Repository navigation
Conversation
In HTML forms, form controls with name="action" (such as <button name="action">
or <input name="action">) shadow the form.action DOM property via named
element getters on HTMLFormElement.
In listenToFormSubmissionsForReplaying, checking `let action = form.action`
caused `action` to evaluate to the shadowing element instead of the form's
action URL string. Consequently, the check against EXPECTED_FORM_ACTION_URL
failed, event.preventDefault() was never called, and the submission was not
queued in $$reactFormReplay.
Fix this by reading `form.getAttribute('action')` instead of `form.action`,
matching how `submitter.getAttribute('formAction')` is already read.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Fixes #37837
In HTML forms, form controls with
name="action"(such as<button name="action">or<input name="action">) shadow theform.actionDOM property via named element getters onHTMLFormElement.In
listenToFormSubmissionsForReplaying(ReactDOMFizzInstructionSetShared.js),let action = form.actioncausedactionto evaluate to the shadowing element instead of the form's action URL string. As a result:action !== EXPECTED_FORM_ACTION_URLevaluated totrue.event.preventDefault()was never called.root['$$reactFormReplay'].javascript:placeholder URL, throwingUncaught Error: React form unexpectedly submitted.This PR updates
listenToFormSubmissionsForReplayingto readform.getAttribute('action')instead ofform.action. This matches howsubmitter.getAttribute('formAction')is already handled and avoids named property shadowing.The compiled instruction string in
ReactDOMFizzInstructionSetInlineCodeStrings.jswas updated viayarn generate-inline-fizz-runtime.How did you test this change?
packages/react-dom/src/__tests__/ReactDOMFizzForm-test.js:should replay a form action after hydration when a field is named "action"should replay a form action after hydration when a button is named "action"Navigate to: [object HTMLButtonElement]/[object HTMLInputElement], and with the fix, all 17 tests inReactDOMFizzForm-test.jspass in both development and production (yarn test --prod ReactDOMFizzForm-test.js).yarn test packages/react-dom/src/__tests__/ReactDOMForm-test.js(45 passed).yarn linc(0 errors).