Skip to content

Commit 70dfb61

Browse files
author
Brian Vaughn
committed
Don't re-export react-scheduler APIs for CJS bundles
1 parent 673f8bc commit 70dfb61

File tree

5 files changed

+30
-19
lines changed

5 files changed

+30
-19
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,6 @@ module.exports = {
8484
spyOnDevAndProd: true,
8585
spyOnProd: true,
8686
__PROFILE__: true,
87+
__UMD__: true,
8788
},
8889
};

packages/react/src/ReactSharedInternals.js

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,35 @@ const ReactSharedInternals = {
3131
ReactCurrentOwner,
3232
// Used by renderers to avoid bundling object-assign twice in UMD bundles:
3333
assign,
34+
};
35+
36+
if (__UMD__) {
3437
// Re-export the react-scheduler API(s) for UMD bundles.
3538
// This avoids introducing a dependency on a new UMD global in a minor update,
3639
// Since that would be a breaking change (e.g. for all existing CodeSandboxes).
37-
Scheduler: {
38-
cancelScheduledWork,
39-
now,
40-
scheduleWork,
41-
},
42-
SchedulerTracking: {
43-
__getInteractionsRef,
44-
__getSubscriberRef,
45-
clear,
46-
getCurrent,
47-
getThreadID,
48-
track,
49-
wrap,
50-
},
51-
SchedulerTrackingSubscriptions: {
52-
subscribe,
53-
unsubscribe,
54-
},
55-
};
40+
// This re-export is only required for UMD bundles;
41+
// CJS bundles use the shared NPM package.
42+
Object.assign(ReactSharedInternals, {
43+
Scheduler: {
44+
cancelScheduledWork,
45+
now,
46+
scheduleWork,
47+
},
48+
SchedulerTracking: {
49+
__getInteractionsRef,
50+
__getSubscriberRef,
51+
clear,
52+
getCurrent,
53+
getThreadID,
54+
track,
55+
wrap,
56+
},
57+
SchedulerTrackingSubscriptions: {
58+
subscribe,
59+
unsubscribe,
60+
},
61+
});
62+
}
5663

5764
if (__DEV__) {
5865
Object.assign(ReactSharedInternals, {

scripts/flow/environment.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
/* eslint-disable */
1111

1212
declare var __PROFILE__: boolean;
13+
declare var __UMD__: boolean;
1314

1415
declare var __REACT_DEVTOOLS_GLOBAL_HOOK__: any; /*?{
1516
inject: ?((stuff: Object) => void)

scripts/jest/setupEnvironment.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ if (NODE_ENV !== 'development' && NODE_ENV !== 'production') {
66
}
77
global.__DEV__ = NODE_ENV === 'development';
88
global.__PROFILE__ = NODE_ENV === 'development';
9+
global.__UMD__ = false;
910

1011
if (typeof window !== 'undefined') {
1112
global.requestAnimationFrame = function(callback) {

scripts/rollup/build.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ function getPlugins(
325325
replace({
326326
__DEV__: isProduction ? 'false' : 'true',
327327
__PROFILE__: isProfiling || !isProduction ? 'true' : 'false',
328+
__UMD__: isUMDBundle ? 'true' : 'false',
328329
'process.env.NODE_ENV': isProduction ? "'production'" : "'development'",
329330
}),
330331
// We still need CommonJS for external deps like object-assign.

0 commit comments

Comments
 (0)