Skip to content

Commit ef63718

Browse files
authored
Remove enableAsyncActions (#31757)
Based on #31756 This is landed everywhere
1 parent fb12845 commit ef63718

27 files changed

+394
-685
lines changed

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

+4-17
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-debug-tools/src/__tests__/ReactHooksInspectionIntegration-test.js

-2
Original file line numberDiff line numberDiff line change
@@ -2581,7 +2581,6 @@ describe('ReactHooksInspectionIntegration', () => {
25812581
`);
25822582
});
25832583

2584-
// @gate enableAsyncActions
25852584
it('should support useOptimistic hook', async () => {
25862585
const useOptimistic = React.useOptimistic;
25872586
function Foo() {
@@ -2647,7 +2646,6 @@ describe('ReactHooksInspectionIntegration', () => {
26472646
`);
26482647
});
26492648

2650-
// @gate enableAsyncActions
26512649
it('should support useActionState hook', async () => {
26522650
function Foo() {
26532651
const [value] = React.useActionState(function increment(n) {

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ import {
9191
enableCreateEventHandleAPI,
9292
enableScopeAPI,
9393
enableTrustedTypesIntegration,
94-
enableAsyncActions,
9594
disableLegacyMode,
9695
enableMoveBefore,
9796
} from 'shared/ReactFeatureFlags';
@@ -1378,9 +1377,8 @@ function getNextHydratable(node: ?Node) {
13781377
nodeData === SUSPENSE_START_DATA ||
13791378
nodeData === SUSPENSE_FALLBACK_START_DATA ||
13801379
nodeData === SUSPENSE_PENDING_START_DATA ||
1381-
(enableAsyncActions &&
1382-
(nodeData === FORM_STATE_IS_MATCHING ||
1383-
nodeData === FORM_STATE_IS_NOT_MATCHING))
1380+
nodeData === FORM_STATE_IS_MATCHING ||
1381+
nodeData === FORM_STATE_IS_NOT_MATCHING
13841382
) {
13851383
break;
13861384
}

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

+4-15
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import type {Dispatcher} from 'react-reconciler/src/ReactInternalTypes';
1111
import type {Awaited} from 'shared/ReactTypes';
1212

13-
import {enableAsyncActions} from 'shared/ReactFeatureFlags';
1413
import ReactSharedInternals from 'shared/ReactSharedInternals';
1514
import ReactDOMSharedInternals from 'shared/ReactDOMSharedInternals';
1615

@@ -66,27 +65,17 @@ function resolveDispatcher() {
6665
}
6766

6867
export function useFormStatus(): FormStatus {
69-
if (!enableAsyncActions) {
70-
throw new Error('Not implemented.');
71-
} else {
72-
const dispatcher = resolveDispatcher();
73-
// $FlowFixMe[not-a-function] We know this exists because of the feature check above.
74-
return dispatcher.useHostTransitionStatus();
75-
}
68+
const dispatcher = resolveDispatcher();
69+
return dispatcher.useHostTransitionStatus();
7670
}
7771

7872
export function useFormState<S, P>(
7973
action: (Awaited<S>, P) => S,
8074
initialState: Awaited<S>,
8175
permalink?: string,
8276
): [Awaited<S>, (P) => void, boolean] {
83-
if (!enableAsyncActions) {
84-
throw new Error('Not implemented.');
85-
} else {
86-
const dispatcher = resolveDispatcher();
87-
// $FlowFixMe[not-a-function] This is unstable, thus optional
88-
return dispatcher.useFormState(action, initialState, permalink);
89-
}
77+
const dispatcher = resolveDispatcher();
78+
return dispatcher.useFormState(action, initialState, permalink);
9079
}
9180

9281
export function requestFormReset(form: HTMLFormElement) {

packages/react-dom/src/__tests__/ReactDOMFizzForm-test.js

-3
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,6 @@ describe('ReactDOMFizzForm', () => {
398398
expect(buttonRef.current.hasAttribute('formTarget')).toBe(false);
399399
});
400400

401-
// @gate enableAsyncActions
402401
it('useFormStatus is not pending during server render', async () => {
403402
function App() {
404403
const {pending} = useFormStatus();
@@ -488,7 +487,6 @@ describe('ReactDOMFizzForm', () => {
488487
expect(rootActionCalled).toBe(false);
489488
});
490489

491-
// @gate enableAsyncActions
492490
it('useOptimistic returns passthrough value', async () => {
493491
function App() {
494492
const [optimisticState] = useOptimistic('hi');
@@ -507,7 +505,6 @@ describe('ReactDOMFizzForm', () => {
507505
expect(container.textContent).toBe('hi');
508506
});
509507

510-
// @gate enableAsyncActions
511508
it('useActionState returns initial state', async () => {
512509
async function action(state) {
513510
return state;

packages/react-dom/src/__tests__/ReactDOMFizzServer-test.js

-2
Original file line numberDiff line numberDiff line change
@@ -6330,7 +6330,6 @@ describe('ReactDOMFizzServer', () => {
63306330
expect(getVisibleChildren(container)).toEqual('Hi');
63316331
});
63326332

6333-
// @gate enableAsyncActions
63346333
it('useActionState hydrates without a mismatch', async () => {
63356334
// This is testing an implementation detail: useActionState emits comment
63366335
// nodes into the SSR stream, so this checks that they are handled correctly
@@ -6383,7 +6382,6 @@ describe('ReactDOMFizzServer', () => {
63836382
expect(childRef.current).toBe(child);
63846383
});
63856384

6386-
// @gate enableAsyncActions
63876385
it("useActionState hydrates without a mismatch if there's a render phase update", async () => {
63886386
async function action(state) {
63896387
return state;

packages/react-dom/src/__tests__/ReactDOMForm-test.js

-25
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,6 @@ describe('ReactDOMForm', () => {
669669
expect(actionCalled).toBe(false);
670670
});
671671

672-
// @gate enableAsyncActions
673672
it('form actions are transitions', async () => {
674673
const formRef = React.createRef();
675674

@@ -707,7 +706,6 @@ describe('ReactDOMForm', () => {
707706
expect(container.textContent).toBe('Updated');
708707
});
709708

710-
// @gate enableAsyncActions
711709
it('multiple form actions', async () => {
712710
const formRef = React.createRef();
713711

@@ -798,12 +796,6 @@ describe('ReactDOMForm', () => {
798796
});
799797

800798
it('sync errors in form actions can be captured by an error boundary', async () => {
801-
if (gate(flags => !flags.enableAsyncActions)) {
802-
// TODO: Uncaught JSDOM errors fail the test after the scope has finished
803-
// so don't work with the `gate` mechanism.
804-
return;
805-
}
806-
807799
class ErrorBoundary extends React.Component {
808800
state = {error: null};
809801
static getDerivedStateFromError(error) {
@@ -844,12 +836,6 @@ describe('ReactDOMForm', () => {
844836
});
845837

846838
it('async errors in form actions can be captured by an error boundary', async () => {
847-
if (gate(flags => !flags.enableAsyncActions)) {
848-
// TODO: Uncaught JSDOM errors fail the test after the scope has finished
849-
// so don't work with the `gate` mechanism.
850-
return;
851-
}
852-
853839
class ErrorBoundary extends React.Component {
854840
state = {error: null};
855841
static getDerivedStateFromError(error) {
@@ -895,7 +881,6 @@ describe('ReactDOMForm', () => {
895881
expect(container.textContent).toBe('Oh no!');
896882
});
897883

898-
// @gate enableAsyncActions
899884
it('useFormStatus reads the status of a pending form action', async () => {
900885
const formRef = React.createRef();
901886

@@ -992,7 +977,6 @@ describe('ReactDOMForm', () => {
992977
);
993978
});
994979

995-
// @gate enableAsyncActions
996980
it('useActionState updates state asynchronously and queues multiple actions', async () => {
997981
let actionCounter = 0;
998982
async function action(state, type) {
@@ -1052,7 +1036,6 @@ describe('ReactDOMForm', () => {
10521036
expect(container.textContent).toBe('2');
10531037
});
10541038

1055-
// @gate enableAsyncActions
10561039
it('useActionState supports inline actions', async () => {
10571040
let increment;
10581041
function App({stepSize}) {
@@ -1084,7 +1067,6 @@ describe('ReactDOMForm', () => {
10841067
assertLog(['Pending 1', '11']);
10851068
});
10861069

1087-
// @gate enableAsyncActions
10881070
it('useActionState: dispatch throws if called during render', async () => {
10891071
function App() {
10901072
const [state, dispatch, isPending] = useActionState(async () => {}, 0);
@@ -1100,7 +1082,6 @@ describe('ReactDOMForm', () => {
11001082
});
11011083
});
11021084

1103-
// @gate enableAsyncActions
11041085
it('useActionState: queues multiple actions and runs them in order', async () => {
11051086
let action;
11061087
function App() {
@@ -1132,7 +1113,6 @@ describe('ReactDOMForm', () => {
11321113
expect(container.textContent).toBe('D');
11331114
});
11341115

1135-
// @gate enableAsyncActions
11361116
it(
11371117
'useActionState: when calling a queued action, uses the implementation ' +
11381118
'that was current at the time it was dispatched, not the most recent one',
@@ -1179,7 +1159,6 @@ describe('ReactDOMForm', () => {
11791159
},
11801160
);
11811161

1182-
// @gate enableAsyncActions
11831162
it('useActionState: works if action is sync', async () => {
11841163
let increment;
11851164
function App({stepSize}) {
@@ -1211,7 +1190,6 @@ describe('ReactDOMForm', () => {
12111190
assertLog(['Pending 1', '11']);
12121191
});
12131192

1214-
// @gate enableAsyncActions
12151193
it('useActionState: can mix sync and async actions', async () => {
12161194
let action;
12171195
function App() {
@@ -1239,7 +1217,6 @@ describe('ReactDOMForm', () => {
12391217
expect(container.textContent).toBe('E');
12401218
});
12411219

1242-
// @gate enableAsyncActions
12431220
it('useActionState: error handling (sync action)', async () => {
12441221
class ErrorBoundary extends React.Component {
12451222
state = {error: null};
@@ -1288,7 +1265,6 @@ describe('ReactDOMForm', () => {
12881265
expect(container.textContent).toBe('Caught an error: Oops!');
12891266
});
12901267

1291-
// @gate enableAsyncActions
12921268
it('useActionState: error handling (async action)', async () => {
12931269
class ErrorBoundary extends React.Component {
12941270
state = {error: null};
@@ -1394,7 +1370,6 @@ describe('ReactDOMForm', () => {
13941370
expect(container.textContent).toBe('Caught an error: Oops!');
13951371
});
13961372

1397-
// @gate enableAsyncActions
13981373
it('useActionState works in StrictMode', async () => {
13991374
let actionCounter = 0;
14001375
async function action(state, type) {

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

+2-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import type {
1616
import {isValidContainer} from 'react-dom-bindings/src/client/ReactDOMContainer';
1717
import {queueExplicitHydrationTarget} from 'react-dom-bindings/src/events/ReactDOMEventReplaying';
1818
import {REACT_ELEMENT_TYPE} from 'shared/ReactSymbols';
19-
import {enableAsyncActions} from 'shared/ReactFeatureFlags';
2019

2120
export type RootType = {
2221
render(children: ReactNodeList): void,
@@ -305,10 +304,8 @@ export function hydrateRoot(
305304
if (options.unstable_transitionCallbacks !== undefined) {
306305
transitionCallbacks = options.unstable_transitionCallbacks;
307306
}
308-
if (enableAsyncActions) {
309-
if (options.formState !== undefined) {
310-
formState = options.formState;
311-
}
307+
if (options.formState !== undefined) {
308+
formState = options.formState;
312309
}
313310
}
314311

0 commit comments

Comments
 (0)