Skip to content

Commit 25b51b3

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

File tree

5 files changed

+48
-2
lines changed

5 files changed

+48
-2
lines changed
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

+3-1
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

+3-1
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/react.shared-subset.js

+10
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

+8
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/src/ReactSharedSubset'),
56+
global.__WWW__
57+
);
58+
return jest.requireActual(resolvedEntryPoint);
59+
});
60+
5361
jest.mock('react-reconciler/src/ReactFiberReconciler', () => {
5462
return jest.requireActual(
5563
__VARIANT__

0 commit comments

Comments
 (0)