Skip to content

Commit

Permalink
Fork ReactSharedInternals for UMD builds
Browse files Browse the repository at this point in the history
  • Loading branch information
acdlite committed May 10, 2019
1 parent 39ef609 commit f057121
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
2 changes: 0 additions & 2 deletions packages/react/src/ReactSharedInternals.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
*/

import assign from 'object-assign';
import * as Scheduler from 'scheduler';
import * as SchedulerTracing from 'scheduler/tracing';
import ReactCurrentDispatcher from './ReactCurrentDispatcher';
import ReactCurrentOwner from './ReactCurrentOwner';
import ReactDebugCurrentFrame from './ReactDebugCurrentFrame';
Expand Down
44 changes: 44 additions & 0 deletions packages/react/src/forks/ReactSharedInternals.umd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* 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.
*/

import assign from 'object-assign';
import * as Scheduler from 'scheduler';
import * as SchedulerTracing from 'scheduler/tracing';
import ReactCurrentDispatcher from '../ReactCurrentDispatcher';
import ReactCurrentOwner from '../ReactCurrentOwner';
import ReactDebugCurrentFrame from '../ReactDebugCurrentFrame';

const ReactSharedInternals = {
ReactCurrentDispatcher,
ReactCurrentOwner,
// used by act()
ReactShouldWarnActingUpdates: {current: false},
// Used by renderers to avoid bundling object-assign twice in UMD bundles:
assign,
};

if (__DEV__) {
Object.assign(ReactSharedInternals, {
// These should not be included in production.
ReactDebugCurrentFrame,
// Shim for React DOM 16.0.0 which still destructured (but not used) this.
// TODO: remove in React 17.0.
ReactComponentTreeHook: {},
});
}

// Re-export the schedule API(s) for UMD bundles.
// This avoids introducing a dependency on a new UMD global in a minor update,
// Since that would be a breaking change (e.g. for all existing CodeSandboxes).
// This re-export is only required for UMD bundles;
// CJS bundles use the shared NPM package.
Object.assign(ReactSharedInternals, {
Scheduler,
SchedulerTracing,
});

export default ReactSharedInternals;
2 changes: 1 addition & 1 deletion packages/shared/__tests__/ReactDOMFrameScheduling-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('ReactDOMFrameScheduling', () => {
};
spyOnDevAndProd(console, 'error');
require('react-dom');
expect(console.error.calls.count()).toEqual(2);
expect(console.error.calls.count()).toEqual(1);
expect(console.error.calls.argsFor(0)[0]).toMatch(
"This browser doesn't support requestAnimationFrame.",
);
Expand Down
11 changes: 11 additions & 0 deletions scripts/rollup/forks.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,17 @@ const forks = Object.freeze({
}
},

'react/src/ReactSharedInternals.js': (bundleType, entry) => {
switch (bundleType) {
case UMD_DEV:
case UMD_PROD:
case UMD_PROFILING:
return 'react/src/forks/ReactSharedInternals.umd.js';
default:
return null;
}
},

// Different wrapping/reporting for caught errors.
'shared/invokeGuardedCallbackImpl': (bundleType, entry) => {
switch (bundleType) {
Expand Down

0 comments on commit f057121

Please sign in to comment.