Commit Graph

9862 Commits

Author SHA1 Message Date
Timothy Yung
369dd4fb17 Update headers for React Native shims (#12806) 2018-05-15 01:47:47 +01:00
Dan Abramov
45b90d4866 Move renderer host configs into separate modules (#12791)
* Separate test renderer host config

* Separate ART renderer host config

* Separate ReactDOM host config

* Extract RN Fabric host config

* Extract RN host config
2018-05-15 01:12:28 +01:00
Timothy Yung
b2d16047ae Fix Type for ReactNative.NativeComponent (#12805) 2018-05-14 16:36:50 -07:00
Brian Vaughn
c802d29bd1 Use HostContext to warn about invalid View/Text nesting (#12766) 2018-05-14 15:34:01 -07:00
Andrew Clark
c5d3104fc0 Do not fire getDerivedStateFromProps unless props or state have changed (#12802)
Fixes an oversight from #12600. getDerivedStateFromProps should fire
if either props *or* state have changed, but not if *neither* have
changed. This prevents a parent from re-rendering if a deep child
receives an update.
2018-05-14 14:56:48 -07:00
Brian Vaughn
0ba63aa141 Mark React Native and Fabric renderers as @generated (#12801)
Mark React Native and Fabric renderers as @generated
2018-05-14 10:39:30 -07:00
Sophie Alpert
c4abfa4015 Add context provider/consumer to getComponentName (#12778)
RN Inspector uses these.
2018-05-14 10:10:36 -07:00
Sophie Alpert
2a4d2ca7fc Set owner correctly inside forwardRef and context consumer (#12777)
Previously, _owner would be null if you create an element inside forwardRef or inside a context consumer. This is used by ReactNativeFiberInspector when traversing the hierarchy and also to give more info in some warning texts. This also means you'll now correctly get a warning if you call setState inside one of these.

Test Plan: Tim tried it in the RN inspector.
2018-05-14 10:07:31 -07:00
Dan Abramov
72542030cf Use Java version of Google Closure Compiler (#12800)
* makes closure compiler threaded

* Dans PR with a closure compiler java version

* Remove unused dep

* Pin GCC

* Prettier

* Nit rename

* Fix error handling

* Name plugins consistently

* Fix lint

* Maybe this works?

* or this

* AppVeyor

* Fix lint
2018-05-14 17:49:41 +01:00
Dan Abramov
37d12e2916 Update lockfile 2018-05-14 16:20:33 +01:00
Dan Abramov
0470854f55 Split ReactNoop into normal and persistent exports (#12793)
* Copy-paste ReactNoop into ReactNoopPersistent

* Split ReactNoop into normal and persistent exports

* ReactNoopShared -> createReactNoop
2018-05-14 13:57:33 +01:00
Toru Kobayashi
d430e13582 Fix a typo (#12798) 2018-05-14 12:35:20 +01:00
Bartosz Kaszubowski
8506062975 remove unused ES3-specific packages - refs #12716 (#12797) 2018-05-14 11:18:31 +01:00
Dan
7b19f93ab9 Record sizes 2018-05-13 21:12:25 +01:00
Andrew Clark
4b2e65d32e Put recent change to getDerivedStateFromProps behind a feature flag (#12788)
This will allow us to safely ship it at Facebook and get a better idea
for if/how it breaks existing product code.
2018-05-11 18:45:00 -07:00
Filipp Riabchun
4f459bb144 Shallow renderer: pass component instance to setState updater as this (#12784)
* Shallow renderer: pass component instance to setState updater as `this`

* Run prettier
2018-05-11 18:03:08 +01:00
Andrew Clark
b0726e9947 Support sharing context objects between concurrent renderers (#12779)
* Support concurrent primary and secondary renderers.

As a workaround to support multiple concurrent renderers, we categorize
some renderers as primary and others as secondary. We only expect
there to be two concurrent renderers at most: React Native (primary) and
Fabric (secondary); React DOM (primary) and React ART (secondary).
Secondary renderers store their context values on separate fields.

* Add back concurrent renderer warning

Only warn for two concurrent primary or two concurrent secondary renderers.

* Change "_secondary" suffix to "2"

#EveryBitCounts
2018-05-10 18:34:01 -07:00
Andrew Clark
6565795377 Suspense (#12279)
* Timeout component

Adds Timeout component. If a promise is thrown from inside a Timeout component,
React will suspend the in-progress render from committing. When the promise
resolves, React will retry. If the render is suspended for longer than the
maximum threshold, the Timeout switches to a placeholder state.

The timeout threshold is defined as the minimum of:
- The expiration time of the current render
- The `ms` prop given to each Timeout component in the ancestor path of the
thrown promise.

* Add a test for nested fallbacks

Co-authored-by: Andrew Clark <acdlite@fb.com>

* Resume on promise rejection

React should resume rendering regardless of whether it resolves
or rejects.

* Wrap Suspense code in feature flag

* Children of a Timeout must be strict mode compatible

Async is not required for Suspense, but strict mode is.

* Simplify list of pending work

Some of this was added with "soft expiration" in mind, but now with our revised
model for how soft expiration will work, this isn't necessary.

It would be nice to remove more of this, but I think the list itself is inherent
because we need a way to track the start times, for <Timeout ms={ms} />.

* Only use the Timeout update queue to store promises, not for state

It already worked this way in practice.

* Wrap more Suspense-only paths in the feature flag

* Attach promise listener immediately on suspend

Instead of waiting for commit phase.

* Infer approximate start time using expiration time

* Remove list of pending priority levels

We can replicate almost all the functionality by tracking just five
separate levels: the highest/lowest priority pending levels, the
highest/lowest priority suspended levels, and the lowest pinged level.

We lose a bit of granularity, in that if there are multiple levels of
pending updates, only the first and last ones are known. But in practice
this likely isn't a big deal.

These heuristics are almost entirely isolated to a single module and
can be adjusted later, without API changes, if necessary.

Non-IO-bound work is not affected at all.

* ReactFiberPendingWork -> ReactFiberPendingPriority

* Renaming method names from "pending work" to "pending priority"

* Get rid of SuspenseThenable module

Idk why I thought this was neccessary

* Nits based on Sebastian's feedback

* More naming nits + comments

* Add test for hiding a suspended tree to unblock

* Revert change to expiration time rounding

This means you have to account for the start time approximation
heuristic when writing Suspense tests, but that's going to be
true regardless.

When updating the tests, I also made a fix related to offscreen
priority. We should never timeout inside a hidden tree.

* palceholder -> placeholder
2018-05-10 18:09:10 -07:00
Andrew Clark
42a1262375 Update sizes 2018-05-10 18:08:11 -07:00
Brian Vaughn
fc3777b1fe Add Profiler component for collecting new render timing info (#12745)
Add a new component type, Profiler, that can be used to collect new render time metrics. Since this is a new, experimental API, it will be exported as React.unstable_Profiler initially.

Most of the functionality for this component has been added behind a feature flag, enableProfileModeMetrics. When the feature flag is disabled, the component will just render its children with no additional behavior. When the flag is enabled, React will also collect timing information and pass it to the onRender function (as described below).
2018-05-10 15:25:32 -07:00
Flarnie Marchan
a9abd27e4f [schedule] Support multiple callbacks in scheduler (#12746)
* Support using id to cancel scheduled callback

**what is the change?:**
see title

**why make this change?:**
Once we support multiple callbacks you will need to use the id to
specify which callback you mean.

**test plan:**
Added a test, ran all tests, lint, etc.

* ran prettier

* fix lint

* Use object for storing callback info in scheduler

* Wrap initial test in a describe block

* Support multiple callbacks in `ReactScheduler`

**what is the change?:**
We keep a queue of callbacks instead of just one at a time, and call
them in order first by their timeoutTime and then by the order which
they were scheduled in.

**why make this change?:**
We plan on using this module to coordinate JS outside of React, so we
will need to schedule more than one callback at a time.

**test plan:**
Added a boatload of shiny new tests. :)

Plus ran all the old ones.

NOTE: The tests do not yet cover the vital logic of callbacks timing
out, and later commits will add the missing test coverage.

* Heuristic to avoid looking for timed out callbacks when none timed out

**what is the change?:**
Tracks the current soonest timeOut time for all scheduled callbacks.

**why make this change?:**
We were checking every scheduled callback to see if it timed out on
every tick. It's more efficient to skip that O(n) check if we know that
none have timed out.

**test plan:**
Ran existing tests.

Will write new tests to cover timeout behavior in more detail soon.

* Put multiple callback support under a disabled feature flag

**what is the change?:**
See title

**why make this change?:**
We don't have error handling in place yet, so should maintain the old
behavior until that is in place.

But want to get this far to continue making incremental changes.

**test plan:**
Updated and ran tests.

* Hide support for multiple callbacks under a feature flag

**what is the change?:**
see title

**why make this change?:**
We haven't added error handling yet, so should not expose this feature.

**test plan:**
Ran all tests, temporarily split out the tests for multiple callbacks
into separate file. Will recombine once we remove the flag.

* Fix nits from code review

See comments on https://github.com/facebook/react/pull/12743

* update checklist in comments

* Remove nested loop which calls additional timed out callbacks

**what is the change?:**
We used to re-run any callbacks which time out whilst other callbacks
are running, but now we will only check once for timed out callbacks
then then run them.

**why make this change?:**
To simplify the code and the behavior of this module.

**test plan:**
Ran all existing tests.

* Remove feature flag

**what is the change?:**
see title

**why make this change?:**
Because only React is using this, and it sounds like async. rendering
won't hit any different behavior due to these changes.

**test plan:**
Existing tests pass, and this allowed us to recombine all tests to run
in both 'test' and 'test-build' modes.

* remove outdated file

* fix typo
2018-05-09 15:28:13 -07:00
bee0060
3fb8be5c30 Minor fix params description for addPercent function (#12669) 2018-05-07 17:46:42 -07:00
Toru Kobayashi
0bf24cc83e setState returning null and undefined is no-op on the ShallowRenderer (#12756) 2018-05-07 17:31:33 -07:00
Dan Abramov
25dda90c1e Mark context consumers with PerformedWork effect on render (#12729)
* Mark new component types with PerformedWork effect

* Don't do it for ForwardRef

Since this has some overhead and ForwardRef is likely going to be used around context, let's skip it.
We don't highlight ForwardRef alone in DevTools anyway.
2018-05-02 16:35:16 +01:00
Dan Abramov
ad7cd68667 Rename internal property to fix React DevTools (#12727) 2018-05-01 21:04:20 +01:00
Sophie Alpert
200357596a Add error when running jest directly (#12726)
```
$ jest
 FAIL  scripts/jest/dont-run-jest-directly.js
  ● Test suite failed to run

    Don't run `jest` directly. Run `yarn test` instead.

    > 1 | throw new Error("Don't run `jest` directly. Run `yarn test` instead.");
      2 |

      at Object.<anonymous> (scripts/jest/dont-run-jest-directly.js:1:96)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        0.866s
Ran all test suites.
```
2018-05-01 12:46:17 -07:00
Dan Abramov
e0ca51a85d Make React.forwardRef() components discoverable by TestRenderer traversal (#12725) 2018-05-01 19:55:06 +01:00
Toru Kobayashi
7dd4ca2911 Call getDerivedStateFromProps even for setState of ShallowRenderer (#12676) 2018-04-30 17:04:40 +01:00
Dan Abramov
9a9f54720f Remove ES3-specific transforms (#12716) 2018-04-30 14:30:37 +01:00
Airam
dcc854bcc3 prevent removing attributes on custom component tags (#12702) 2018-04-28 20:52:30 +01:00
Dan Abramov
045d4f166d Fix a context propagation bug (#12708)
* Fix a context propagation bug

* Add a regression test
2018-04-28 01:52:48 +01:00
Dan Abramov
7c39328571 Don't bail on new context Provider if a legacy provider rendered above (#12586)
* Don't bail on new context Provider if a legacy provider rendered above

* Avoid an extra variable
2018-04-26 20:59:17 +01:00
Dan Abramov
d883d59863 forwardRef() components should not re-render on deep setState() (#12690)
* Add a failing test for forwardRef memoization

* Memoize forwardRef props and bail out on strict equality

* Bail out only when ref matches the current ref
2018-04-26 19:47:34 +01:00
Heaven
ec57d29941 Remove redundant feature flag in the test due to https://github.com/facebook/react/pull/12117 (#12696) 2018-04-26 18:39:11 +01:00
Flarnie Marchan
9c77ffb444 Dedup conditional in ReactScheduler (#12680)
**what is the change?:**
We had a condition to set either 'performance.now' or 'Date.now' as the
'now' function.

Then later we had another conditional checking again if
'performance.now' was supported, and using it if so, otherwise falling
back to 'Date.now'.

More efficient to just use the 'now' shortcut defined above.

**why make this change?:**
Fewer lines, clearer code.

**test plan:**
Now that we have tests we can run them :)
2018-04-24 08:54:31 -07:00
Andrew Clark
09a14eacd4 Update bundle sizes 2018-04-23 19:38:07 -07:00
Andrew Clark
1673485720 Revert stray console.log 2018-04-23 18:44:14 -07:00
Flarnie Marchan
1e3cd332a0 Remove the 'alwaysUseRequestIdleCallbackPolyfill' feature flag (#12648)
* Remove the 'alwaysUseRequestIdleCallbackPolyfill' feature flag

**what is the change?:**
Removes the feature flag 'alwaysUseRequestIdleCallbackPolyfill', such
that we **always** use the polyfill for requestIdleCallback.

**why make this change?:**
We have been testing this feature flag at 100% for some time internally,
and determined it works better for React than the native implementation.
Looks like RN was overriding the flag to use the native when possible,
but since no RN products are using 'async' mode it should be safe to
switch this flag over for RN as well.

**test plan:**
We have already been testing this internally for some time.

**issue:**
internal task t28128480

* fix mistaken conditional

* Add mocking of rAF, postMessage, and initial test for ReactScheduler

**what is the change?:**
- In all tests where we previously mocked rIC or relied on native
mocking which no longer works, we are now mocking rAF and postMessage.
- Also adds a basic initial test for ReactScheduler.
NOTE -> we do plan to write headless browser tests for ReactScheduler!
This is just an initial test, to verify that it works with the mocked
out browser APIs as expected.

**why make this change?:**
We need to mock out the browser APIs more completely for the new
'ReactScheduler' to work in our tests. Many tests are depending on it,
since it's used at a low level.

By mocking the browser APIs rather than the 'react-scheduler' module, we
enable testing the production bundles. This approach is trading
isolation for accuracy. These tests will be closer to a real use.

**test plan:**
run the tests :)

**issue:**
internal task T28128480
2018-04-23 15:25:46 -07:00
Brian Vaughn
149a34f735 Exposed flushSync on the test renderer (#12672) 2018-04-23 10:27:39 -07:00
Andrew Clark
b548b3cd64 Decouple update queue from Fiber type (#12600)
* Decouple update queue from Fiber type

The update queue is in need of a refactor. Recent bugfixes (#12528) have
exposed some flaws in how it's modeled. Upcoming features like Suspense
and [redacted] also rely on the update queue in ways that weren't
anticipated in the original design.

Major changes:

- Instead of boolean flags for `isReplace` and `isForceUpdate`, updates
have a `tag` field (like Fiber). This lowers the cost for adding new
types of updates.
- Render phase updates are special cased. Updates scheduled during
the render phase are dropped if the work-in-progress does not commit.
This is used for `getDerivedStateFrom{Props,Catch}`.
- `callbackList` has been replaced with a generic effect list. Aside
from callbacks, this is also used for `componentDidCatch`.

* Remove first class UpdateQueue types and use closures instead

I tried to avoid this at first, since we avoid it everywhere else in the Fiber
codebase, but since updates are not in a hot path, the trade off with file size
seems worth it.

* Store captured errors on a separate part of the update queue

This way they can be reused independently of updates like
getDerivedStateFromProps. This will be important for resuming.

* Revert back to storing hasForceUpdate on the update queue

Instead of using the effect tag. Ideally, this would be part of the
return type of processUpdateQueue.

* Rename UpdateQueue effect type back to Callback

I don't love this name either, but it's less confusing than UpdateQueue
I suppose. Conceptually, this is usually a callback: setState callbacks,
componentDidCatch. The only case that feels a bit weird is Timeouts,
which use this effect to attach a promise listener. I guess that kinda
fits, too.

* Call getDerivedStateFromProps every render, even if props did not change

Rather than enqueue a new setState updater for every props change, we
can skip the update queue entirely and merge the result into state at
the end. This makes more sense, since "receiving props" is not an event
that should be observed. It's still a bit weird, since eventually we do
persist the derived state (in other words, it accumulates).

* Store captured effects on separate list from "own" effects (callbacks)

For resuming, we need the ability to discard the "own" effects while
reusing the captured effects.

* Optimize for class components

Change `process` and `callback` to match the expected payload types
for class components. I had intended for the update queue to be reusable
for both class components and a future React API, but we'll likely have
to fork anyway.

* Only double-invoke render phase lifecycles functions in DEV

* Use global state to track currently processing queue in DEV
2018-04-22 23:05:28 -07:00
Nicole Levy
5dcf93d146 Validate props on context providers (#12658)
* checkPropTypes in updateContextProvider

* invalid “prop”

* `type not `types` .. :l

* test

* don’t need extra check with no spelling mistake (:

* change error message to specifically address provider

* don’t need class, add extra render to make sure good props go through

* nitpicky rename

* prettier

* switch to `Context.Provider`

* add stack to warning, add extra undefined check

* separate dev check

* add stack to test

* more efficient

* remove unused function

* prettier

* const to top
2018-04-22 13:39:38 +01:00
Dan Abramov
c040bcbea8 Add server integration tests for new context (#12654)
* Add server integration tests for new context

* Pretty please

* Remove unused
2018-04-21 21:21:05 +01:00
Flarnie Marchan
999b656ed1 Initial commit (#12624)
This is the first step - pulling the ReactDOMFrameScheduling module out
into a separate package.

Co-authored-by: Brandon Dail <aweary@users.noreply.github.com>
2018-04-19 09:29:08 -07:00
Brian Vaughn
f80bbf88e5 StrictMode should not warn about polyfilled getSnapshotBeforeUpdate (#12647)
* Installed 3.x release of react-lifecycles-compat
* Updated ReactComponentLifeCycle-test and ReactDOMServerLifecycles-test to cover both polyfilled lifecycles in StrictMode
* Updated StrictMode warnings to not warn about polyfilled getSnapshotBeforeUpdate
2018-04-19 09:08:44 -07:00
Brian Vaughn
920f30ef77 Add forwardRef DEV warning for prop-types on render function (#12644) 2018-04-18 16:36:31 -07:00
Brian Vaughn
0887c7d56c Fork React Native renderer into FB and OSS bundles (#12625)
* Added new "native-fb" and "native-fabric-fb" bundles.
* Split RN_DEV and RN_PROD bundle types into RN_OSS_DEV, RN_OSS_PROD, RN_FB_DEV, and RN_FB_PROD. (This is a bit redundant but it seemed the least intrusive way of supporting a forked feature flags file for these bundles.)
* Renamed FB_DEV and FB_PROD bundle types to be more explicitly for www (FB_WWW_DEV and FB_WWW_PROD)
* Removed Haste @providesModule headers from the RB-specific RN renderer bundles to avoid a duplicate name conflicts.
* Remove dynamic values from OSS RN feature flags. (Leave them in FB RN feature flags.)
* Updated the sync script(s) to account for new renderer type.
* Move ReactFeatureFlags.js shim to FB bundle only (since OSS bundle no longer needs dynamic values).
2018-04-18 13:16:50 -07:00
Sebastian Markbåge
039695cc01 [RN] Update Secret Types (#12635) 2018-04-17 19:21:46 -07:00
Dan Abramov
b05e67e36a Bump Prettier (#12622) 2018-04-17 01:43:55 +01:00
Brian Vaughn
77ebeb1b09 Don't git commit noop-renderer unless package deps change (#12623) 2018-04-16 09:46:39 -07:00
Heaven
b85c5cd188 remove duplicate code in test (#12620) 2018-04-16 16:36:49 +01:00