Skip to content

Commit c2ad4af

Browse files
committed
Move ReactDOMLegacy implementation into RootFB
Only the FB entry point has legacy mode now so we can move the remaining code in there.
1 parent 48ec17b commit c2ad4af

File tree

15 files changed

+161
-509
lines changed

15 files changed

+161
-509
lines changed

packages/react-devtools-shell/src/app/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ function mountStrictApp(App) {
6969
}
7070

7171
function mountLegacyApp(App: () => React$Node) {
72+
// $FlowFixMe[prop-missing]: These are removed in 19.
7273
const {render, unmountComponentAtNode} = require('react-dom');
7374

7475
function LegacyRender() {
@@ -77,8 +78,10 @@ function mountLegacyApp(App: () => React$Node) {
7778

7879
const container = createContainer();
7980

81+
// $FlowFixMe[not-a-function]: These are removed in 19.
8082
render(createElement(LegacyRender), container);
8183

84+
// $FlowFixMe: These are removed in 19.
8285
unmountFunctions.push(() => unmountComponentAtNode(container));
8386
}
8487

packages/react-devtools-shell/src/e2e-regression/app-legacy.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ function mountApp(App: () => React$Node) {
1515

1616
((document.body: any): HTMLBodyElement).appendChild(container);
1717

18+
// $FlowFixMe[prop-missing]: These are removed in 19.
1819
ReactDOM.render(<App />, container);
1920
}
2021
function mountTestApp() {

packages/react-dom/index.classic.fb.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,8 @@ Object.assign((Internals: any), {
2020

2121
export {
2222
createPortal,
23-
findDOMNode,
2423
flushSync,
25-
unmountComponentAtNode,
2624
unstable_createEventHandle,
27-
unstable_renderSubtreeIntoContainer,
2825
unstable_runWithPriority, // DO NOT USE: Temporarily exposed to migrate off of Scheduler.runWithPriority.
2926
useFormStatus,
3027
useFormState,
@@ -42,6 +39,9 @@ export {
4239
hydrateRoot,
4340
render,
4441
unstable_batchedUpdates,
42+
findDOMNode,
43+
unstable_renderSubtreeIntoContainer,
44+
unmountComponentAtNode,
4545
} from './src/client/ReactDOMRootFB';
4646

4747
export {Internals as __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED};

packages/react-dom/index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@ export {
1515
createRoot,
1616
hydrateRoot,
1717
flushSync,
18-
render,
19-
unmountComponentAtNode,
2018
unstable_batchedUpdates,
2119
unstable_createEventHandle,
22-
unstable_renderSubtreeIntoContainer,
2320
unstable_runWithPriority, // DO NOT USE: Temporarily exposed to migrate off of Scheduler.runWithPriority.
2421
useFormStatus,
2522
useFormState,

packages/react-dom/index.stable.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ export {
1313
createRoot,
1414
hydrateRoot,
1515
flushSync,
16-
render,
17-
unmountComponentAtNode,
1816
unstable_batchedUpdates,
19-
unstable_renderSubtreeIntoContainer,
2017
useFormStatus,
2118
useFormState,
2219
prefetchDNS,

packages/react-dom/src/ReactDOMSharedInternals.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* @flow
88
*/
99

10-
import type {FindDOMNodeType} from './client/ReactDOMLegacy.js';
1110
import type {HostDispatcher} from './shared/ReactDOMTypes';
1211

1312
type InternalsType = {
@@ -16,7 +15,11 @@ type InternalsType = {
1615
ReactDOMCurrentDispatcher: {
1716
current: HostDispatcher,
1817
},
19-
findDOMNode: null | FindDOMNodeType,
18+
findDOMNode:
19+
| null
20+
| ((
21+
componentOrElement: React$Component<any, any>,
22+
) => null | Element | Text),
2023
};
2124

2225
function noop() {}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ let act;
1414
let React;
1515
let ReactDOM;
1616
let ReactDOMClient;
17-
let findDOMNode;
1817

1918
const clone = function (o) {
2019
return JSON.parse(JSON.stringify(o));
@@ -95,8 +94,6 @@ describe('ReactComponentLifeCycle', () => {
9594

9695
React = require('react');
9796
ReactDOM = require('react-dom');
98-
findDOMNode =
99-
ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.findDOMNode;
10097
ReactDOMClient = require('react-dom/client');
10198
});
10299

@@ -376,6 +373,7 @@ describe('ReactComponentLifeCycle', () => {
376373
expect(instance.updater.isMounted(instance)).toBe(false);
377374
});
378375

376+
// @gate www && !disableLegacyMode
379377
it('warns if legacy findDOMNode is used inside render', async () => {
380378
class Component extends React.Component {
381379
state = {isMounted: false};
@@ -384,7 +382,7 @@ describe('ReactComponentLifeCycle', () => {
384382
}
385383
render() {
386384
if (this.state.isMounted) {
387-
expect(findDOMNode(this).tagName).toBe('DIV');
385+
expect(React.findDOMNode(this).tagName).toBe('DIV');
388386
}
389387
return <div />;
390388
}

packages/react-dom/src/__tests__/findDOMNode-test.js renamed to packages/react-dom/src/__tests__/findDOMNodeFB-test.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,15 @@
1111

1212
const React = require('react');
1313
const ReactDOM = require('react-dom');
14-
const findDOMNode =
15-
ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.findDOMNode;
1614
const StrictMode = React.StrictMode;
1715

1816
describe('findDOMNode', () => {
17+
// @gate www
1918
it('findDOMNode should return null if passed null', () => {
20-
expect(findDOMNode(null)).toBe(null);
19+
expect(ReactDOM.findDOMNode(null)).toBe(null);
2120
});
2221

23-
// @gate !disableLegacyMode
22+
// @gate www && !disableLegacyMode
2423
it('findDOMNode should find dom element', () => {
2524
class MyNode extends React.Component {
2625
render() {
@@ -34,13 +33,13 @@ describe('findDOMNode', () => {
3433

3534
const container = document.createElement('div');
3635
const myNode = ReactDOM.render(<MyNode />, container);
37-
const myDiv = findDOMNode(myNode);
38-
const mySameDiv = findDOMNode(myDiv);
36+
const myDiv = ReactDOM.findDOMNode(myNode);
37+
const mySameDiv = ReactDOM.findDOMNode(myDiv);
3938
expect(myDiv.tagName).toBe('DIV');
4039
expect(mySameDiv).toBe(myDiv);
4140
});
4241

43-
// @gate !disableLegacyMode
42+
// @gate www && !disableLegacyMode
4443
it('findDOMNode should find dom element after an update from null', () => {
4544
function Bar({flag}) {
4645
if (flag) {
@@ -57,23 +56,24 @@ describe('findDOMNode', () => {
5756
const container = document.createElement('div');
5857

5958
const myNodeA = ReactDOM.render(<MyNode />, container);
60-
const a = findDOMNode(myNodeA);
59+
const a = ReactDOM.findDOMNode(myNodeA);
6160
expect(a).toBe(null);
6261

6362
const myNodeB = ReactDOM.render(<MyNode flag={true} />, container);
6463
expect(myNodeA === myNodeB).toBe(true);
6564

66-
const b = findDOMNode(myNodeB);
65+
const b = ReactDOM.findDOMNode(myNodeB);
6766
expect(b.tagName).toBe('SPAN');
6867
});
6968

69+
// @gate www
7070
it('findDOMNode should reject random objects', () => {
7171
expect(function () {
72-
findDOMNode({foo: 'bar'});
72+
ReactDOM.findDOMNode({foo: 'bar'});
7373
}).toThrowError('Argument appears to not be a ReactComponent. Keys: foo');
7474
});
7575

76-
// @gate !disableLegacyMode
76+
// @gate www && !disableLegacyMode
7777
it('findDOMNode should reject unmounted objects with render func', () => {
7878
class Foo extends React.Component {
7979
render() {
@@ -85,16 +85,16 @@ describe('findDOMNode', () => {
8585
const inst = ReactDOM.render(<Foo />, container);
8686
ReactDOM.unmountComponentAtNode(container);
8787

88-
expect(() => findDOMNode(inst)).toThrowError(
88+
expect(() => ReactDOM.findDOMNode(inst)).toThrowError(
8989
'Unable to find node on an unmounted component.',
9090
);
9191
});
9292

93-
// @gate !disableLegacyMode
93+
// @gate www && !disableLegacyMode
9494
it('findDOMNode should not throw an error when called within a component that is not mounted', () => {
9595
class Bar extends React.Component {
9696
UNSAFE_componentWillMount() {
97-
expect(findDOMNode(this)).toBeNull();
97+
expect(ReactDOM.findDOMNode(this)).toBeNull();
9898
}
9999

100100
render() {
@@ -107,7 +107,7 @@ describe('findDOMNode', () => {
107107
}).not.toThrow();
108108
});
109109

110-
// @gate !disableLegacyMode
110+
// @gate www && !disableLegacyMode
111111
it('findDOMNode should warn if used to find a host component inside StrictMode', () => {
112112
let parent = undefined;
113113
let child = undefined;
@@ -129,7 +129,7 @@ describe('findDOMNode', () => {
129129
);
130130

131131
let match;
132-
expect(() => (match = findDOMNode(parent))).toErrorDev([
132+
expect(() => (match = ReactDOM.findDOMNode(parent))).toErrorDev([
133133
'Warning: findDOMNode is deprecated in StrictMode. ' +
134134
'findDOMNode was passed an instance of ContainsStrictModeChild which renders StrictMode children. ' +
135135
'Instead, add a ref directly to the element you want to reference. ' +
@@ -141,7 +141,7 @@ describe('findDOMNode', () => {
141141
expect(match).toBe(child);
142142
});
143143

144-
// @gate !disableLegacyMode
144+
// @gate www && !disableLegacyMode
145145
it('findDOMNode should warn if passed a component that is inside StrictMode', () => {
146146
let parent = undefined;
147147
let child = undefined;
@@ -162,7 +162,7 @@ describe('findDOMNode', () => {
162162
);
163163

164164
let match;
165-
expect(() => (match = findDOMNode(parent))).toErrorDev([
165+
expect(() => (match = ReactDOM.findDOMNode(parent))).toErrorDev([
166166
'Warning: findDOMNode is deprecated in StrictMode. ' +
167167
'findDOMNode was passed an instance of IsInStrictMode which is inside StrictMode. ' +
168168
'Instead, add a ref directly to the element you want to reference. ' +

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

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,12 @@
88
*/
99

1010
import type {ReactNodeList} from 'shared/ReactTypes';
11-
import type {
12-
Container,
13-
PublicInstance,
14-
} from 'react-dom-bindings/src/client/ReactFiberConfigDOM';
1511
import type {
1612
RootType,
1713
HydrateRootOptions,
1814
CreateRootOptions,
1915
} from './ReactDOMRoot';
2016

21-
import {
22-
findDOMNode,
23-
render,
24-
unstable_renderSubtreeIntoContainer,
25-
unmountComponentAtNode,
26-
} from './ReactDOMLegacy';
2717
import {
2818
createRoot as createRootImpl,
2919
hydrateRoot as hydrateRootImpl,
@@ -35,6 +25,7 @@ import {
3525
flushSync as flushSyncWithoutWarningIfAlreadyRendering,
3626
isAlreadyRendering,
3727
injectIntoDevTools,
28+
findHostInstance,
3829
} from 'react-reconciler/src/ReactFiberReconciler';
3930
import {runWithPriority} from 'react-reconciler/src/ReactEventPriorities';
4031
import {createPortal as createPortalImpl} from 'react-reconciler/src/ReactPortal';
@@ -99,20 +90,6 @@ function createPortal(
9990
return createPortalImpl(children, container, null, key);
10091
}
10192

102-
function renderSubtreeIntoContainer(
103-
parentComponent: React$Component<any, any>,
104-
element: React$Element<any>,
105-
containerNode: Container,
106-
callback: ?Function,
107-
): React$Component<any, any> | PublicInstance | null {
108-
return unstable_renderSubtreeIntoContainer(
109-
parentComponent,
110-
element,
111-
containerNode,
112-
callback,
113-
);
114-
}
115-
11693
function createRoot(
11794
container: Element | Document | DocumentFragment,
11895
options?: CreateRootOptions,
@@ -163,6 +140,12 @@ function flushSync<R>(fn: (() => R) | void): R | void {
163140
return flushSyncWithoutWarningIfAlreadyRendering(fn);
164141
}
165142

143+
function findDOMNode(
144+
componentOrElement: React$Component<any, any>,
145+
): null | Element | Text {
146+
return findHostInstance(componentOrElement);
147+
}
148+
166149
// Expose findDOMNode on internals
167150
Internals.findDOMNode = findDOMNode;
168151

@@ -178,15 +161,9 @@ export {
178161
unstable_batchedUpdates,
179162
flushSync,
180163
ReactVersion as version,
181-
// Disabled behind disableLegacyReactDOMAPIs
182-
findDOMNode,
183-
render,
184-
unmountComponentAtNode,
185164
// exposeConcurrentModeAPIs
186165
createRoot,
187166
hydrateRoot,
188-
// Disabled behind disableUnstableRenderSubtreeIntoContainer
189-
renderSubtreeIntoContainer as unstable_renderSubtreeIntoContainer,
190167
// enableCreateEventHandleAPI
191168
createEventHandle as unstable_createEventHandle,
192169
// TODO: Remove this once callers migrate to alternatives.

0 commit comments

Comments
 (0)