@samitouri / QOS-React-2 / commits / 03ab1efeb4

Improve DX when combining react-dom/profiling and schedule/tracking (#13605)

* Added blessed production+profiling entry point for schedule/tracking * Add invariant when profiling renderer is used with non-profiling schedule/tracking

Brian Vaughn committed Sep 10, 2018 at 08:32 UTC 03ab1efeb4dde9e07b93ff038c87cc4fa443abf4
4 files changed +48
packages/react-reconciler/src/ReactFiberScheduler.js
+12
@@ -168,6 +168,18 @@ let didWarnSetStateChildContext;
168 let warnAboutUpdateOnUnmounted;
169 let warnAboutInvalidUpdates;
170
171 +if (enableSchedulerTracking) {
172 + // Provide explicit error message when production+profiling bundle of e.g. react-dom
173 + // is used with production (non-profiling) bundle of schedule/tracking
174 + invariant(
175 + __interactionsRef != null && __interactionsRef.current != null,
176 + 'It is not supported to run the profiling version of a renderer (for example, `react-dom/profiling`) ' +
177 + 'without also replacing the `schedule/tracking` module with `schedule/tracking-profiling`. ' +
178 + 'Your bundler might have a setting for aliasing both modules. ' +
179 + 'Learn more at http://fb.me/react-profiling',
180 + );
181 +}
182 +
183 if (__DEV__) {
184 didWarnAboutStateTransition = false;
185 didWarnSetStateChildContext = false;
packages/react-reconciler/src/__tests__/ReactTracking-test.internal.js new
+28
@@ -0,0 +1,28 @@
1 +/**
2 + * Copyright (c) Facebook, Inc. and its affiliates.
3 + *
4 + * This source code is licensed under the MIT license found in the
5 + * LICENSE file in the root directory of this source tree.
6 + *
7 + * @emails react-core
8 + * @jest-environment node
9 + */
10 +
11 +'use strict';
12 +
13 +describe('ReactTracking', () => {
14 + it('should error if profiling renderer and non-profiling schedule/tracking bundles are combined', () => {
15 + jest.resetModules();
16 +
17 + const ReactFeatureFlags = require('shared/ReactFeatureFlags');
18 + ReactFeatureFlags.enableSchedulerTracking = false;
19 +
20 + require('schedule/tracking');
21 +
22 + ReactFeatureFlags.enableSchedulerTracking = true;
23 +
24 + expect(() => require('react-dom')).toThrow(
25 + 'Learn more at http://fb.me/react-profiling',
26 + );
27 + });
28 +});
packages/schedule/npm/tracking-profiling.js new
+7
@@ -0,0 +1,7 @@
1 +'use strict';
2 +
3 +if (process.env.NODE_ENV === 'production') {
4 + module.exports = require('./cjs/schedule-tracking.profiling.min.js');
5 +} else {
6 + module.exports = require('./cjs/schedule-tracking.development.js');
7 +}
packages/schedule/package.json
+1
@@ -20,6 +20,7 @@
20 "README.md",
21 "index.js",
22 "tracking.js",
23 + "tracking-profiling.js",
24 "cjs/",
25 "umd/"
26 ]