Skip to content

Commit 03ab1ef

Browse files
authored
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
1 parent 144328f commit 03ab1ef

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

packages/react-reconciler/src/ReactFiberScheduler.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,18 @@ let didWarnSetStateChildContext;
168168
let warnAboutUpdateOnUnmounted;
169169
let warnAboutInvalidUpdates;
170170

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+
171183
if (__DEV__) {
172184
didWarnAboutStateTransition = false;
173185
didWarnSetStateChildContext = false;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"README.md",
2121
"index.js",
2222
"tracking.js",
23+
"tracking-profiling.js",
2324
"cjs/",
2425
"umd/"
2526
]

0 commit comments

Comments
 (0)