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

Fork ReactSharedInternals for UMD builds #15617

Merged
merged 1 commit into from
May 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 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 All @@ -21,18 +19,6 @@ const ReactSharedInternals = {
assign,
};

if (__UMD__) {
// 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,
});
}

if (__DEV__) {
Object.assign(ReactSharedInternals, {
// These should not be included in production.
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;
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ describe('Scheduling UMD bundle', () => {
const umdAPIDev = require('../../npm/umd/scheduler.development');
const umdAPIProd = require('../../npm/umd/scheduler.production.min');
const umdAPIProfiling = require('../../npm/umd/scheduler.profiling.min');
const secretAPI = require('react/src/ReactSharedInternals').default;
const secretAPI = require('react/src/forks/ReactSharedInternals.umd')
.default;
validateForwardedAPIs(api, [
umdAPIDev,
umdAPIProd,
Expand All @@ -69,7 +70,8 @@ describe('Scheduling UMD bundle', () => {
const umdAPIDev = require('../../npm/umd/scheduler-tracing.development');
const umdAPIProd = require('../../npm/umd/scheduler-tracing.production.min');
const umdAPIProfiling = require('../../npm/umd/scheduler-tracing.profiling.min');
const secretAPI = require('react/src/ReactSharedInternals').default;
const secretAPI = require('react/src/forks/ReactSharedInternals.umd')
.default;
validateForwardedAPIs(api, [
umdAPIDev,
umdAPIProd,
Expand Down
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