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

Warn when rendering tests in concurrent/sync mode without a mocked scheduler #16207

Conversation

threepointone
Copy link
Contributor

@threepointone threepointone commented Jul 25, 2019

Concurrent/Sync mode tests should always be run with a mocked scheduler (v17 or not). This PR adds a warning for the same. I'll put up a separate PR to the docs with a page detailing how to mock the scheduler.

@sizebot
Copy link

sizebot commented Jul 25, 2019

Details of bundled changes.

Comparing: e276a5e...e2858f6

react-art

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-art.development.js +0.2% +0.3% 642.29 KB 643.87 KB 139.99 KB 140.46 KB UMD_DEV
react-art.development.js +0.3% +0.4% 573.16 KB 574.75 KB 122.7 KB 123.17 KB NODE_DEV
react-art.production.min.js 0.0% 0.0% 67.53 KB 67.53 KB 20.6 KB 20.6 KB NODE_PROD
ReactART-dev.js +0.3% +0.4% 586.95 KB 588.74 KB 122.26 KB 122.77 KB FB_WWW_DEV

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom-server.browser.development.js 0.0% 0.0% 136.79 KB 136.79 KB 36.14 KB 36.14 KB UMD_DEV
ReactDOM-dev.js +0.2% +0.3% 929.97 KB 931.75 KB 205.61 KB 206.14 KB FB_WWW_DEV
react-dom-test-utils.development.js -5.1% -7.3% 58.68 KB 55.72 KB 16.12 KB 14.95 KB UMD_DEV
react-dom-unstable-fizz.browser.development.js 0.0% +0.1% 3.78 KB 3.78 KB 1.52 KB 1.52 KB UMD_DEV
react-dom-test-utils.development.js -5.2% -7.5% 56.95 KB 53.99 KB 15.8 KB 14.62 KB NODE_DEV
react-dom.development.js +0.2% +0.2% 906.65 KB 908.23 KB 205.29 KB 205.76 KB UMD_DEV
ReactTestUtils-dev.js -3.0% -3.4% 54.29 KB 52.66 KB 14.5 KB 14.01 KB FB_WWW_DEV
react-dom.development.js +0.2% +0.2% 900.94 KB 902.53 KB 203.81 KB 204.28 KB NODE_DEV
react-dom-server.node.development.js 0.0% 0.0% 134.85 KB 134.85 KB 35.75 KB 35.76 KB NODE_DEV
react-dom-server.browser.development.js 0.0% 0.0% 132.92 KB 132.92 KB 35.22 KB 35.22 KB NODE_DEV

react-test-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactTestRenderer-dev.js +0.2% +0.2% 598.74 KB 599.73 KB 124.95 KB 125.22 KB FB_WWW_DEV
react-test-renderer-shallow.development.js 0.0% -0.0% 33.5 KB 33.5 KB 8.51 KB 8.51 KB NODE_DEV
react-test-renderer.development.js +0.2% +0.2% 586.92 KB 587.8 KB 125.58 KB 125.81 KB UMD_DEV
react-test-renderer.development.js +0.2% +0.2% 582.46 KB 583.34 KB 124.47 KB 124.69 KB NODE_DEV

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler.development.js +0.3% +0.4% 571.24 KB 572.83 KB 121.2 KB 121.71 KB NODE_DEV
react-reconciler-persistent.development.js +0.3% +0.4% 568.39 KB 569.98 KB 120.02 KB 120.49 KB NODE_DEV
react-reconciler-persistent.production.min.js 0.0% 0.0% 68.76 KB 68.76 KB 20.44 KB 20.44 KB NODE_PROD

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactFabric-dev.js +0.2% +0.3% 733.68 KB 735.47 KB 154.97 KB 155.49 KB RN_FB_DEV
ReactNativeRenderer-dev.js +0.2% +0.3% 720.97 KB 722.76 KB 152.51 KB 153.04 KB RN_OSS_DEV
ReactNativeRenderer-dev.js +0.2% +0.3% 721.06 KB 722.85 KB 152.56 KB 153.08 KB RN_FB_DEV
ReactFabric-dev.js +0.2% +0.3% 733.58 KB 735.37 KB 154.93 KB 155.45 KB RN_OSS_DEV

react-noop-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-noop-renderer-server.production.min.js 0.0% -0.2% 813 B 813 B 491 B 490 B NODE_PROD
react-noop-renderer-persistent.development.js -7.7% -13.6% 38.55 KB 35.57 KB 9.52 KB 8.23 KB NODE_DEV
react-noop-renderer-persistent.production.min.js 0.0% -0.0% 12.08 KB 12.08 KB 3.82 KB 3.82 KB NODE_PROD
react-noop-renderer.development.js -7.8% -13.6% 38.43 KB 35.45 KB 9.51 KB 8.21 KB NODE_DEV
react-noop-renderer.production.min.js 0.0% 0.0% 12.06 KB 12.06 KB 3.81 KB 3.82 KB NODE_PROD

Generated by 🚫 dangerJS

@threepointone threepointone force-pushed the warn-unmocked-scheduler-when-concurrent-batched branch from bb8a6b4 to 78b5880 Compare July 25, 2019 16:58
@acdlite
Copy link
Collaborator

acdlite commented Jul 25, 2019

I don't think we're going to call it "batched mode" publicly. We use that term now to distinguish it from the legacy synchronous mode.

But in the future, only "batched" and concurrent modes will exist. In that world, "batched" doesn't make sense because concurrent mode is also batched. So our current plan for the naming of the three modes is:

  • Legacy modeReactDOM.render
  • Sync mode - ReactDOM.createSyncRoot
  • Concurrent mode - ReactDOM.createRoot

I sometimes refer to the two synchronous modes as "legacy sync" and "batched sync" if there's ambiguity.

@threepointone threepointone force-pushed the warn-unmocked-scheduler-when-concurrent-batched branch from 78b5880 to d5419a6 Compare July 25, 2019 17:33
@threepointone
Copy link
Contributor Author

Noted, changed "Batched" for "Sync" in the messages.

@threepointone threepointone changed the title Warn when rendering tests in concurrent/batched mode without a mocked scheduler Warn when rendering tests in concurrent/sync mode without a mocked scheduler Jul 25, 2019
threepointone added a commit to threepointone/reactjs.org that referenced this pull request Jul 25, 2019
This PR adds a page on how to mock the scheduler, as a companion to facebook/react#16207.

(Most people won't see this, since nobody's using concurrent/sync modes yet.)
@threepointone threepointone force-pushed the warn-unmocked-scheduler-when-concurrent-batched branch from d5419a6 to eb9908c Compare July 25, 2019 23:47
@threepointone
Copy link
Contributor Author

I moved the one in the act() definition into this new one, much prefer it this way.

@threepointone threepointone force-pushed the warn-unmocked-scheduler-when-concurrent-batched branch 3 times, most recently from 048ac70 to 461c8a7 Compare July 26, 2019 02:48
@threepointone
Copy link
Contributor Author

renamed some stuff for consistency
warnAboutMissingMockScheduler -> warnAboutUnmockedScheduler
warnIfNotMockedScheduler -> warnIfUnmockedScheduler
didWarnAboutNotMockedScheduler -> didWarnAboutUnmockedScheduler

@threepointone threepointone force-pushed the warn-unmocked-scheduler-when-concurrent-batched branch from 461c8a7 to 61e545f Compare July 26, 2019 12:23
@@ -47,6 +48,9 @@ import {
scheduleSyncCallback,
} from './SchedulerWithReactIntegration';

// The scheduler is imported here *only* to detect whether it's been mocked
import * as Scheduler from 'scheduler';
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 could have also exported isSchedulerMocked from SchedulerWithReactIntegration.js if we want to prevent this import here.

@threepointone threepointone force-pushed the warn-unmocked-scheduler-when-concurrent-batched branch 2 times, most recently from a33244e to 9154e61 Compare July 26, 2019 12:54
@threepointone threepointone force-pushed the warn-unmocked-scheduler-when-concurrent-batched branch from 9154e61 to f2fbc75 Compare July 26, 2019 16:53
@threepointone
Copy link
Contributor Author

ping!

@acdlite
Copy link
Collaborator

acdlite commented Jul 29, 2019

I find it weird that most developers will never interact with Scheduler, but we're asking them to mock it.

If we provide them with a testing build of React DOM (and the other renderers), would that replace the need to mock the Scheduler package? I think it would in the normal case. The exception is if your framework interacts with Scheduler directly (instead of via built-in APIs like useSuspenseTransition).

Btw, this doesn't affect 16.9, right? Since both createRoot and createSyncRoot are unstable.

@threepointone
Copy link
Contributor Author

So you’re right about your points in the short term. As you said, just the testing build will not be sufficient in the future, because a consumer may well use the scheduler directly via scheduler.next, etc. So in the future, we’ll end up asking them to mock the scheduler anyway.

The reason I raised this PR, was to help early adopters with their tests. Assuming we won’t do another release for a few months, this could at least guide the shape of their tests and make it easier when we do make changes and demand a testing build etc. So let’s say, 6 months out, when we do ship, at least their tests wouldn’t break horribly. If we had testing builds right now, we could’ve suggested that, but this seemed like low effort-moderate win to be had now. Most, like 99%, of folks won’t see this warning, but the ones that do, tests will still work as expected for them.

@threepointone
Copy link
Contributor Author

(This isn’t really blocking 16.9, happy to punt, but figured it would be a nice-to-have)

@threepointone
Copy link
Contributor Author

btw, the linked doc (reactjs/react.dev#2171, preview at https://deploy-preview-2171--reactjs.netlify.com/docs/mock-scheduler.html) tries to make the role of the scheduler clearer

@threepointone threepointone force-pushed the warn-unmocked-scheduler-when-concurrent-batched branch from f2fbc75 to 591b50b Compare July 30, 2019 17:52
… scheduler

Concurrent/Batched mode tests should always be run with a mocked scheduler (v17 or not). This PR adds a warning for the same. I'll put up a separate PR to the docs with a page detailing how to mock the scheduler.
@threepointone threepointone force-pushed the warn-unmocked-scheduler-when-concurrent-batched branch from 591b50b to e2858f6 Compare July 30, 2019 17:54
@threepointone
Copy link
Contributor Author

pending item: land the doc PR, and set up the fb.me link. Will do.

@threepointone threepointone merged commit e6a0473 into facebook:master Jul 30, 2019
@threepointone threepointone deleted the warn-unmocked-scheduler-when-concurrent-batched branch July 30, 2019 18:00
NMinhNguyen referenced this pull request in enzymejs/react-shallow-renderer Jan 29, 2020
… scheduler (#16207)

Concurrent/Batched mode tests should always be run with a mocked scheduler (v17 or not). This PR adds a warning for the same. I'll put up a separate PR to the docs with a page detailing how to mock the scheduler.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants