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

Conversation

rickhanlonii
Copy link
Member

Summary

Refactors the scheduler to remove SchedulerHostConfigs in favor of separate Schedulers:

  • SchedulerDOM: Scheduler.js + DOM branch of SchedulerHostConfig.default.js
  • SchedulerNoDOM: Scheduler.js + fallback branch of SchedulerHostConfig.default.js
  • SchedulerMock: Scheduler.js + SchedulerHostConfig.mock.js
  • SchedulerPostTask: unchanged

For the mean time, I've included a switch in index.js to select either the DOM or NoDOM version.

Clients should be updated to select the correct version:

import Scheduler from 'scheduler'; // DOM by default
import Scheduler from 'scheduler/unstable_no_dom';
import Scheduler from 'scheduler/unstable_mock';
import Scheduler from 'scheduler/unstable_post_task';

@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 14, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 1527bb9:

Sandbox Source
React Configuration

@@ -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!

@@ -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.

@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Oct 14, 2020
@sizebot
Copy link

sizebot commented Oct 14, 2020

Details of bundled changes.

Comparing: 7e405d4...1527bb9

scheduler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
SchedulerNoDOM-prod.js n/a n/a 0 B 8.65 KB 0 B 2.2 KB FB_WWW_PROD
scheduler-unstable_mock.development.js +1.9% +1.7% 23.47 KB 23.92 KB 5.38 KB 5.47 KB UMD_DEV
scheduler-unstable_post_task.production.min.js 0.0% 🔺+0.2% 1.94 KB 1.94 KB 858 B 860 B NODE_PROD
SchedulerNoDOM-profiling.js n/a n/a 0 B 13.45 KB 0 B 3.13 KB FB_WWW_PROFILING
Scheduler-dev.js -5.6% -3.7% 25 KB 23.59 KB 6.4 KB 6.17 KB FB_WWW_DEV
Scheduler-prod.js -9.4% -5.6% 11.81 KB 10.7 KB 2.91 KB 2.75 KB FB_WWW_PROD
Scheduler-profiling.js -6.7% -4.1% 16.61 KB 15.5 KB 3.81 KB 3.66 KB FB_WWW_PROFILING
SchedulerMock-dev.js +1.9% +1.7% 21.96 KB 22.38 KB 5.27 KB 5.36 KB RN_FB_DEV
SchedulerMock-prod.js 🔺+2.2% 🔺+1.4% 11.17 KB 11.42 KB 2.66 KB 2.69 KB RN_FB_PROD
scheduler-unstable_no_dom.development.js n/a n/a 0 B 18.23 KB 0 B 4.69 KB NODE_DEV
Scheduler-dev.js -6.7% -4.8% 22.73 KB 21.21 KB 5.91 KB 5.62 KB RN_FB_DEV
scheduler-unstable_no_dom.production.min.js n/a n/a 0 B 3.46 KB 0 B 1.45 KB NODE_PROD
Scheduler-prod.js -10.5% -6.3% 10.9 KB 9.76 KB 2.7 KB 2.53 KB RN_FB_PROD
Scheduler-profiling.js -7.9% -4.8% 14.72 KB 13.56 KB 3.5 KB 3.33 KB RN_FB_PROFILING
SchedulerNoDOM-dev.js n/a n/a 0 B 19.03 KB 0 B 4.81 KB FB_WWW_DEV
scheduler-unstable_mock.production.min.js 🔺+2.6% 🔺+2.3% 4.56 KB 4.68 KB 1.93 KB 1.98 KB UMD_PROD
scheduler-unstable_mock.development.js +1.9% +1.8% 21.88 KB 22.3 KB 5.26 KB 5.36 KB NODE_DEV
scheduler-unstable_mock.production.min.js 🔺+2.7% 🔺+2.1% 4.52 KB 4.64 KB 1.84 KB 1.88 KB NODE_PROD
SchedulerNoDOM-dev.js n/a n/a 0 B 18.23 KB 0 B 4.68 KB RN_FB_DEV
SchedulerNoDOM-prod.js n/a n/a 0 B 8.38 KB 0 B 2.11 KB RN_FB_PROD
SchedulerMock-dev.js +2.0% +1.9% 22.73 KB 23.18 KB 5.39 KB 5.49 KB FB_WWW_DEV
SchedulerNoDOM-profiling.js n/a n/a 0 B 12.2 KB 0 B 2.93 KB RN_FB_PROFILING
scheduler.development.js -6.7% -4.6% 22.63 KB 21.12 KB 5.9 KB 5.63 KB NODE_DEV
SchedulerMock-prod.js 🔺+2.3% 🔺+1.8% 11.44 KB 11.7 KB 2.74 KB 2.79 KB FB_WWW_PROD
scheduler.production.min.js -10.2% -5.5% 4.73 KB 4.25 KB 1.89 KB 1.79 KB NODE_PROD

react

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react.development.js -1.6% -1.2% 108.45 KB 106.75 KB 26.5 KB 26.19 KB UMD_DEV
React-dev.js 0.0% 0.0% 90 KB 90 KB 21.4 KB 21.41 KB RN_FB_DEV
react-jsx-dev-runtime.development.js 0.0% -0.0% 36.88 KB 36.88 KB 10.6 KB 10.59 KB NODE_DEV
react.production.min.js -3.8% -3.0% 11.2 KB 10.77 KB 4.48 KB 4.34 KB UMD_PROD
react.profiling.min.js -2.9% -2.5% 14.71 KB 14.28 KB 5.56 KB 5.42 KB UMD_PROFILING
React-dev.js 0.0% -0.0% 97.77 KB 97.77 KB 23.63 KB 23.63 KB FB_WWW_DEV
React-prod.js 0.0% 0.0% 17.02 KB 17.02 KB 4.42 KB 4.42 KB FB_WWW_PROD
React-profiling.js 0.0% 0.0% 17.02 KB 17.02 KB 4.42 KB 4.42 KB FB_WWW_PROFILING

React: size: -3.8%, gzip: -3.0%

Size changes (stable)

Generated by 🚫 dangerJS against 1527bb9

@sizebot
Copy link

sizebot commented Oct 14, 2020

Details of bundled changes.

Comparing: 7e405d4...1527bb9

scheduler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
SchedulerNoDOM-prod.js n/a n/a 0 B 8.65 KB 0 B 2.2 KB FB_WWW_PROD
scheduler-unstable_mock.development.js +1.9% +1.8% 23.48 KB 23.94 KB 5.38 KB 5.48 KB UMD_DEV
scheduler-unstable_post_task.production.min.js 0.0% 🔺+0.2% 1.95 KB 1.95 KB 867 B 869 B NODE_PROD
SchedulerNoDOM-profiling.js n/a n/a 0 B 13.45 KB 0 B 3.13 KB FB_WWW_PROFILING
Scheduler-dev.js -5.6% -3.7% 25 KB 23.59 KB 6.4 KB 6.17 KB FB_WWW_DEV
Scheduler-prod.js -9.4% -5.6% 11.81 KB 10.7 KB 2.91 KB 2.75 KB FB_WWW_PROD
Scheduler-profiling.js -6.7% -4.1% 16.61 KB 15.5 KB 3.81 KB 3.66 KB FB_WWW_PROFILING
SchedulerMock-dev.js +1.9% +1.7% 21.96 KB 22.38 KB 5.27 KB 5.36 KB RN_FB_DEV
SchedulerMock-prod.js 🔺+2.2% 🔺+1.4% 11.17 KB 11.42 KB 2.66 KB 2.69 KB RN_FB_PROD
scheduler-unstable_no_dom.development.js n/a n/a 0 B 18.25 KB 0 B 4.71 KB NODE_DEV
scheduler-tracing.development.js 0.0% -0.1% 8.81 KB 8.81 KB 1.79 KB 1.79 KB NODE_DEV
Scheduler-dev.js -6.7% -4.8% 22.73 KB 21.21 KB 5.91 KB 5.62 KB RN_FB_DEV
scheduler-unstable_no_dom.production.min.js n/a n/a 0 B 3.47 KB 0 B 1.46 KB NODE_PROD
scheduler-tracing.production.min.js 0.0% 🔺+0.3% 685 B 685 B 353 B 354 B NODE_PROD
Scheduler-prod.js -10.5% -6.3% 10.9 KB 9.76 KB 2.7 KB 2.53 KB RN_FB_PROD
Scheduler-profiling.js -7.9% -4.8% 14.72 KB 13.56 KB 3.5 KB 3.33 KB RN_FB_PROFILING
SchedulerNoDOM-dev.js n/a n/a 0 B 19.03 KB 0 B 4.81 KB FB_WWW_DEV
scheduler-unstable_mock.production.min.js 🔺+2.6% 🔺+2.3% 4.58 KB 4.69 KB 1.94 KB 1.99 KB UMD_PROD
scheduler-unstable_mock.development.js +1.9% +1.8% 21.89 KB 22.31 KB 5.27 KB 5.37 KB NODE_DEV
scheduler-unstable_mock.production.min.js 🔺+2.7% 🔺+2.1% 4.53 KB 4.65 KB 1.85 KB 1.89 KB NODE_PROD
SchedulerNoDOM-dev.js n/a n/a 0 B 18.23 KB 0 B 4.68 KB RN_FB_DEV
SchedulerNoDOM-prod.js n/a n/a 0 B 8.38 KB 0 B 2.11 KB RN_FB_PROD
SchedulerMock-dev.js +2.0% +1.9% 22.73 KB 23.18 KB 5.39 KB 5.49 KB FB_WWW_DEV
SchedulerNoDOM-profiling.js n/a n/a 0 B 12.2 KB 0 B 2.93 KB RN_FB_PROFILING
scheduler.development.js -6.6% -4.6% 22.64 KB 21.13 KB 5.91 KB 5.64 KB NODE_DEV
SchedulerMock-prod.js 🔺+2.3% 🔺+1.8% 11.44 KB 11.7 KB 2.74 KB 2.79 KB FB_WWW_PROD
scheduler.production.min.js -10.1% -5.5% 4.74 KB 4.26 KB 1.9 KB 1.79 KB NODE_PROD

react

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-jsx-runtime.development.js 0.0% -0.0% 37.47 KB 37.47 KB 10.77 KB 10.77 KB NODE_DEV
react.development.js -1.5% -1.2% 112.43 KB 110.73 KB 27.23 KB 26.9 KB UMD_DEV
react-unstable-cache.development.js 0.0% +0.2% 1.05 KB 1.05 KB 588 B 589 B NODE_DEV
React-dev.js 0.0% -0.0% 89 KB 89 KB 21.17 KB 21.17 KB RN_FB_DEV
react-unstable-cache.profiling.min.js 0.0% -0.2% 866 B 866 B 563 B 562 B NODE_PROFILING
react-jsx-dev-runtime.development.js 0.0% -0.0% 36.89 KB 36.89 KB 10.6 KB 10.6 KB NODE_DEV
react.production.min.js -3.5% -2.7% 12.3 KB 11.88 KB 4.79 KB 4.66 KB UMD_PROD
react.profiling.min.js -2.7% -2.1% 15.82 KB 15.39 KB 5.88 KB 5.75 KB UMD_PROFILING
React-dev.js 0.0% -0.0% 96.77 KB 96.77 KB 23.4 KB 23.4 KB FB_WWW_DEV

React: size: -3.5%, gzip: -2.7%

Size changes (experimental)

Generated by 🚫 dangerJS against 1527bb9

@rickhanlonii
Copy link
Member Author

rickhanlonii commented Oct 20, 2020

@acdlite There's one test left that's failing and it's related to requiring react-dom in a node environment. Is that related to server-rendering? How were you thinking we would support that, check for window in react-dom?

@acdlite
Copy link
Collaborator

acdlite commented Oct 30, 2020

@rickhanlonii The test is failing when running against the source files because the checks that you added in npm/index.js only affect the final build artifacts. Whereas Jest imports Scheduler.js directly.

It does pass during the yarn test --build jobs because those run against the build artifacts.

So I would either modify the Jest config to go through the npm/index.js file, or I would disable this particular test when running against source.

@rickhanlonii
Copy link
Member Author

Good point @acdlite, I added a @gate source pragma for disabling tests based on source/build env.

This is ready for review now!

@rickhanlonii rickhanlonii marked this pull request as ready for review October 30, 2020 14:18
@rickhanlonii rickhanlonii merged commit 454c221 into facebook:master Nov 2, 2020
@rickhanlonii rickhanlonii deleted the rh-refector-scheduler branch November 2, 2020 17:47
@@ -1,6 +1,8 @@
'use strict';

if (process.env.NODE_ENV === 'production') {
if (typeof window === 'undefined' || typeof MessageChannel !== 'function') {
module.exports = require('./unstable_no_dom');
Copy link
Collaborator

@sebmarkbage sebmarkbage Nov 3, 2020

Choose a reason for hiding this comment

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

I'm not sure about this pattern because it's the first time we start doing this kind of switching in the npm wrappers and it won't port nicely to ESM. The thing that we do for production is a static switch which we can move into a compiler but we can't do the same for this.

We should move this branching into the implementation which forces us to treat this nicely in an ESM world.

facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request Nov 9, 2020
Summary:
Base sync before adding Flight files.

This sync includes the following changes:
- **[454c2211c](facebook/react@454c2211c )**: Refactor SchedulerHostConfigs ([#20025](facebook/react#20025)) //<Ricky>//
- **[56e9feead](facebook/react@56e9feead )**: Remove Blocks ([#20138](facebook/react#20138)) //<Sebastian Markbåge>//
- **[3fbd47b86](facebook/react@3fbd47b86 )**: Serialize pending server components by reference (lazy component) ([#20137](facebook/react#20137)) //<Sebastian Markbåge>//
- **[930ce7c15](facebook/react@930ce7c15 )**: Allow values to be encoded by "reference" to a value rather than the value itself ([#20136](facebook/react#20136)) //<Sebastian Markbåge>//
- **[39eb6d176](facebook/react@39eb6d176 )**: Rename ([#20134](facebook/react#20134)) //<Sebastian Markbåge>//
- **[ffd842335](facebook/react@ffd842335 )**: [Flight] Add support for Module References in transport protocol ([#20121](facebook/react#20121)) //<Sebastian Markbåge>//
- **[343d7a4a7](facebook/react@343d7a4a7 )**: Fast Refresh: Don't block DevTools commit hook ([#20129](facebook/react#20129)) //<Brian Vaughn>//
- **[779a472b0](facebook/react@779a472b0 )**: Prevent inlining into recursive commit functions ([#20105](facebook/react#20105)) //<Andrew Clark>//
- **[25b18d31c](facebook/react@25b18d31c )**: Traverse commit phase effects iteratively ([#20094](facebook/react#20094)) //<Andrew Clark>//

Changelog:
[General][Changed] - React Native sync for revisions 4e5d7fa...454c221

Reviewed By: rickhanlonii

Differential Revision: D24698701

fbshipit-source-id: dfaf692b1051150355dece1657764a484b7ae603
}
// There's no pending input. Only yield if we've reached the max
// yield interval.
return currentTime >= maxYieldInterval;

Choose a reason for hiding this comment

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

Should this be currentTime - deadline >= maxYieldInterval?

koto pushed a commit to koto/react that referenced this pull request Jun 15, 2021
* Remove SchedulerHostConfigs

* Fix builds

* Fix forks

* Move SchedulerNoDom check to npm/index.js

* Fix tests

* Add @GATE source

* Gate build-only test to build test runs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed React Core Team Opened by a member of the React Core Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants