Skip to content

Commit 677848b

Browse files
committed
Check for nullish values on ReactCustomFormAction
Usually we don't have to do this since we only set these in the loop but the ReactCustomFormAction props are optional so they might be undefined. Also moved it to a general type since it's a semi-public API.
1 parent 388686f commit 677848b

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @flow
88
*/
99

10-
import type {ReactNodeList} from 'shared/ReactTypes';
10+
import type {ReactNodeList, ReactCustomFormAction} from 'shared/ReactTypes';
1111

1212
import {
1313
checkHtmlStringCoercion,
@@ -668,15 +668,6 @@ function pushStringAttribute(
668668
}
669669
}
670670

671-
type CustomFormAction = {
672-
name?: string,
673-
action?: string,
674-
encType?: string,
675-
method?: string,
676-
target?: string,
677-
data?: FormData,
678-
};
679-
680671
function makeFormFieldPrefix(responseState: ResponseState): string {
681672
// I'm just reusing this counter. It's not really the same namespace as "name".
682673
// It could just be its own counter.
@@ -761,7 +752,7 @@ function pushFormActionAttribute(
761752
);
762753
}
763754
}
764-
const customAction: CustomFormAction = formAction.$$FORM_ACTION;
755+
const customAction: ReactCustomFormAction = formAction.$$FORM_ACTION;
765756
if (typeof customAction === 'function') {
766757
// This action has a custom progressive enhancement form that can submit the form
767758
// back to the server if it's invoked before hydration. Such as a Server Action.
@@ -794,19 +785,19 @@ function pushFormActionAttribute(
794785
injectFormReplayingRuntime(responseState);
795786
}
796787
}
797-
if (name !== null) {
788+
if (name != null) {
798789
pushAttribute(target, 'name', name);
799790
}
800-
if (formAction !== null) {
791+
if (formAction != null) {
801792
pushAttribute(target, 'formAction', formAction);
802793
}
803-
if (formEncType !== null) {
794+
if (formEncType != null) {
804795
pushAttribute(target, 'formEncType', formEncType);
805796
}
806-
if (formMethod !== null) {
797+
if (formMethod != null) {
807798
pushAttribute(target, 'formMethod', formMethod);
808799
}
809-
if (formTarget !== null) {
800+
if (formTarget != null) {
810801
pushAttribute(target, 'formTarget', formTarget);
811802
}
812803
return formData;
@@ -1455,7 +1446,7 @@ function pushStartForm(
14551446
);
14561447
}
14571448
}
1458-
const customAction: CustomFormAction = formAction.$$FORM_ACTION;
1449+
const customAction: ReactCustomFormAction = formAction.$$FORM_ACTION;
14591450
if (typeof customAction === 'function') {
14601451
// This action has a custom progressive enhancement form that can submit the form
14611452
// back to the server if it's invoked before hydration. Such as a Server Action.
@@ -1487,16 +1478,16 @@ function pushStartForm(
14871478
injectFormReplayingRuntime(responseState);
14881479
}
14891480
}
1490-
if (formAction !== null) {
1481+
if (formAction != null) {
14911482
pushAttribute(target, 'action', formAction);
14921483
}
1493-
if (formEncType !== null) {
1484+
if (formEncType != null) {
14941485
pushAttribute(target, 'encType', formEncType);
14951486
}
1496-
if (formMethod !== null) {
1487+
if (formMethod != null) {
14971488
pushAttribute(target, 'method', formMethod);
14981489
}
1499-
if (formTarget !== null) {
1490+
if (formTarget != null) {
15001491
pushAttribute(target, 'target', formTarget);
15011492
}
15021493

packages/shared/ReactTypes.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,3 +217,12 @@ export type StartTransitionOptions = {
217217
};
218218

219219
export type Usable<T> = Thenable<T> | ReactContext<T>;
220+
221+
export type ReactCustomFormAction = {
222+
name?: string,
223+
action?: string,
224+
encType?: string,
225+
method?: string,
226+
target?: string,
227+
data?: null | FormData,
228+
};

0 commit comments

Comments
 (0)