Skip to content

Commit c987354

Browse files
committed
Let ReactDOM initialize in RSC
1 parent c635807 commit c987354

File tree

7 files changed

+50
-4
lines changed

7 files changed

+50
-4
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @emails react-core
8+
*/
9+
10+
'use strict';
11+
12+
describe('ReactDOMInReactServer', () => {
13+
beforeEach(() => {
14+
jest.resetModules();
15+
jest.mock('react', () => require('react/react.shared-subset'));
16+
});
17+
18+
// @gate experimental
19+
it('can require react-dom', () => {
20+
// In RSC this will be aliased.
21+
require('react');
22+
require('react-dom');
23+
});
24+
});

packages/react-reconciler/src/ReactFiberClassComponent.new.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ const fakeInternalInstance = {};
8282

8383
// React.Component uses a shared frozen object by default.
8484
// We'll use it to determine whether we need to initialize legacy refs.
85-
export const emptyRefsObject: $FlowFixMe = new React.Component().refs;
85+
export const emptyRefsObject: $FlowFixMe = React.Component
86+
? new React.Component().refs
87+
: {};
8688

8789
let didWarnAboutStateAssignmentForComponent;
8890
let didWarnAboutUninitializedState;

packages/react-reconciler/src/ReactFiberClassComponent.old.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ const fakeInternalInstance = {};
8282

8383
// React.Component uses a shared frozen object by default.
8484
// We'll use it to determine whether we need to initialize legacy refs.
85-
export const emptyRefsObject: $FlowFixMe = new React.Component().refs;
85+
export const emptyRefsObject: $FlowFixMe = React.Component
86+
? new React.Component().refs
87+
: {};
8688

8789
let didWarnAboutStateAssignmentForComponent;
8890
let didWarnAboutUninitializedState;

packages/react/src/ReactSharedSubset.experimental.js renamed to packages/react/react.shared-subset.experimental.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ export {
3535
useDebugValue,
3636
useMemo,
3737
version,
38-
} from './React';
38+
} from './src/React';
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
export * from './src/ReactSharedSubset';

scripts/jest/setupHostConfigs.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ jest.mock('react', () => {
5050
return jest.requireActual(resolvedEntryPoint);
5151
});
5252

53+
jest.mock('react/react.shared-subset', () => {
54+
const resolvedEntryPoint = resolveEntryFork(
55+
require.resolve('react/react.shared-subset'),
56+
global.__WWW__
57+
);
58+
return jest.requireActual(resolvedEntryPoint);
59+
});
60+
5361
jest.mock('react-reconciler/src/ReactFiberReconciler', () => {
5462
return jest.requireActual(
5563
__VARIANT__

scripts/rollup/bundles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const bundles = [
9090
{
9191
bundleTypes: [NODE_DEV, NODE_PROD],
9292
moduleType: ISOMORPHIC,
93-
entry: 'react/src/ReactSharedSubset.js',
93+
entry: 'react/react.shared-subset',
9494
name: 'react.shared-subset',
9595
global: 'React',
9696
minifyWithProdErrorCodes: true,

0 commit comments

Comments
 (0)