Skip to content

Commit

Permalink
Don't re-export react-scheduler APIs for CJS bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed Aug 31, 2018
1 parent 673f8bc commit 70dfb61
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 19 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,6 @@ module.exports = {
spyOnDevAndProd: true,
spyOnProd: true,
__PROFILE__: true,
__UMD__: true,
},
};
45 changes: 26 additions & 19 deletions packages/react/src/ReactSharedInternals.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,35 @@ const ReactSharedInternals = {
ReactCurrentOwner,
// Used by renderers to avoid bundling object-assign twice in UMD bundles:
assign,
};

if (__UMD__) {
// Re-export the react-scheduler 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).
Scheduler: {
cancelScheduledWork,
now,
scheduleWork,
},
SchedulerTracking: {
__getInteractionsRef,
__getSubscriberRef,
clear,
getCurrent,
getThreadID,
track,
wrap,
},
SchedulerTrackingSubscriptions: {
subscribe,
unsubscribe,
},
};
// This re-export is only required for UMD bundles;
// CJS bundles use the shared NPM package.
Object.assign(ReactSharedInternals, {
Scheduler: {
cancelScheduledWork,
now,
scheduleWork,
},
SchedulerTracking: {
__getInteractionsRef,
__getSubscriberRef,
clear,
getCurrent,
getThreadID,
track,
wrap,
},
SchedulerTrackingSubscriptions: {
subscribe,
unsubscribe,
},
});
}

if (__DEV__) {
Object.assign(ReactSharedInternals, {
Expand Down
1 change: 1 addition & 0 deletions scripts/flow/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
/* eslint-disable */

declare var __PROFILE__: boolean;
declare var __UMD__: boolean;

declare var __REACT_DEVTOOLS_GLOBAL_HOOK__: any; /*?{
inject: ?((stuff: Object) => void)
Expand Down
1 change: 1 addition & 0 deletions scripts/jest/setupEnvironment.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ if (NODE_ENV !== 'development' && NODE_ENV !== 'production') {
}
global.__DEV__ = NODE_ENV === 'development';
global.__PROFILE__ = NODE_ENV === 'development';
global.__UMD__ = false;

if (typeof window !== 'undefined') {
global.requestAnimationFrame = function(callback) {
Expand Down
1 change: 1 addition & 0 deletions scripts/rollup/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ function getPlugins(
replace({
__DEV__: isProduction ? 'false' : 'true',
__PROFILE__: isProfiling || !isProduction ? 'true' : 'false',
__UMD__: isUMDBundle ? 'true' : 'false',
'process.env.NODE_ENV': isProduction ? "'production'" : "'development'",
}),
// We still need CommonJS for external deps like object-assign.
Expand Down

0 comments on commit 70dfb61

Please sign in to comment.