@samitouri / QOS-React / commits / ca237d6f0a

Add back temporary `experimental_` aliases for Server Actions APIs (#27461)

This adds back the `experimental_`-prefixed Server Actions APIs to the experimental builds only, so that apps that use those don't immediately break when upgrading. The APIs will log a warning to encourage people to move to the unprefixed version, or to switch to the canary release channel. We can remove these in a few weeks after we've given people a chance to upgrade. This does not affect the canary builds at all, since they never had the prefixed versions to begin with.

Andrew Clark committed Oct 4, 2023 at 15:58 UTC ca237d6f0ab986e799f192224d3066f76d66b73b
2 files changed +42
packages/react-dom/index.experimental.js
+27
@@ -30,3 +30,30 @@ export {
30 preinitModule,
31 version,
32 } from './src/client/ReactDOM';
33 +
34 +import type {FormStatus} from 'react-dom-bindings/src/shared/ReactDOMFormActions';
35 +import {useFormStatus, useFormState} from './src/client/ReactDOM';
36 +
37 +export function experimental_useFormStatus(): FormStatus {
38 + if (__DEV__) {
39 + console.error(
40 + 'useFormStatus is now in canary. Remove the experimental_ prefix. ' +
41 + 'The prefixed alias will be removed in an upcoming release.',
42 + );
43 + }
44 + return useFormStatus();
45 +}
46 +
47 +export function experimental_useFormState<S, P>(
48 + action: (S, P) => Promise<S>,
49 + initialState: S,
50 + permalink?: string,
51 +): [S, (P) => void] {
52 + if (__DEV__) {
53 + console.error(
54 + 'useFormState is now in canary. Remove the experimental_ prefix. ' +
55 + 'The prefixed alias will be removed in an upcoming release.',
56 + );
57 + }
58 + return useFormState(action, initialState, permalink);
59 +}
packages/react/index.experimental.js
+15
@@ -58,3 +58,18 @@ export {
58 useTransition,
59 version,
60 } from './src/React';
61 +
62 +import {useOptimistic} from './src/React';
63 +
64 +export function experimental_useOptimistic<S, A>(
65 + passthrough: S,
66 + reducer: ?(S, A) => S,
67 +): [S, (A) => void] {
68 + if (__DEV__) {
69 + console.error(
70 + 'useOptimistic is now in canary. Remove the experimental_ prefix. ' +
71 + 'The prefixed alias will be removed in an upcoming release.',
72 + );
73 + }
74 + return useOptimistic(passthrough, reducer);
75 +}