Skip to content

Commit e08ebb1

Browse files
committed
Update internal Flow type
Updates our internal Flow type for useFormState to allow for synchronous actions. I tried to make it match what the TypeScript equivalent would be, so although Flow does not include an Awaited type helper, I copied the one from TypeScript and added it to our internal types. Unfortunately this led to a few "Recursion limit exceeded" Flow errors in the Fiber implementation. I wasn't able to figure out whether these were legit type errors, or if the types were correct but the recursiveness of the types tripped some internal limit. But since this only affects the type coverage of our internal implementation and not the public API, I sprinkled in some `any`s and called it a day.
1 parent 50570e8 commit e08ebb1

File tree

8 files changed

+104
-81
lines changed

8 files changed

+104
-81
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
import type {Dispatcher} from 'react-reconciler/src/ReactInternalTypes';
11+
import type {Awaited} from 'shared/ReactTypes';
1112

1213
import {enableAsyncActions, enableFormActions} from 'shared/ReactFeatureFlags';
1314
import ReactSharedInternals from 'shared/ReactSharedInternals';
@@ -76,10 +77,10 @@ export function useFormStatus(): FormStatus {
7677
}
7778

7879
export function useFormState<S, P>(
79-
action: (S, P) => Promise<S>,
80-
initialState: S,
80+
action: (Awaited<S>, P) => S,
81+
initialState: Awaited<S>,
8182
permalink?: string,
82-
): [S, (P) => void] {
83+
): [Awaited<S>, (P) => void] {
8384
if (!(enableFormActions && enableAsyncActions)) {
8485
throw new Error('Not implemented.');
8586
} else {

packages/react-dom/index.experimental.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export {
3131
version,
3232
} from './src/client/ReactDOM';
3333

34+
import type {Awaited} from 'shared/ReactTypes';
3435
import type {FormStatus} from 'react-dom-bindings/src/shared/ReactDOMFormActions';
3536
import {useFormStatus, useFormState} from './src/client/ReactDOM';
3637

@@ -45,10 +46,10 @@ export function experimental_useFormStatus(): FormStatus {
4546
}
4647

4748
export function experimental_useFormState<S, P>(
48-
action: (S, P) => Promise<S>,
49-
initialState: S,
49+
action: (Awaited<S>, P) => S,
50+
initialState: Awaited<S>,
5051
permalink?: string,
51-
): [S, (P) => void] {
52+
): [Awaited<S>, (P) => void] {
5253
if (__DEV__) {
5354
console.error(
5455
'useFormState is now in canary. Remove the experimental_ prefix. ' +

packages/react-dom/server-rendering-stub.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
useFormStatus,
3535
useFormState,
3636
} from './src/server/ReactDOMServerRenderingStub';
37+
import type {Awaited} from 'shared/ReactTypes';
3738

3839
export function experimental_useFormStatus(): FormStatus {
3940
if (__DEV__) {
@@ -46,10 +47,10 @@ export function experimental_useFormStatus(): FormStatus {
4647
}
4748

4849
export function experimental_useFormState<S, P>(
49-
action: (S, P) => Promise<S>,
50-
initialState: S,
50+
action: (Awaited<S>, P) => S,
51+
initialState: Awaited<S>,
5152
permalink?: string,
52-
): [S, (P) => void] {
53+
): [Awaited<S>, (P) => void] {
5354
if (__DEV__) {
5455
console.error(
5556
'useFormState is now in canary. Remove the experimental_ prefix. ' +

0 commit comments

Comments
 (0)