Skip to content

Commit

Permalink
Move type DOMContainer to HostConfig (#18112)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sebmarkbage authored Feb 24, 2020
1 parent 501a788 commit ccab494
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 26 deletions.
8 changes: 2 additions & 6 deletions packages/react-dom/src/client/ReactDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* @flow
*/

import type {RootType} from './ReactDOMRoot';
import type {ReactNodeList} from 'shared/ReactTypes';
import type {Container} from './ReactDOMHostConfig';

import '../shared/checkReact';
import './ReactDOMClientInjection';
Expand Down Expand Up @@ -116,13 +116,9 @@ setBatchingImplementation(
batchedEventUpdates,
);

export type DOMContainer =
| (Element & {_reactRootContainer: ?RootType, ...})
| (Document & {_reactRootContainer: ?RootType, ...});

function createPortal(
children: ReactNodeList,
container: DOMContainer,
container: Container,
key: ?string = null,
) {
invariant(
Expand Down
9 changes: 6 additions & 3 deletions packages/react-dom/src/client/ReactDOMHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* @flow
*/

import type {RootType} from './ReactDOMRoot';

import {
precacheFiberNode,
updateFiberProps,
Expand Down Expand Up @@ -45,7 +47,6 @@ import {
} from '../shared/HTMLNodeType';
import dangerousStyleValue from '../shared/dangerousStyleValue';

import type {DOMContainer} from './ReactDOM';
import type {
ReactDOMEventResponder,
ReactDOMEventResponderInstance,
Expand Down Expand Up @@ -99,7 +100,9 @@ export type EventTargetChildElement = {
},
...
};
export type Container = DOMContainer;
export type Container =
| (Element & {_reactRootContainer: ?RootType, ...})
| (Document & {_reactRootContainer: ?RootType, ...});
export type Instance = Element;
export type TextInstance = Text;
export type SuspenseInstance = Comment & {_reactRetry?: () => void, ...};
Expand Down Expand Up @@ -419,7 +422,7 @@ export function appendChild(
}

export function appendChildToContainer(
container: DOMContainer,
container: Container,
child: Instance | TextInstance,
): void {
let parentNode;
Expand Down
16 changes: 8 additions & 8 deletions packages/react-dom/src/client/ReactDOMLegacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @flow
*/

import type {DOMContainer} from './ReactDOM';
import type {Container} from './ReactDOMHostConfig';
import type {RootType} from './ReactDOMRoot';
import type {ReactNodeList} from 'shared/ReactTypes';

Expand Down Expand Up @@ -43,7 +43,7 @@ let topLevelUpdateWarnings;
let warnedAboutHydrateAPI = false;

if (__DEV__) {
topLevelUpdateWarnings = (container: DOMContainer) => {
topLevelUpdateWarnings = (container: Container) => {
if (container._reactRootContainer && container.nodeType !== COMMENT_NODE) {
const hostInstance = findHostInstanceWithNoPortals(
container._reactRootContainer._internalRoot.current,
Expand Down Expand Up @@ -111,7 +111,7 @@ function shouldHydrateDueToLegacyHeuristic(container) {
}

function legacyCreateRootFromDOMContainer(
container: DOMContainer,
container: Container,
forceHydrate: boolean,
): RootType {
const shouldHydrate =
Expand Down Expand Up @@ -175,7 +175,7 @@ function warnOnInvalidCallback(callback: mixed, callerName: string): void {
function legacyRenderSubtreeIntoContainer(
parentComponent: ?React$Component<any, any>,
children: ReactNodeList,
container: DOMContainer,
container: Container,
forceHydrate: boolean,
callback: ?Function,
) {
Expand Down Expand Up @@ -255,7 +255,7 @@ export function findDOMNode(

export function hydrate(
element: React$Node,
container: DOMContainer,
container: Container,
callback: ?Function,
) {
invariant(
Expand Down Expand Up @@ -286,7 +286,7 @@ export function hydrate(

export function render(
element: React$Element<any>,
container: DOMContainer,
container: Container,
callback: ?Function,
) {
invariant(
Expand Down Expand Up @@ -317,7 +317,7 @@ export function render(
export function unstable_renderSubtreeIntoContainer(
parentComponent: React$Component<any, any>,
element: React$Element<any>,
containerNode: DOMContainer,
containerNode: Container,
callback: ?Function,
) {
invariant(
Expand All @@ -337,7 +337,7 @@ export function unstable_renderSubtreeIntoContainer(
);
}

export function unmountComponentAtNode(container: DOMContainer) {
export function unmountComponentAtNode(container: Container) {
invariant(
isValidContainer(container),
'unmountComponentAtNode(...): Target container is not a DOM element.',
Expand Down
14 changes: 7 additions & 7 deletions packages/react-dom/src/client/ReactDOMRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @flow
*/

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

function ReactDOMRoot(container: DOMContainer, options: void | RootOptions) {
function ReactDOMRoot(container: Container, options: void | RootOptions) {
this._internalRoot = createRootImpl(container, ConcurrentRoot, options);
}

function ReactDOMBlockingRoot(
container: DOMContainer,
container: Container,
tag: RootTag,
options: void | RootOptions,
) {
Expand Down Expand Up @@ -108,7 +108,7 @@ ReactDOMRoot.prototype.unmount = ReactDOMBlockingRoot.prototype.unmount = functi
};

function createRootImpl(
container: DOMContainer,
container: Container,
tag: RootTag,
options: void | RootOptions,
) {
Expand All @@ -129,7 +129,7 @@ function createRootImpl(
}

export function createRoot(
container: DOMContainer,
container: Container,
options?: RootOptions,
): RootType {
invariant(
Expand All @@ -141,7 +141,7 @@ export function createRoot(
}

export function createBlockingRoot(
container: DOMContainer,
container: Container,
options?: RootOptions,
): RootType {
invariant(
Expand All @@ -153,7 +153,7 @@ export function createBlockingRoot(
}

export function createLegacyRoot(
container: DOMContainer,
container: Container,
options?: RootOptions,
): RootType {
return new ReactDOMBlockingRoot(container, LegacyRoot, options);
Expand Down
3 changes: 1 addition & 2 deletions packages/react-dom/src/events/ReactDOMEventReplaying.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import type {Container, SuspenseInstance} from '../client/ReactDOMHostConfig';
import type {DOMTopLevelEventType} from 'legacy-events/TopLevelEventTypes';
import type {EventSystemFlags} from 'legacy-events/EventSystemFlags';
import type {FiberRoot} from 'react-reconciler/src/ReactFiberRoot';
import type {DOMContainer} from '../client/ReactDOM';

import {
enableDeprecatedFlareAPI,
Expand Down Expand Up @@ -238,7 +237,7 @@ function trapReplayableEventForDocument(
}

export function eagerlyTrapReplayableEvents(
container: DOMContainer,
container: Container,
document: Document,
) {
const listenerMapForDoc = getListenerMapForElement(document);
Expand Down

0 comments on commit ccab494

Please sign in to comment.