Skip to content

Commit ccab494

Browse files
authored
Move type DOMContainer to HostConfig (#18112)
Exports from ReactDOM represents React's public API. This include types exported by React. At some point we'll start building Flow types from these files. The duplicate name between DOMContainer and Container seems confusing too since it was used in the same files even though they're the same.
1 parent 501a788 commit ccab494

File tree

5 files changed

+24
-26
lines changed

5 files changed

+24
-26
lines changed

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
* @flow
88
*/
99

10-
import type {RootType} from './ReactDOMRoot';
1110
import type {ReactNodeList} from 'shared/ReactTypes';
11+
import type {Container} from './ReactDOMHostConfig';
1212

1313
import '../shared/checkReact';
1414
import './ReactDOMClientInjection';
@@ -116,13 +116,9 @@ setBatchingImplementation(
116116
batchedEventUpdates,
117117
);
118118

119-
export type DOMContainer =
120-
| (Element & {_reactRootContainer: ?RootType, ...})
121-
| (Document & {_reactRootContainer: ?RootType, ...});
122-
123119
function createPortal(
124120
children: ReactNodeList,
125-
container: DOMContainer,
121+
container: Container,
126122
key: ?string = null,
127123
) {
128124
invariant(

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* @flow
88
*/
99

10+
import type {RootType} from './ReactDOMRoot';
11+
1012
import {
1113
precacheFiberNode,
1214
updateFiberProps,
@@ -45,7 +47,6 @@ import {
4547
} from '../shared/HTMLNodeType';
4648
import dangerousStyleValue from '../shared/dangerousStyleValue';
4749

48-
import type {DOMContainer} from './ReactDOM';
4950
import type {
5051
ReactDOMEventResponder,
5152
ReactDOMEventResponderInstance,
@@ -99,7 +100,9 @@ export type EventTargetChildElement = {
99100
},
100101
...
101102
};
102-
export type Container = DOMContainer;
103+
export type Container =
104+
| (Element & {_reactRootContainer: ?RootType, ...})
105+
| (Document & {_reactRootContainer: ?RootType, ...});
103106
export type Instance = Element;
104107
export type TextInstance = Text;
105108
export type SuspenseInstance = Comment & {_reactRetry?: () => void, ...};
@@ -419,7 +422,7 @@ export function appendChild(
419422
}
420423

421424
export function appendChildToContainer(
422-
container: DOMContainer,
425+
container: Container,
423426
child: Instance | TextInstance,
424427
): void {
425428
let parentNode;

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @flow
88
*/
99

10-
import type {DOMContainer} from './ReactDOM';
10+
import type {Container} from './ReactDOMHostConfig';
1111
import type {RootType} from './ReactDOMRoot';
1212
import type {ReactNodeList} from 'shared/ReactTypes';
1313

@@ -43,7 +43,7 @@ let topLevelUpdateWarnings;
4343
let warnedAboutHydrateAPI = false;
4444

4545
if (__DEV__) {
46-
topLevelUpdateWarnings = (container: DOMContainer) => {
46+
topLevelUpdateWarnings = (container: Container) => {
4747
if (container._reactRootContainer && container.nodeType !== COMMENT_NODE) {
4848
const hostInstance = findHostInstanceWithNoPortals(
4949
container._reactRootContainer._internalRoot.current,
@@ -111,7 +111,7 @@ function shouldHydrateDueToLegacyHeuristic(container) {
111111
}
112112

113113
function legacyCreateRootFromDOMContainer(
114-
container: DOMContainer,
114+
container: Container,
115115
forceHydrate: boolean,
116116
): RootType {
117117
const shouldHydrate =
@@ -175,7 +175,7 @@ function warnOnInvalidCallback(callback: mixed, callerName: string): void {
175175
function legacyRenderSubtreeIntoContainer(
176176
parentComponent: ?React$Component<any, any>,
177177
children: ReactNodeList,
178-
container: DOMContainer,
178+
container: Container,
179179
forceHydrate: boolean,
180180
callback: ?Function,
181181
) {
@@ -255,7 +255,7 @@ export function findDOMNode(
255255

256256
export function hydrate(
257257
element: React$Node,
258-
container: DOMContainer,
258+
container: Container,
259259
callback: ?Function,
260260
) {
261261
invariant(
@@ -286,7 +286,7 @@ export function hydrate(
286286

287287
export function render(
288288
element: React$Element<any>,
289-
container: DOMContainer,
289+
container: Container,
290290
callback: ?Function,
291291
) {
292292
invariant(
@@ -317,7 +317,7 @@ export function render(
317317
export function unstable_renderSubtreeIntoContainer(
318318
parentComponent: React$Component<any, any>,
319319
element: React$Element<any>,
320-
containerNode: DOMContainer,
320+
containerNode: Container,
321321
callback: ?Function,
322322
) {
323323
invariant(
@@ -337,7 +337,7 @@ export function unstable_renderSubtreeIntoContainer(
337337
);
338338
}
339339

340-
export function unmountComponentAtNode(container: DOMContainer) {
340+
export function unmountComponentAtNode(container: Container) {
341341
invariant(
342342
isValidContainer(container),
343343
'unmountComponentAtNode(...): Target container is not a DOM element.',

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* @flow
88
*/
99

10-
import type {DOMContainer} from './ReactDOM';
10+
import type {Container} from './ReactDOMHostConfig';
1111
import type {RootTag} from 'shared/ReactRootTags';
1212
import type {ReactNodeList} from 'shared/ReactTypes';
1313
// TODO: This type is shared between the reconciler and ReactDOM, but will
@@ -49,12 +49,12 @@ import {createContainer, updateContainer} from 'react-reconciler/inline.dom';
4949
import invariant from 'shared/invariant';
5050
import {BlockingRoot, ConcurrentRoot, LegacyRoot} from 'shared/ReactRootTags';
5151

52-
function ReactDOMRoot(container: DOMContainer, options: void | RootOptions) {
52+
function ReactDOMRoot(container: Container, options: void | RootOptions) {
5353
this._internalRoot = createRootImpl(container, ConcurrentRoot, options);
5454
}
5555

5656
function ReactDOMBlockingRoot(
57-
container: DOMContainer,
57+
container: Container,
5858
tag: RootTag,
5959
options: void | RootOptions,
6060
) {
@@ -108,7 +108,7 @@ ReactDOMRoot.prototype.unmount = ReactDOMBlockingRoot.prototype.unmount = functi
108108
};
109109

110110
function createRootImpl(
111-
container: DOMContainer,
111+
container: Container,
112112
tag: RootTag,
113113
options: void | RootOptions,
114114
) {
@@ -129,7 +129,7 @@ function createRootImpl(
129129
}
130130

131131
export function createRoot(
132-
container: DOMContainer,
132+
container: Container,
133133
options?: RootOptions,
134134
): RootType {
135135
invariant(
@@ -141,7 +141,7 @@ export function createRoot(
141141
}
142142

143143
export function createBlockingRoot(
144-
container: DOMContainer,
144+
container: Container,
145145
options?: RootOptions,
146146
): RootType {
147147
invariant(
@@ -153,7 +153,7 @@ export function createBlockingRoot(
153153
}
154154

155155
export function createLegacyRoot(
156-
container: DOMContainer,
156+
container: Container,
157157
options?: RootOptions,
158158
): RootType {
159159
return new ReactDOMBlockingRoot(container, LegacyRoot, options);

packages/react-dom/src/events/ReactDOMEventReplaying.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import type {Container, SuspenseInstance} from '../client/ReactDOMHostConfig';
1212
import type {DOMTopLevelEventType} from 'legacy-events/TopLevelEventTypes';
1313
import type {EventSystemFlags} from 'legacy-events/EventSystemFlags';
1414
import type {FiberRoot} from 'react-reconciler/src/ReactFiberRoot';
15-
import type {DOMContainer} from '../client/ReactDOM';
1615

1716
import {
1817
enableDeprecatedFlareAPI,
@@ -238,7 +237,7 @@ function trapReplayableEventForDocument(
238237
}
239238

240239
export function eagerlyTrapReplayableEvents(
241-
container: DOMContainer,
240+
container: Container,
242241
document: Document,
243242
) {
244243
const listenerMapForDoc = getListenerMapForElement(document);

0 commit comments

Comments
 (0)