Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from
Sep 10, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/react-reconciler/src/ReactFiberScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,16 @@ 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: does this line need to start with capital letter? Made reading the sentence a bit confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I can change the comment 😆

invariant(
__interactionsRef != null && __interactionsRef.current != null,
"Profiling renderer (e.g. 'react-dom/profiling') cannot be used with non-profiling 'schedule/tracking'. " +
"To fix, alias 'schedule/tracking' to 'schedule/tracking-profiling'.",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be bundler specific and I’m not sure they all use the “alias” wording.

Another thing to consider is that the person seeing this might be unaware that schedule package exists or what it is.

How about

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

The link points to a gist explaining how to do it in webpack. Later we change it to point to a blog post.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dig it. 👍 Thanks for the ideas Dan.

);
}

if (__DEV__) {
didWarnAboutStateTransition = false;
didWarnSetStateChildContext = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -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(
"Profiling renderer (e.g. 'react-dom/profiling') cannot be used with non-profiling 'schedule/tracking'.",
);
});
});
7 changes: 7 additions & 0 deletions packages/schedule/npm/tracking-profiling.js
Original file line number Diff line number Diff line change
@@ -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');
}
1 change: 1 addition & 0 deletions packages/schedule/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"README.md",
"index.js",
"tracking.js",
"tracking-profiling.js",
"cjs/",
"umd/"
]
Expand Down