diff --git a/packages/react-reconciler/src/ReactFiberScheduler.js b/packages/react-reconciler/src/ReactFiberScheduler.js index 20b2b4d4f8500..1a407aab55619 100644 --- a/packages/react-reconciler/src/ReactFiberScheduler.js +++ b/packages/react-reconciler/src/ReactFiberScheduler.js @@ -168,6 +168,18 @@ let didWarnSetStateChildContext; let warnAboutUpdateOnUnmounted; let warnAboutInvalidUpdates; +if (enableSchedulerTracking) { + // Provide explicit error message when production+profiling bundle of e.g. react-dom + // is used with production (non-profiling) bundle of schedule/tracking + invariant( + __interactionsRef != null && __interactionsRef.current != null, + 'It is not supported to run the profiling version of a renderer (for example, `react-dom/profiling`) ' + + 'without also replacing the `schedule/tracking` module with `schedule/tracking-profiling`. ' + + 'Your bundler might have a setting for aliasing both modules. ' + + 'Learn more at http://fb.me/react-profiling', + ); +} + if (__DEV__) { didWarnAboutStateTransition = false; didWarnSetStateChildContext = false; diff --git a/packages/react-reconciler/src/__tests__/ReactTracking-test.internal.js b/packages/react-reconciler/src/__tests__/ReactTracking-test.internal.js new file mode 100644 index 0000000000000..3168f6f778505 --- /dev/null +++ b/packages/react-reconciler/src/__tests__/ReactTracking-test.internal.js @@ -0,0 +1,28 @@ +/** + * 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. + * + * @emails react-core + * @jest-environment node + */ + +'use strict'; + +describe('ReactTracking', () => { + it('should error if profiling renderer and non-profiling schedule/tracking bundles are combined', () => { + jest.resetModules(); + + const ReactFeatureFlags = require('shared/ReactFeatureFlags'); + ReactFeatureFlags.enableSchedulerTracking = false; + + require('schedule/tracking'); + + ReactFeatureFlags.enableSchedulerTracking = true; + + expect(() => require('react-dom')).toThrow( + 'Learn more at http://fb.me/react-profiling', + ); + }); +}); diff --git a/packages/schedule/npm/tracking-profiling.js b/packages/schedule/npm/tracking-profiling.js new file mode 100644 index 0000000000000..c90851e796d23 --- /dev/null +++ b/packages/schedule/npm/tracking-profiling.js @@ -0,0 +1,7 @@ +'use strict'; + +if (process.env.NODE_ENV === 'production') { + module.exports = require('./cjs/schedule-tracking.profiling.min.js'); +} else { + module.exports = require('./cjs/schedule-tracking.development.js'); +} diff --git a/packages/schedule/package.json b/packages/schedule/package.json index db052a1edc91c..f0ce6c2a4c54c 100644 --- a/packages/schedule/package.json +++ b/packages/schedule/package.json @@ -20,6 +20,7 @@ "README.md", "index.js", "tracking.js", + "tracking-profiling.js", "cjs/", "umd/" ]