Skip to content

Commit

Permalink
Refactor React Server entrypoint to not depend on the client one (fac…
Browse files Browse the repository at this point in the history
…ebook#27940)

This refactors the Server Components entrypoint for the `react` package
(ReactServer.js) so that it doesn't depend on the client entrypoint
(React.js). I also renamed React.js to ReactClient.js to make the
separation clearer.

This structure will make it easier to add client-only and server-only
features.
  • Loading branch information
acdlite authored and AndyPengc12 committed Apr 15, 2024
1 parent 128e936 commit 65c10b7
Show file tree
Hide file tree
Showing 11 changed files with 695 additions and 608 deletions.
2 changes: 1 addition & 1 deletion packages/react/index.classic.fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ export {
useSyncExternalStore,
useTransition,
version,
} from './src/React';
} from './src/ReactClient';
export {jsx, jsxs, jsxDEV} from './src/jsx/ReactJSX';
4 changes: 2 additions & 2 deletions packages/react/index.experimental.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ export {
useSyncExternalStore,
useTransition,
version,
} from './src/React';
} from './src/ReactClient';

import {useOptimistic} from './src/React';
import {useOptimistic} from './src/ReactClient';

export function experimental_useOptimistic<S, A>(
passthrough: S,
Expand Down
2 changes: 1 addition & 1 deletion packages/react/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,4 @@ export {
useState,
useTransition,
version,
} from './src/React';
} from './src/ReactClient';
2 changes: 1 addition & 1 deletion packages/react/index.modern.fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ export {
useSyncExternalStore,
useTransition,
version,
} from './src/React';
} from './src/ReactClient';
export {jsx, jsxs, jsxDEV} from './src/jsx/ReactJSX';
2 changes: 1 addition & 1 deletion packages/react/index.stable.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ export {
useSyncExternalStore,
useTransition,
version,
} from './src/React';
} from './src/ReactClient';
23 changes: 4 additions & 19 deletions packages/react/src/React.js → packages/react/src/ReactClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import {Component, PureComponent} from './ReactBaseClasses';
import {createRef} from './ReactCreateRef';
import {forEach, map, count, toArray, only} from './ReactChildren';
import {
createElement as createElementProd,
createFactory as createFactoryProd,
cloneElement as cloneElementProd,
createElement,
createFactory,
cloneElement,
isValidElement,
} from './ReactElement';
import {createContext} from './ReactContext';
Expand Down Expand Up @@ -61,27 +61,12 @@ import {
useMemoCache,
useOptimistic,
} from './ReactHooks';
import {
createElementWithValidation,
createFactoryWithValidation,
cloneElementWithValidation,
} from './ReactElementValidator';

import {createServerContext} from './ReactServerContext';
import ReactSharedInternals from './ReactSharedInternalsClient';
import {startTransition} from './ReactStartTransition';
import {act} from './ReactAct';

// TODO: Move this branching into the other module instead and just re-export.
const createElement: any = __DEV__
? createElementWithValidation
: createElementProd;
const cloneElement: any = __DEV__
? cloneElementWithValidation
: cloneElementProd;
const createFactory: any = __DEV__
? createFactoryWithValidation
: createFactoryProd;

const Children = {
map,
forEach,
Expand Down
Loading

0 comments on commit 65c10b7

Please sign in to comment.