Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ function extractEvents(
}
const formInst = maybeTargetInst;
const form: HTMLFormElement = (nativeEventTarget: any);
let action = coerceFormActionProp(
(getFiberCurrentPropsFromNode(form): any).action,
);
const formProps = (getFiberCurrentPropsFromNode(form): any);
let action = coerceFormActionProp(formProps.action);
const autoReset: boolean = formProps.autoReset !== false;
let submitter: null | void | HTMLInputElement | HTMLButtonElement =
(nativeEvent: any).submitter;
let submitterAction;
Expand Down Expand Up @@ -124,6 +124,7 @@ function extractEvents(
// the action.
null,
formData,
autoReset,
);
} else {
// No earlier event scheduled a transition. Exit without setting a
Expand All @@ -144,7 +145,7 @@ function extractEvents(
if (__DEV__) {
Object.freeze(pendingState);
}
startHostTransition(formInst, pendingState, action, formData);
startHostTransition(formInst, pendingState, action, formData, autoReset);
} else {
// No earlier event prevented the default submission, and no action was
// provided. Exit without setting a pending form status.
Expand Down Expand Up @@ -180,5 +181,7 @@ export function dispatchReplayedFormAction(
if (__DEV__) {
Object.freeze(pendingState);
}
startHostTransition(formInst, pendingState, action, formData);
const autoReset: boolean =
(getFiberCurrentPropsFromNode(form): any).autoReset !== false;
startHostTransition(formInst, pendingState, action, formData, autoReset);
}
7 changes: 5 additions & 2 deletions packages/react-reconciler/src/ReactFiberHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3240,6 +3240,7 @@ export function startHostTransition<F>(
pendingState: TransitionStatus,
action: (F => mixed) | null,
formData: F,
autoReset: boolean = true,
): void {
if (formFiber.tag !== HostComponent) {
throw new Error(
Expand Down Expand Up @@ -3271,8 +3272,10 @@ export function startHostTransition<F>(
// set the pending form status.
noop
: () => {
// Automatically reset the form when the action completes.
requestFormReset(formFiber);
if (autoReset) {
// Automatically reset the form when the action completes.
requestFormReset(formFiber);
}
return action(formData);
},
);
Expand Down