Skip to content

Commit c23745d

Browse files
committed
Fixes and Dispatcher type
1 parent 2c82664 commit c23745d

File tree

7 files changed

+22
-31
lines changed

7 files changed

+22
-31
lines changed

packages/react-debug-tools/src/ReactDebugHooks.js

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,22 +104,14 @@ function getPrimitiveStackCache(): Map<string, Array<any>> {
104104
);
105105
Dispatcher.useDeferredValue(null);
106106
Dispatcher.useMemo(() => null);
107+
Dispatcher.useOptimistic(null, (s: mixed, a: mixed) => s);
108+
Dispatcher.useFormState((s: mixed, p: mixed) => s, null);
109+
Dispatcher.useActionState((s: mixed, p: mixed) => s, null);
110+
Dispatcher.useHostTransitionStatus();
107111
if (typeof Dispatcher.useMemoCache === 'function') {
108112
// This type check is for Flow only.
109113
Dispatcher.useMemoCache(0);
110114
}
111-
if (typeof Dispatcher.useOptimistic === 'function') {
112-
// This type check is for Flow only.
113-
Dispatcher.useOptimistic(null, (s: mixed, a: mixed) => s);
114-
}
115-
if (typeof Dispatcher.useFormState === 'function') {
116-
// This type check is for Flow only.
117-
Dispatcher.useFormState((s: mixed, p: mixed) => s, null);
118-
}
119-
if (typeof Dispatcher.useActionState === 'function') {
120-
// This type check is for Flow only.
121-
Dispatcher.useActionState((s: mixed, p: mixed) => s, null);
122-
}
123115
if (typeof Dispatcher.use === 'function') {
124116
// This type check is for Flow only.
125117
Dispatcher.use(
@@ -143,11 +135,6 @@ function getPrimitiveStackCache(): Map<string, Array<any>> {
143135
}
144136

145137
Dispatcher.useId();
146-
147-
if (typeof Dispatcher.useHostTransitionStatus === 'function') {
148-
// This type check is for Flow only.
149-
Dispatcher.useHostTransitionStatus();
150-
}
151138
} finally {
152139
readHookLog = hookLog;
153140
hookLog = [];

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ function resolveDispatcher() {
6666

6767
export function useFormStatus(): FormStatus {
6868
const dispatcher = resolveDispatcher();
69-
// $FlowFixMe[not-a-function] We know this exists because of the feature check above.
7069
return dispatcher.useHostTransitionStatus();
7170
}
7271

@@ -76,7 +75,6 @@ export function useFormState<S, P>(
7675
permalink?: string,
7776
): [Awaited<S>, (P) => void, boolean] {
7877
const dispatcher = resolveDispatcher();
79-
// $FlowFixMe[not-a-function] This is unstable, thus optional
8078
return dispatcher.useFormState(action, initialState, permalink);
8179
}
8280

packages/react-reconciler/src/ReactFiberHooks.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5106,6 +5106,12 @@ if (__DEV__) {
51065106
mountHookTypesDev();
51075107
return mountSyncExternalStore(subscribe, getSnapshot, getServerSnapshot);
51085108
},
5109+
useId(): string {
5110+
currentHookNameInDev = 'useId';
5111+
warnInvalidHookAccess();
5112+
mountHookTypesDev();
5113+
return mountId();
5114+
},
51095115
useFormState<S, P>(
51105116
action: (Awaited<S>, P) => S,
51115117
initialState: Awaited<S>,
@@ -5126,12 +5132,6 @@ if (__DEV__) {
51265132
mountHookTypesDev();
51275133
return mountActionState(action, initialState, permalink);
51285134
},
5129-
useId(): string {
5130-
currentHookNameInDev = 'useId';
5131-
warnInvalidHookAccess();
5132-
mountHookTypesDev();
5133-
return mountId();
5134-
},
51355135
useOptimistic<S, A>(
51365136
passthrough: S,
51375137
reducer: ?(S, A) => S,

packages/react-reconciler/src/ReactInternalTypes.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,17 +448,17 @@ export type Dispatcher = {
448448
useId(): string,
449449
useCacheRefresh?: () => <T>(?() => T, ?T) => void,
450450
useMemoCache?: (size: number) => Array<any>,
451-
useHostTransitionStatus?: () => TransitionStatus,
452-
useOptimistic?: <S, A>(
451+
useHostTransitionStatus: () => TransitionStatus,
452+
useOptimistic: <S, A>(
453453
passthrough: S,
454454
reducer: ?(S, A) => S,
455455
) => [S, (A) => void],
456-
useFormState?: <S, P>(
456+
useFormState: <S, P>(
457457
action: (Awaited<S>, P) => S,
458458
initialState: Awaited<S>,
459459
permalink?: string,
460460
) => [Awaited<S>, (P) => void, boolean],
461-
useActionState?: <S, P>(
461+
useActionState: <S, P>(
462462
action: (Awaited<S>, P) => S,
463463
initialState: Awaited<S>,
464464
permalink?: string,

packages/react-server/src/ReactFizzHooks.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,10 @@ export const HooksDispatcher: Dispatcher = supportsClientAPIs
832832
useId,
833833
// Subscriptions are not setup in a server environment.
834834
useSyncExternalStore,
835+
useOptimistic,
836+
useActionState,
837+
useFormState: useActionState,
838+
useHostTransitionStatus,
835839
}
836840
: {
837841
readContext,

packages/react-server/src/ReactFlightHooks.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ export const HooksDispatcher: Dispatcher = {
7777
useImperativeHandle: (unsupportedHook: any),
7878
useEffect: (unsupportedHook: any),
7979
useId,
80+
useHostTransitionStatus: (unsupportedHook: any),
81+
useOptimistic: (unsupportedHook: any),
82+
useFormState: (unsupportedHook: any),
83+
useActionState: (unsupportedHook: any),
8084
useSyncExternalStore: (unsupportedHook: any),
8185
useCacheRefresh(): <T>(?() => T, ?T) => void {
8286
return unsupportedRefresh;

packages/react/src/ReactHooks.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,6 @@ export function useOptimistic<S, A>(
252252
reducer: ?(S, A) => S,
253253
): [S, (A) => void] {
254254
const dispatcher = resolveDispatcher();
255-
// $FlowFixMe[not-a-function] This is unstable, thus optional
256255
return dispatcher.useOptimistic(passthrough, reducer);
257256
}
258257

@@ -262,6 +261,5 @@ export function useActionState<S, P>(
262261
permalink?: string,
263262
): [Awaited<S>, (P) => void, boolean] {
264263
const dispatcher = resolveDispatcher();
265-
// $FlowFixMe[not-a-function] This is unstable, thus optional
266264
return dispatcher.useActionState(action, initialState, permalink);
267265
}

0 commit comments

Comments
 (0)