GeezerVison is showing github.com — Scaffolding for requestFormReset API (#28808) · react/react-native@374b5d2
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js +19Lines changed: 19 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -102,6 +102,7 @@ import {listenToAllSupportedEvents} from '../events/DOMPluginEventSystem'; | 102 | 102 | import {validateLinkPropsForStyleResource} from '../shared/ReactDOMResourceValidation'; | 103 | 103 | import escapeSelectorAttributeValueInsideDoubleQuotes from './escapeSelectorAttributeValueInsideDoubleQuotes'; | 104 | 104 | import {flushSyncWork as flushSyncWorkOnAllRoots} from 'react-reconciler/src/ReactFiberWorkLoop'; | | 105 | +import {requestFormReset as requestFormResetOnFiber} from 'react-reconciler/src/ReactFiberHooks'; | 105 | 106 |
| 106 | 107 | import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals'; | 107 | 108 |
| @@ -1928,6 +1929,7 @@ ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */ = { | 1928 | 1929 | f /* flushSyncWork */: disableLegacyMode | 1929 | 1930 | ? flushSyncWork | 1930 | 1931 | : previousDispatcher.f /* flushSyncWork */, | | 1932 | + r: requestFormReset, | 1931 | 1933 | D /* prefetchDNS */: prefetchDNS, | 1932 | 1934 | C /* preconnect */: preconnect, | 1933 | 1935 | L /* preload */: preload, | @@ -1951,6 +1953,23 @@ function flushSyncWork() { | 1951 | 1953 | } | 1952 | 1954 | } | 1953 | 1955 |
| | 1956 | +function requestFormReset(form: HTMLFormElement) { | | 1957 | + const formInst = getInstanceFromNodeDOMTree(form); | | 1958 | + if ( | | 1959 | + formInst !== null && | | 1960 | + formInst.tag === HostComponent && | | 1961 | + formInst.type === 'form' | | 1962 | + ) { | | 1963 | + requestFormResetOnFiber(formInst); | | 1964 | + } else { | | 1965 | + // This form was either not rendered by this React renderer (or it's an | | 1966 | + // invalid type). Try the next one. | | 1967 | + // | | 1968 | + // The last implementation in the sequence will throw an error. | | 1969 | + previousDispatcher.r(/* requestFormReset */ form); | | 1970 | + } | | 1971 | +} | | 1972 | + | 1954 | 1973 | // We expect this to get inlined. It is a function mostly to communicate the special nature of | 1955 | 1974 | // how we resolve the HoistableRoot for ReactDOM.pre*() methods. Because we support calling | 1956 | 1975 | // these methods outside of render there is no way to know which Document or ShadowRoot is 'scoped' | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom-bindings/src/server/ReactDOMFlightServerHostDispatcher.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -28,6 +28,7 @@ const previousDispatcher = | 28 | 28 | ReactDOMSharedInternals.d; /* ReactDOMCurrentDispatcher */ | 29 | 29 | ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */ = { | 30 | 30 | f /* flushSyncWork */: previousDispatcher.f /* flushSyncWork */, | | 31 | + r /* requestFormReset */: previousDispatcher.r /* requestFormReset */, | 31 | 32 | D /* prefetchDNS */: prefetchDNS, | 32 | 33 | C /* preconnect */: preconnect, | 33 | 34 | L /* preload */: preload, | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom-bindings/src/server/ReactFizzConfigDOM.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -88,6 +88,7 @@ const previousDispatcher = | 88 | 88 | ReactDOMSharedInternals.d; /* ReactDOMCurrentDispatcher */ | 89 | 89 | ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */ = { | 90 | 90 | f /* flushSyncWork */: previousDispatcher.f /* flushSyncWork */, | | 91 | + r /* requestFormReset */: previousDispatcher.r /* requestFormReset */, | 91 | 92 | D /* prefetchDNS */: prefetchDNS, | 92 | 93 | C /* preconnect */: preconnect, | 93 | 94 | L /* preload */: preload, | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom-bindings/src/shared/ReactDOMFormActions.js +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -12,6 +12,7 @@ import type {Awaited} from 'shared/ReactTypes'; | 12 | 12 |
| 13 | 13 | import {enableAsyncActions} from 'shared/ReactFeatureFlags'; | 14 | 14 | import ReactSharedInternals from 'shared/ReactSharedInternals'; | | 15 | +import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals'; | 15 | 16 |
| 16 | 17 | type FormStatusNotPending = {| | 17 | 18 | pending: false, | @@ -87,3 +88,8 @@ export function useFormState<S, P>( | 87 | 88 | return dispatcher.useFormState(action, initialState, permalink); | 88 | 89 | } | 89 | 90 | } | | 91 | + | | 92 | +export function requestFormReset(form: HTMLFormElement) { | | 93 | + ReactDOMSharedInternals.d /* ReactDOMCurrentDispatcher */ | | 94 | + .r(/* requestFormReset */ form); | | 95 | +} |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/index.classic.fb.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -25,6 +25,7 @@ export { | 25 | 25 | unstable_runWithPriority, // DO NOT USE: Temporarily exposed to migrate off of Scheduler.runWithPriority. | 26 | 26 | useFormStatus, | 27 | 27 | useFormState, | | 28 | + requestFormReset, | 28 | 29 | prefetchDNS, | 29 | 30 | preconnect, | 30 | 31 | preload, | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/index.experimental.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -17,6 +17,7 @@ export { | 17 | 17 | unstable_runWithPriority, // DO NOT USE: Temporarily exposed to migrate off of Scheduler.runWithPriority. | 18 | 18 | useFormStatus, | 19 | 19 | useFormState, | | 20 | + requestFormReset, | 20 | 21 | prefetchDNS, | 21 | 22 | preconnect, | 22 | 23 | preload, | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/index.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -20,6 +20,7 @@ export { | 20 | 20 | unstable_runWithPriority, // DO NOT USE: Temporarily exposed to migrate off of Scheduler.runWithPriority. | 21 | 21 | useFormStatus, | 22 | 22 | useFormState, | | 23 | + requestFormReset, | 23 | 24 | prefetchDNS, | 24 | 25 | preconnect, | 25 | 26 | preload, | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/index.modern.fb.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,6 +16,7 @@ export { | 16 | 16 | unstable_runWithPriority, // DO NOT USE: Temporarily exposed to migrate off of Scheduler.runWithPriority. | 17 | 17 | useFormStatus, | 18 | 18 | useFormState, | | 19 | + requestFormReset, | 19 | 20 | prefetchDNS, | 20 | 21 | preconnect, | 21 | 22 | preload, | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/index.stable.js +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -16,6 +16,7 @@ export { | 16 | 16 | unstable_batchedUpdates, | 17 | 17 | useFormStatus, | 18 | 18 | useFormState, | | 19 | + requestFormReset, | 19 | 20 | prefetchDNS, | 20 | 21 | preconnect, | 21 | 22 | preload, | |
Collapse file Copy file name to clipboardExpand all lines: packages/react-dom/src/ReactDOMSharedInternals.js +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -29,8 +29,16 @@ export type ReactDOMInternalsDev = ReactDOMInternals & { | 29 | 29 |
| 30 | 30 | function noop() {} | 31 | 31 |
| | 32 | +function requestFormReset(element: HTMLFormElement) { | | 33 | + throw new Error( | | 34 | + 'Invalid form element. requestFormReset must be passed a form that was ' + | | 35 | + 'rendered by React.', | | 36 | + ); | | 37 | +} | | 38 | + | 32 | 39 | const DefaultDispatcher: HostDispatcher = { | 33 | 40 | f /* flushSyncWork */: noop, | | 41 | + r /* requestFormReset */: requestFormReset, | 34 | 42 | D /* prefetchDNS */: noop, | 35 | 43 | C /* preconnect */: noop, | 36 | 44 | L /* preload */: noop, | |
|