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

Remove SchedulerHostConfigs #20025

Merged
merged 7 commits into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
35 changes: 34 additions & 1 deletion packages/scheduler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,37 @@

'use strict';

export * from './src/Scheduler';
const isBrowserEnvironment =
typeof window !== 'undefined' && typeof MessageChannel === 'function';
Copy link
Member Author

Choose a reason for hiding this comment

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

Could I just drop this check and only export the DOM version if I update the callers during the sync?

Copy link
Member Author

Choose a reason for hiding this comment

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

The inline require breaks the build but I'll wait to hear back on this before fixing it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

For www you can lift the checks into the outer module wrapper, but for OSS this seems like the right place to put them.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually I guess the right place is here? https://github.com/facebook/react/blob/master/packages/scheduler/npm/index.js

I don't know what the best practice is in the npm ecosystem. Ideally we would handle this at the bundler level, using something like the browser field.

Copy link
Member Author

Choose a reason for hiding this comment

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

Perfect, thanks!


// Select the correct scheduler for this environment.
// TODO: this should be handled upstream by importing the correct scheduler.
let Scheduler;
if (isBrowserEnvironment) {
Scheduler = require('./src/forks/SchedulerDOM');
} else {
Scheduler = require('./src/forks/SchedulerNoDOM');
}

export const unstable_ImmediatePriority = Scheduler.unstable_ImmediatePriority;
export const unstable_UserBlockingPriority =
Scheduler.unstable_UserBlockingPriority;
export const unstable_NormalPriority = Scheduler.unstable_NormalPriority;
export const unstable_IdlePriority = Scheduler.unstable_IdlePriority;
export const unstable_LowPriority = Scheduler.unstable_LowPriority;
export const unstable_runWithPriority = Scheduler.unstable_runWithPriority;
export const unstable_next = Scheduler.unstable_next;
export const unstable_scheduleCallback = Scheduler.unstable_scheduleCallback;
export const unstable_cancelCallback = Scheduler.unstable_cancelCallback;
export const unstable_wrapCallback = Scheduler.unstable_wrapCallback;
export const unstable_getCurrentPriorityLevel =
Scheduler.unstable_getCurrentPriorityLevel;
export const unstable_shouldYield = Scheduler.unstable_shouldYield;
export const unstable_requestPaint = Scheduler.unstable_requestPaint;
export const unstable_continueExecution = Scheduler.unstable_continueExecution;
export const unstable_pauseExecution = Scheduler.unstable_pauseExecution;
export const unstable_getFirstCallbackNode =
Scheduler.unstable_getFirstCallbackNode;
export const unstable_now = Scheduler.unstable_now;
export const unstable_forceFrameRate = Scheduler.unstable_forceFrameRate;
export const unstable_Profiling = Scheduler.unstable_Profiling;
7 changes: 7 additions & 0 deletions packages/scheduler/npm/unstable_no_dom.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/scheduler-unstable_no_dom.production.min.js');
} else {
module.exports = require('./cjs/scheduler-unstable_no_dom.development.js');
}
1 change: 1 addition & 0 deletions packages/scheduler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"tracing.js",
"tracing-profiling.js",
"unstable_mock.js",
"unstable_no_dom.js",
Copy link
Member Author

Choose a reason for hiding this comment

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

I considered calling the NoDOM version Native since the primary user will be React Native, what do you think about the naming @acdlite?

Copy link
Collaborator

Choose a reason for hiding this comment

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

To me the primary purpose is to act as a last resort if you accidentally call this in a Node.js environment, like if you run a test without wrapping in act.

React Native will eventually need its own scheduler, so I'd rather not call this one a React Native scheduler since it's not optimized for that at all.

"unstable_post_task.js",
"cjs/",
"umd/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ describe('SchedulerBrowser', () => {

// Un-mock scheduler
jest.mock('scheduler', () => require.requireActual('scheduler'));
jest.mock('scheduler/src/SchedulerHostConfig', () =>
require.requireActual(
'scheduler/src/forks/SchedulerHostConfig.default.js',
),
);

runtime = installMockBrowserRuntime();
performance = global.performance;
Expand Down
7 changes: 2 additions & 5 deletions packages/scheduler/src/__tests__/SchedulerNoDOM-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ describe('SchedulerNoDOM', () => {
jest.useFakeTimers();

// Un-mock scheduler
jest.mock('scheduler', () => require.requireActual('scheduler'));
jest.mock('scheduler/src/SchedulerHostConfig', () =>
require.requireActual(
'scheduler/src/forks/SchedulerHostConfig.default.js',
),
jest.mock('scheduler', () =>
require.requireActual('scheduler/unstable_no_dom'),
);

Scheduler = require('scheduler');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ describe('Scheduling UMD bundle', () => {
jest.resetModules();

jest.mock('scheduler', () => require.requireActual('scheduler'));
jest.mock('scheduler/src/SchedulerHostConfig', () =>
require.requireActual(
'scheduler/src/forks/SchedulerHostConfig.default.js',
),
);
});

function filterPrivateKeys(name) {
Expand Down
Loading