Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export React as Named Exports instead of CommonJS #18106

Merged
merged 12 commits into from
Feb 25, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ describe('ReactHooksInspection', () => {
ReactDebugTools = require('react-debug-tools');
});

if (!__EXPERIMENTAL__) {
it("empty test so Jest doesn't complain", () => {});
return;
}

it('should inspect a simple useResponder hook', () => {
const TestResponder = React.DEPRECATED_createResponder('TestResponder', {});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,22 @@ export default function useContextMenu({
}: {|
data: Object,
id: string,
ref: ElementRef<HTMLElement>,
ref: {current: ElementRef<'div'> | null},
|}) {
const {showMenu} = useContext(RegistryContext);

useEffect(() => {
if (ref.current !== null) {
const handleContextMenu = event => {
const handleContextMenu = (event: MouseEvent | TouchEvent) => {
event.preventDefault();
event.stopPropagation();

const pageX = event.pageX || (event.touches && event.touches[0].pageX);
const pageY = event.pageY || (event.touches && event.touches[0].pageY);
const pageX =
event.pageX ||
(event.touches && ((event: any): TouchEvent).touches[0].pageX);
const pageY =
event.pageY ||
(event.touches && ((event: any): TouchEvent).touches[0].pageY);

showMenu({data, id, pageX, pageY});
};
Expand Down
46 changes: 46 additions & 0 deletions packages/react-dom/index.classic.fb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

import {addUserTimingListener} from 'shared/ReactFeatureFlags';
import {isEnabled} from './src/events/ReactDOMEventListener';
import {getClosestInstanceFromNode} from './src/client/ReactDOMComponentTree';

import {__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED} from './src/client/ReactDOM';

// For classic WWW builds, include a few internals that are already in use.
Object.assign((__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: any), {
ReactBrowserEventEmitter: {
isEnabled,
},
ReactDOMComponentTree: {
getClosestInstanceFromNode,
},
// Perf experiment
addUserTimingListener,
});

export {
createPortal,
unstable_batchedUpdates,
flushSync,
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
version,
findDOMNode,
hydrate,
render,
unmountComponentAtNode,
createRoot,
createBlockingRoot,
unstable_discreteUpdates,
unstable_flushDiscreteUpdates,
unstable_flushControlled,
unstable_scheduleHydration,
unstable_renderSubtreeIntoContainer,
unstable_createPortal,
} from './src/client/ReactDOM';
34 changes: 34 additions & 0 deletions packages/react-dom/index.experimental.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

export {
createPortal,
unstable_batchedUpdates,
flushSync,
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
version,
// Disabled behind disableLegacyReactDOMAPIs
findDOMNode,
hydrate,
render,
unmountComponentAtNode,
// exposeConcurrentModeAPIs
createRoot,
createBlockingRoot,
unstable_discreteUpdates,
unstable_flushDiscreteUpdates,
unstable_flushControlled,
unstable_scheduleHydration,
// Disabled behind disableUnstableRenderSubtreeIntoContainer
unstable_renderSubtreeIntoContainer,
// Disabled behind disableUnstableCreatePortal
// Temporary alias since we already shipped React 16 RC with it.
// TODO: remove in React 17.
unstable_createPortal,
} from './src/client/ReactDOM';
14 changes: 0 additions & 14 deletions packages/react-dom/index.fb.js

This file was deleted.

8 changes: 1 addition & 7 deletions packages/react-dom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,4 @@
* @flow
*/

'use strict';

const ReactDOM = require('./src/client/ReactDOM');

// TODO: decide on the top-level export form.
// This is hacky but makes it work with both Rollup and Jest.
module.exports = ReactDOM.default || ReactDOM;
export * from './src/client/ReactDOM';
22 changes: 22 additions & 0 deletions packages/react-dom/index.modern.fb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

export {
createPortal,
unstable_batchedUpdates,
flushSync,
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
version,
createRoot,
createBlockingRoot,
unstable_discreteUpdates,
unstable_flushDiscreteUpdates,
unstable_flushControlled,
unstable_scheduleHydration,
} from './src/client/ReactDOM';
24 changes: 24 additions & 0 deletions packages/react-dom/index.stable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

export {
createPortal,
unstable_batchedUpdates,
flushSync,
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
version,
findDOMNode,
hydrate,
render,
unmountComponentAtNode,
unstable_renderSubtreeIntoContainer,
// Temporary alias since we already shipped React 16 RC with it.
// TODO: remove in React 17.
unstable_createPortal,
} from './src/client/ReactDOM';
4 changes: 1 addition & 3 deletions packages/react-dom/src/__tests__/ReactDOMFiber-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ const React = require('react');
const ReactDOM = require('react-dom');
const PropTypes = require('prop-types');

const ReactFeatureFlags = require('shared/ReactFeatureFlags');

describe('ReactDOMFiber', () => {
let container;

Expand Down Expand Up @@ -249,7 +247,7 @@ describe('ReactDOMFiber', () => {
});

// TODO: remove in React 17
if (!ReactFeatureFlags.disableUnstableCreatePortal) {
if (!__EXPERIMENTAL__) {
it('should support unstable_createPortal alias', () => {
const portalContainer = document.createElement('div');

Expand Down
Loading