Commit Graph

1009 Commits

Author SHA1 Message Date
Dominic Gannaway b83e01cade
Adds more scaffolding for experimental event API (#15112)
* Adds more scaffolding for experimental event API
2019-03-20 11:20:17 +00:00
Dominic Gannaway 55cc921c5d
Adds react-events package for internal testing (#15150)
* Adds react-events package for internal testing
2019-03-19 15:12:45 +00:00
Andrew Clark 42c3c967d1
Compile invariant directly to throw expressions (#15071)
* Transform invariant to custom error type

This transforms calls to the invariant module:

```js
invariant(condition, 'A %s message that contains %s', adj, noun);
```

Into throw statements:

```js
if (!condition) {
  if (__DEV__) {
    throw ReactError(`A ${adj} message that contains ${noun}`);
  } else {
    throw ReactErrorProd(ERR_CODE, adj, noun);
  }
}
```

The only thing ReactError does is return an error whose name is set
to "Invariant Violation" to match the existing behavior.

ReactErrorProd is a special version used in production that throws
a minified error code, with a link to see to expanded form. This
replaces the reactProdInvariant module.

As a next step, I would like to replace our use of the invariant module
for user facing errors by transforming normal Error constructors to
ReactError and ReactErrorProd. (We can continue using invariant for
internal React errors that are meant to be unreachable, which was the
original purpose of invariant.)

* Use numbers instead of strings for error codes

* Use arguments instead of an array

I wasn't sure about this part so I asked Sebastian, and his rationale
was that using arguments will make ReactErrorProd slightly slower, but
using an array will likely make all the functions that throw slightly
slower to compile, so it's hard to say which way is better. But since
ReactErrorProd is in an error path, and fewer bytes is generally better,
no array is good.

* Casing nit
2019-03-18 13:58:03 -07:00
Kayla Ngan ff4fb6d368 Remove facts tracker (#15111)
* Removed Travis references

* Remove used facts tracker
2019-03-15 19:25:06 +00:00
Dominic Gannaway 371bbf36bb
Add infrastructure for passive/non-passive event support for future API exploration (#15036)
* Add infrastructure for passive/non-passive event support for future event API experimentation
2019-03-15 09:39:43 +00:00
Andrew Clark bc8bd24c14
Run persistent mode tests in CI (#15029)
* Add command to run tests in persistent mode

* Convert Suspense fuzz tester to use noop renderer

So we can run it in persistent mode, too.

* Don't mutate stateNode in appendAllChildren

We can't mutate the stateNode in appendAllChildren because the children
could be current.

This is a bit weird because now the child that we append is different
from the one on the fiber stateNode. I think this makes conceptual
sense, but I suspect this likely breaks an assumption in Fabric.

With this approach, we no longer need to clone to unhide the children,
so I removed those host config methods.

Fixes bug surfaced by fuzz tester. (The test case that failed was the
one that's already hard coded.)

* In persistent mode, disable test that reads a ref

Refs behave differently in persistent mode. I added a TODO to write
a persistent mode version of this test.

* Run persistent mode tests in CI

* test-persistent should skip files without noop

If a file doesn't reference react-noop-renderer, we shouldn't bother
running it in persistent mode, since the results will be identical to
the normal test run.

* Remove module constructor from placeholder tests

We don't need this now that we have the ability to run any test file in
either mutation or persistent mode.

* Revert "test-persistent should skip files without noop"

Seb objected to adding shelljs as a dep and I'm too lazy to worry about
Windows support so whatever I'll just revert this.

* Delete duplicate file
2019-03-11 10:56:34 -07:00
Andrew Clark 69060e1da6
Swap expect(ReactNoop) for expect(Scheduler) (#14971)
* Swap expect(ReactNoop) for expect(Scheduler)

In the previous commits, I upgraded our custom Jest matchers for the
noop and test renderers to use Scheduler under the hood.

Now that all these matchers are using Scheduler, we can drop
support for passing ReactNoop and test roots and always pass
Scheduler directly.

* Externalize Scheduler in noop and test bundles

I also noticed we don't need to regenerator runtime in noop anymore.
2019-02-28 12:54:47 -08:00
Andrew Clark ccb2a8a44e
Replace test renderer's fake Scheduler implementation with mock build (#14970)
* Replace test renderer's fake Scheduler implementation with mock build

The test renderer has its own mock implementation of the Scheduler
interface, with the ability to partially render work in tests. Now that
this functionality has been lifted into a proper mock Scheduler build,
we can use that instead.

* Fix Profiler tests in prod
2019-02-28 10:50:38 -08:00
Andrew Clark 53e787b45f
Replace noop's fake Scheduler implementation with mock Scheduler build (#14969)
* Replace noop's fake Scheduler implementation with mock Scheduler build

The noop renderer has its own mock implementation of the Scheduler
interface, with the ability to partially render work in tests. Now that
this functionality has been lifted into a proper mock Scheduler build,
we can use that instead.

Most of the existing noop tests were unaffected, but I did have to make
some changes. The biggest one involved passive effects: previously, they
were scheduled on a separate queue from the queue that handles
rendering. After this change, both rendering and effects are scheduled
in the Scheduler queue. I think this is a better approach because tests
no longer have to worry about the difference; if you call `flushAll`,
all the work is flushed, both rendering and effects. But for those few
tests that do care to flush the rendering without the effects, that's
still possible using the `yieldValue` API.

Follow-up: Do the same for test renderer.

* Fix import to scheduler/unstable_mock
2019-02-28 10:30:46 -08:00
Andrew Clark 00748c53e1
Add new mock build of Scheduler with flush, yield API (#14964)
* Add new mock build of Scheduler with flush, yield API

Test environments need a way to take control of the Scheduler queue and
incrementally flush work. Our current tests accomplish this either using
dynamic injection, or by using Jest's fake timers feature. Both of these
options are fragile and rely too much on implementation details.

In this new approach, we have a separate build of Scheduler that is
specifically designed for test environments. We mock the default
implementation like we would any other module; in our case, via Jest.
This special build has methods like `flushAll` and `yieldValue` that
control when work is flushed. These methods are based on equivalent
methods we've been using to write incremental React tests. Eventually
we may want to migrate the React tests to interact with the mock
Scheduler directly, instead of going through the host config like we
currently do.

For now, I'm using our custom static injection infrastructure to create
the two builds of Scheduler — a default build for DOM (which falls back
to a naive timer based implementation), and the new mock build. I did it
this way because it allows me to share most of the implementation, which
isn't specific to a host environment — e.g. everything related to the
priority queue. It may be better to duplicate the shared code instead,
especially considering that future environments (like React Native) may
have entirely forked implementations. I'd prefer to wait until the
implementation stabilizes before worrying about that, but I'm open to
changing this now if we decide it's important enough.

* Mock Scheduler in bundle tests, too

* Remove special case by making regex more restrictive
2019-02-26 20:51:17 -08:00
Andrew Clark 8e25ed20bd
Unify noop and test renderer assertion APIs (#14952)
* Throw in tests if work is done before emptying log

Test renderer already does this. Makes it harder to miss unexpected
behavior by forcing you to assert on every logged value.

* Convert ReactNoop tests to use jest matchers

The matchers warn if work is flushed while the log is empty. This is
the pattern we already follow for test renderer. I've used the same APIs
as test renderer, so it should be easy to switch between the two.
2019-02-25 19:01:45 -08:00
Marco 1d6b1660a2 Fixed typo (#14943) 2019-02-24 09:50:23 -08:00
Brian Vaughn 33cb3f04f1
Release script clarifies which test fixture failed (#14922) 2019-02-22 07:43:27 -08:00
Brian Vaughn f708f9e307
Improve pactch release process docs (#14923) 2019-02-22 07:43:18 -08:00
Brian Vaughn 0e67969cb1
Prompt to include UMD build artifact links in GitHub release (#14864) 2019-02-15 10:48:20 -08:00
Brian Vaughn fad0842fd4
Release scripts documentation (#14863)
* Improve release script process documentation
* Improved pre-publish instructions/message based on feedback
* Added reminder to attach build artifacts to GitHub release
2019-02-15 10:00:43 -08:00
Dan Abramov 3e55560438 Release 16.8.2 2019-02-14 19:13:15 +00:00
Brian Vaughn aa9423701e Tweaked publish canary message to show newly published version 2019-02-06 18:24:51 +00:00
Brian Vaughn 0975ea3278 eslint-plugin-react-hooks v1.0.0 2019-02-06 10:14:57 +00:00
Brian Vaughn 008a2ab9cd 16.8.0 2019-02-06 08:04:00 +00:00
Brian Vaughn 8c1614a2fd
Tidy up NPM checkout process (#14631) 2019-01-18 11:40:50 -08:00
Brian Vaughn 4846809370
Prune NPM metadata fields from packages before re-publishing (#14617) 2019-01-17 14:34:34 -08:00
Brian Vaughn 0ca628b216
Rename release script fixture test scheduler->tracing (#14590) 2019-01-14 17:52:03 -08:00
Sunil Pai 3e15b1c690
make a fork for ReactCurrentDispatcher (#14588) 2019-01-14 16:35:56 +00:00
Andrew Clark c695b2384f React v16.7.0 2018-12-19 17:23:14 -08:00
Andrew Clark 1c5aa2f23a Move SchedulerFeatureFlags fork to src directory to fix lint 2018-12-18 11:09:44 -08:00
Andrew Clark 653bc582f9
Create separate SchedulerFeatureFlags instead of using ReactFeatureFlags (#14455) 2018-12-17 17:55:34 -08:00
Andrew Clark 4a1072194f
Memoize promise listeners to prevent exponential growth (#14429)
* Memoize promise listeners to prevent exponential growth

Previously, React would attach a new listener every time a promise is
thrown, regardless of whether the same listener was already attached
during a previous render. Because React attempts to render every time
a promise resolves, the number of listeners grows quickly.

This was especially bad in synchronous mode because the renders that
happen when the promise pings are not batched together. So if a single
promise has multiple listeners for the same root, there will be multiple
renders, which in turn results in more listeners being added to the
remaining unresolved promises. This results in exponential growth in
the number of listeners with respect to the number of IO-bound
components in a single render.

Fixes #14220

* Memoize on the root and Suspense fiber instead of on the promise

* Add TODO to fix persistent mode tests
2018-12-14 11:03:23 -08:00
Brian Vaughn 535804f5c8
Removed Fabric-specific feature flag files and updated Rollup to use the (non-Fabric) React Native flag files. (#14437) 2018-12-14 07:54:46 -08:00
Brian Vaughn 2743fb7b23
Enable hooks by default for FB React Native renderer (#14435)
* Enable hooks by default for FB React Native renderer
* Updated RN+FB feature flags to make some of the dynamic ones static
2018-12-13 13:20:23 -08:00
Heaven 947bddd5cf Remove redundant argument of getPlugins function (#14419) 2018-12-12 10:07:07 -08:00
Brian Vaughn ce43a8cd07
Updated version incrementing suggestion in release script based on team discussion (#14389) 2018-12-07 09:08:39 -08:00
Brian Vaughn e382b0ba95
Don't prompt to tag or create GitHub release for canary releases (#14376) 2018-12-03 09:16:17 -08:00
Brian Vaughn 8482cbe22d
Automated fixture tests (#14370)
* Renamed snapshot test from test.js to snapshot-test.js
* Automate fixtures tests
2018-12-02 11:25:45 -08:00
Brian Vaughn f00c2755b9
Removed unnecessary externals from Jest bundles (#14372) 2018-12-01 17:26:12 -08:00
Brian Vaughn 52bea95cfc
Fixed scheduler setTimeout fallback (#14358)
* Fixed scheduler setTimeout fallback
* Moved unit-test-specific setTimeout code into a new NPM package, jest-mock-scheduler.
2018-12-01 13:03:19 -08:00
Sebastian Markbåge 1d25aa5787
[Fizz] New Server Rendering Infra (#14144)
* [Fizz] Add Flow/Jest/Rollup build infra

Add a new package for react-stream which allows for custom server renderer
outputs. I picked the name because it's a reasonable name but also
because the npm name is currently owned by a friend of the project.

The react-dom build has its own inlined server renderer under the
name `react-dom/fizz`.

There is also a noop renderer to be used for testing. At some point
we might add a public one to test-renderer but for now I don't want to have
to think about public API design for the tests.

* Add FormatConfig too

We need to separate the format (DOM, React Native, etc) from the host
running the server (Node, Browser, etc).

* Basic wiring between Node, Noop and DOM configs

The Node DOM API is pipeToNodeStream which accepts a writable stream.

* Merge host and format config in dynamic react-stream entry point

Simpler API this way but also avoids having to fork the wrapper config.

Fixes noop builds.

* Add setImmediate/Buffer globals to lint config

Used by the server renderer

* Properly include fizz.node.js

Also use forwarding to it from fizz.js in builds so that tests covers
this.

* Make react-stream private since we're not ready to publish

or even name it yet

* Rename Renderer -> Streamer

* Prefix react-dom/fizz with react-dom/unstable-fizz

* Add Fizz Browser host config

This lets Fizz render to WHATWG streams. E.g. for rendering in a
Service Worker.

I added react-dom/unstable-fizz.browser as the entry point for this.

Since we now have two configurations of DOM. I had to add another
inlinedHostConfigs configuration called `dom-browser`. The reconciler
treats this configuration the same as `dom`. For stream it checks
against the ReactFizzHostConfigBrowser instead of the Node one.

* Add Fizz Browser Fixture

This is for testing server rendering - on the client.

* Lower version number to detach it from react-reconciler version
2018-11-30 11:38:22 -08:00
Dan Abramov 16e120438c
[Fire] Add initial build infrastructure (#14359) 2018-11-30 11:52:34 +00:00
Brian Vaughn 88ada98198
Release script auto-determine the latest Canary build if none specified (#14339)
* Release script auto-determine the latest Canary build if none specified
2018-11-28 13:56:45 -08:00
chun shang 48f1e5b3ce Add a null type test for memo (#14325) 2018-11-27 13:25:24 +00:00
Christoph Nakazawa 33f6f5e532
Remove usage of `fbjs/lib/invariant` in ReactNativeViewConfigRegistry. (#14330) 2018-11-26 21:48:08 +00:00
Brian Vaughn 409066a0a1
Add progress bars to longer running async release tasks (#14322)
* Add progress bars to longer running async release tasks
* Updated to 0.2 progress estimator version
2018-11-26 09:28:37 -08:00
Brian Vaughn ed4c4a51cd
Add basic release script snapshot test (#14280)
Added regression test for release scripts
2018-11-23 12:53:39 -08:00
Brian Vaughn 686f1060ad
Publish a local release (canary or stable) to NPM (#14260)
New release scripts.

Learn more at https://github.com/facebook/react/blob/master/scripts/release/README.md
2018-11-23 12:37:18 -08:00
Andrew Clark 3cd89daed9 Update error codes 2018-11-13 20:29:30 +00:00
Brian Vaughn 85f5a81eb7
Save CI-built node_modules as build artifacts (#14205)
* Store node_modules generated by CI script as an artifact
* NPM pack artifacts before archiving
2018-11-13 11:00:30 -08:00
Maksim Markelov d204747bef Update Readme (#14176)
Replace core with react, dom-client with react-dom
2018-11-12 16:25:32 +00:00
Sebastian Markbåge 961eb65b4b
Use unique thread ID for each partial render to access Context (#14182)
* BUG: ReactPartialRenderer / New Context polutes mutable global state

The new context API stores the provided values on the shared context instance. When used in a synchronous context, this is not an issue. However when used in an concurrent context this can cause a "push provider" from one react render to have an effect on an unrelated concurrent react render.

I've encountered this bug in production when using renderToNodeStream, which asks ReactPartialRenderer for bytes up to a high water mark before yielding. If two Node Streams are created and read from in parallel, the state of one can polute the other.

I wrote a failing test to illustrate the conditions under which this happens.

I'm also concerned that the experimental concurrent/async React rendering on the client could suffer from the same issue.

* Use unique thread ID for each partial render to access Context

This first adds an allocator that keeps track of a unique ThreadID index
for each currently executing partial renderer. IDs are not just growing
but are reused as streams are destroyed.

This ensures that IDs are kept nice and compact.

This lets us use an "array" for each Context object to store the current
values. The look up for these are fast because they're just looking up
an offset in a tightly packed "array".

I don't use an actual Array object to store the values. Instead, I rely
on that VMs (notably V8) treat storage of numeric index property access
as a separate "elements" allocation.

This lets us avoid an extra indirection.

However, we must ensure that these arrays are not holey to preserve this
feature.

To do that I store the _threadCount on each context (effectively it takes
the place of the .length property on an array).

This lets us first validate that the context has enough slots before we
access the slot. If not, we fill in the slots with the default value.
2018-11-09 15:38:20 -08:00
Andrew Clark 2dd4ba11e0 ESlint -> ESLint 2018-11-09 10:22:18 -08:00
Sophie Alpert 9cc631a539
Don't run danger on bad build (#14143)
sizebot comments can be confusing when not based on reality.

If results.json doesn't exist, danger will fail. This is what we want.
2018-11-09 10:21:39 -08:00