Skip to content

Commit f96f89f

Browse files
committed
Scaffolding for requestFormReset API
This sets adds a new ReactDOM export called requestFormReset, including setting up the export and creating a method on the internal ReactDOM dispatcher. It does not yet add any implementation. Doing this in its own commit for review purposes. The API itself is explained in the next commit.
1 parent 562f9c9 commit f96f89f

15 files changed

+38
-2
lines changed

packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ import {listenToAllSupportedEvents} from '../events/DOMPluginEventSystem';
102102
import {validateLinkPropsForStyleResource} from '../shared/ReactDOMResourceValidation';
103103
import escapeSelectorAttributeValueInsideDoubleQuotes from './escapeSelectorAttributeValueInsideDoubleQuotes';
104104
import {flushSyncWork as flushSyncWorkOnAllRoots} from 'react-reconciler/src/ReactFiberWorkLoop';
105+
import {requestFormReset as requestFormResetOnFiber} from 'react-reconciler/src/ReactFiberHooks';
105106

106107
import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals';
107108

@@ -1928,6 +1929,7 @@ ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */ = {
19281929
f /* flushSyncWork */: disableLegacyMode
19291930
? flushSyncWork
19301931
: previousDispatcher.f /* flushSyncWork */,
1932+
r: requestFormReset,
19311933
D /* prefetchDNS */: prefetchDNS,
19321934
C /* preconnect */: preconnect,
19331935
L /* preload */: preload,
@@ -1951,6 +1953,17 @@ function flushSyncWork() {
19511953
}
19521954
}
19531955

1956+
function requestFormReset(form: HTMLFormElement) {
1957+
previousDispatcher.r(/* requestFormReset */ form);
1958+
const formInst = getInstanceFromNodeDOMTree(form);
1959+
if (formInst !== null) {
1960+
requestFormResetOnFiber(formInst);
1961+
} else {
1962+
// TODO: What if none of the dispatchers find a matching form instance?
1963+
// Should we detect this in dev and warn?
1964+
}
1965+
}
1966+
19541967
// We expect this to get inlined. It is a function mostly to communicate the special nature of
19551968
// how we resolve the HoistableRoot for ReactDOM.pre*() methods. Because we support calling
19561969
// these methods outside of render there is no way to know which Document or ShadowRoot is 'scoped'

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const previousDispatcher =
2828
ReactDOMSharedInternals.d; /* ReactDOMCurrentDispatcher */
2929
ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */ = {
3030
f /* flushSyncWork */: previousDispatcher.f /* flushSyncWork */,
31+
r /* requestFormReset */: previousDispatcher.r /* requestFormReset */,
3132
D /* prefetchDNS */: prefetchDNS,
3233
C /* preconnect */: preconnect,
3334
L /* preload */: preload,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ const previousDispatcher =
8888
ReactDOMSharedInternals.d; /* ReactDOMCurrentDispatcher */
8989
ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */ = {
9090
f /* flushSyncWork */: previousDispatcher.f /* flushSyncWork */,
91+
r /* requestFormReset */: previousDispatcher.r /* requestFormReset */,
9192
D /* prefetchDNS */: prefetchDNS,
9293
C /* preconnect */: preconnect,
9394
L /* preload */: preload,

packages/react-dom-bindings/src/shared/ReactDOMFormActions.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import type {Awaited} from 'shared/ReactTypes';
1212

1313
import {enableAsyncActions} from 'shared/ReactFeatureFlags';
1414
import ReactSharedInternals from 'shared/ReactSharedInternals';
15+
import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals';
1516

1617
type FormStatusNotPending = {|
1718
pending: false,
@@ -87,3 +88,8 @@ export function useFormState<S, P>(
8788
return dispatcher.useFormState(action, initialState, permalink);
8889
}
8990
}
91+
92+
export function requestFormReset(form: HTMLFormElement) {
93+
ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */
94+
.r(/* requestFormReset */ form);
95+
}

packages/react-dom/index.classic.fb.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export {
2525
unstable_runWithPriority, // DO NOT USE: Temporarily exposed to migrate off of Scheduler.runWithPriority.
2626
useFormStatus,
2727
useFormState,
28+
requestFormReset,
2829
prefetchDNS,
2930
preconnect,
3031
preload,

packages/react-dom/index.experimental.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export {
1717
unstable_runWithPriority, // DO NOT USE: Temporarily exposed to migrate off of Scheduler.runWithPriority.
1818
useFormStatus,
1919
useFormState,
20+
requestFormReset,
2021
prefetchDNS,
2122
preconnect,
2223
preload,

packages/react-dom/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export {
2020
unstable_runWithPriority, // DO NOT USE: Temporarily exposed to migrate off of Scheduler.runWithPriority.
2121
useFormStatus,
2222
useFormState,
23+
requestFormReset,
2324
prefetchDNS,
2425
preconnect,
2526
preload,

packages/react-dom/index.modern.fb.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export {
1616
unstable_runWithPriority, // DO NOT USE: Temporarily exposed to migrate off of Scheduler.runWithPriority.
1717
useFormStatus,
1818
useFormState,
19+
requestFormReset,
1920
prefetchDNS,
2021
preconnect,
2122
preload,

packages/react-dom/index.stable.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export {
1616
unstable_batchedUpdates,
1717
useFormStatus,
1818
useFormState,
19+
requestFormReset,
1920
prefetchDNS,
2021
preconnect,
2122
preload,

packages/react-dom/src/ReactDOMSharedInternals.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ function noop() {}
3131

3232
const DefaultDispatcher: HostDispatcher = {
3333
f /* flushSyncWork */: noop,
34+
r /* requestFormReset */: noop,
3435
D /* prefetchDNS */: noop,
3536
C /* preconnect */: noop,
3637
L /* preload */: noop,

packages/react-dom/src/ReactDOMSharedInternalsFB.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function noop() {}
2727

2828
const DefaultDispatcher: HostDispatcher = {
2929
f /* flushSyncWork */: noop,
30+
r /* requestFormReset */: noop,
3031
D /* prefetchDNS */: noop,
3132
C /* preconnect */: noop,
3233
L /* preload */: noop,

packages/react-dom/src/client/ReactDOM.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export {
4848
export {
4949
useFormStatus,
5050
useFormState,
51+
requestFormReset,
5152
} from 'react-dom-bindings/src/shared/ReactDOMFormActions';
5253

5354
if (__DEV__) {

packages/react-dom/src/client/ReactDOMFB.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export {
4848
export {
4949
useFormStatus,
5050
useFormState,
51+
requestFormReset,
5152
} from 'react-dom-bindings/src/shared/ReactDOMFormActions';
5253

5354
if (__DEV__) {

packages/react-dom/src/shared/ReactDOMTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export type PreinitModuleScriptOptions = {
8383

8484
export type HostDispatcher = {
8585
f /* flushSyncWork */: () => boolean | void,
86+
r /* requestFormReset */: (form: HTMLFormElement) => void,
8687
D /* prefetchDNS */: (href: string) => void,
8788
C /* preconnect */: (href: string, crossOrigin?: ?CrossOriginEnum) => void,
8889
L /* preload */: (

packages/react-reconciler/src/ReactFiberHooks.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3008,13 +3008,18 @@ export function startHostTransition<F>(
30083008
// once more of this function is implemented.
30093009
() => {
30103010
// Automatically reset the form when the action completes.
3011-
requestFormReset(formFiber);
3011+
requestFormResetImpl(formFiber);
30123012
return callback(formData);
30133013
},
30143014
);
30153015
}
30163016

3017-
function requestFormReset(formFiber: Fiber) {
3017+
export function requestFormReset(formFiber: Fiber) {
3018+
// TODO: Not yet implemented. Need to upgrade the fiber to be stateful
3019+
// before scheduling the form reset.
3020+
}
3021+
3022+
function requestFormResetImpl(formFiber: Fiber) {
30183023
const transition = requestCurrentTransition();
30193024

30203025
if (__DEV__) {

0 commit comments

Comments
 (0)