Commit Graph

110 Commits

Author SHA1 Message Date
Tom Occhino
dfdff2b61a Move all dev *Hook tests and ComponentTreeTestUtils to expectDev (#8350) 2016-11-18 18:53:48 +00:00
Sebastian Markbåge
0deb71223d Fix ReactDOMFiberSelect to set the initial values (#8349)
I forgot that the normal properties route doesn't do this. We also have
to make sure that the order is 1) insert children (options), 2) set
multiple 3) update the options.
2016-11-18 18:52:15 +00:00
Sebastian Markbage
c1daa6f2c1 Record tests and fix BrowserEventEmitter test to not crash jest 2016-11-18 18:08:40 +00:00
Sebastian Markbage
a2ca759dfd Handle controlled components in Fiber
We need to adjust inputValueTracking a bit to handle the fact that
Fiber attaches wrapper state on nodes.
2016-11-18 17:59:36 +00:00
Sebastian Markbage
836331ba5f Wire up ReactDOMFiberComponent in ReactDOMFiber
We'll need to do the DOM injection now.
2016-11-18 12:01:22 +00:00
Tom Occhino
32f5b034ed Upgrade ESLint and dependencies, fix new lint errors, switch Travis to Yarn (#8309)
* Update ESLint to 3.10.2

Also pull in fbjs for extending properly, per @zpao. This also disables consistent-return, which has about 80 failing cases in React currently. If we'd like to turn this back on, we should do it separately and fix all the call sites properly (rather than just adding 'return undefined;' everywhere, which adds no value.

Fixes to all existing lint errors plus an update for yarn.lock to follow.

* Update yarn.lock after the eslint update.

* Fix all new eslint failures

Unfortunately I had to add three eslint-disable-next-line instances. All have explanations inline.

* Switch Travis to use yarn instead of npm
2016-11-17 22:16:44 +00:00
Ben Alpert
8ecb248e6d Make numerical refs work in Fiber (#8334) 2016-11-17 18:56:33 +00:00
Sebastian Markbage
4e2688db4a Extract event listener from memoizedProps on Fiber instances
This makes some basic events work with Fiber.

This is however not a complete solution since we may be reading the wrong
Fiber.
2016-11-16 15:56:13 +00:00
Sebastian Markbage
b3af02a3cd Add Fibers to ReactTreeTraversal
This traverses parent based on the type of internal instance it is passed.
If it is a Fiber it may have to traverse multiple steps until it finds a
HostComponent.

This will allow us to use the event system with Fiber.
2016-11-16 15:43:55 +00:00
Sebastian Markbage
57cc182f26 Add Fibers to ReactDOMComponentTree
This adds precaching to ReactDOMFiber. I.e. adding a handle from the DOM
node to the internal Fiber. This means that we need to expose an internal
handle to the reconciler.

We use duck typing to figure out if it is a Fiber or Stack instance.

The new failing tests are failing because this is now able to actually
fire events onto Fibers and then the result of those events are
incorrect where as they were ignored before.
2016-11-16 15:42:39 +00:00
Sebastian Markbåge
dde670fd36 Reapply Check for event listener in props instead of bank (#8292)
* Reapply Check for event listener in props instead of bank (#8192)

This reverts the previous revert.

* Don't throw on falsy event listeners

Some code relies on passing null. This restores the earlier behavior.
2016-11-15 18:16:27 +01:00
Dan Abramov
2397f1fce6 Use empty object if context does not exist
This matches Stack behavior.
Had to rewrite a test that used Simulate because Fiber doesn't support events yet.
Also changed tests for componentDidUpdate() since Fiber intentionally doesn't pass prevContext argument.
2016-11-15 16:35:00 +00:00
Dan Abramov
fd8c8038f0 Update passing tests 2016-11-15 14:49:54 +00:00
Dan Abramov
eedca6f641 Disable memoized props bailout when context might have changed 2016-11-14 18:24:32 +00:00
Dan Abramov
f9e1bc9c97 Move context management into scheduler
It is error-prone to push and pop context in begin or complete phases because of all the bailouts. Scheduler has enough knowledge to see if pushing is necessary because it knows when we go inside or outside the tree.
2016-11-14 13:32:09 +00:00
Dan Abramov
b8cca3711e Update passing tests 2016-11-14 13:32:09 +00:00
Dan Abramov
9a42f8a0c5 Update passing tests 2016-11-14 13:22:47 +00:00
Ben Alpert
64cba04bf9 Build infra for tracking dev-specific failures (#8228)
I'll plan to change all of our console.error and component-tree expects to expectDev. It's a little annoying that we need to make sure tests don't throw (see my change to normalizeCodeLocInfo) but any alternative would seem to require two separate test runs or a much more cumbersome syntax.
2016-11-13 14:00:07 -08:00
Ankeet Maini
077822e9d0 Handles risky callbacks on setState. Fixes #8238 (#8242)
* Handles risky callbacks on setState. Fixes #8238

* Updates try-catch to cover `callback` when context is not present.

* Updates code to trapErrors instead of swallowing them.

* Fixes flow errors

* Incorporates review comments

* Traps only the first error.

Removes `callbackWasCalled` and updates fiber tests.
2016-11-12 12:51:36 -08:00
Sebastian Markbåge
4804518c26 Handle nested controlled events (#8251)
I came up with a contrived case of where nested controlled events could
fire within the same batch - but on different targets.

I think we came to the conclusion that controlled values typically cannot
use preventDefault so it is ok that they don't flush until after the event
has finished. So therefore we accumulate a queue of all the nested targets
within a batch and then restore state on all of them.

I'm still skeptical that this is the correct way to do controlled values.
The reason we have to do them in a single event loop is because when you
type, the sequence of values that get accepted or not can matter. I wonder
if there is a scenario we can come up with where you can fire multiple
inner events in an event loop and end up with batching causing problems.

This effectively just reimplements asap again but with no allocations for
a single target and no closure allocations.
2016-11-11 16:49:59 +00:00
Brandon Dail
e43aaab254 Use _hostContainerInfo to track test renderer options (#8261)
* Use _hostContainerInfo to track test renderer options

The transaction is not available when unmounting or updating the
instance, so we track it using _hostContainerInfo

* Throw if hostContainerInfo is not populated in getPublicInstance

* Linting fixes

* Remove transaction from ref lifecycle code path

We don't need to pass the transaction around anymore since we store the
test options on _hostContainerInfo instead

* Remove unused argument
2016-11-11 14:35:18 +00:00
Dan Abramov
da021ca4ae Use ReactDOM.unstable_batchedUpdates in Fiber tests (#8263) 2016-11-10 21:28:49 +00:00
Dan Abramov
a9fa135fd8 [Fiber] Fix reactComponentExpect (#8258) (#8257)
* Add more reactComponentExpect tests

* Implement reactComponentExpect in Fiber
2016-11-10 21:27:07 +00:00
Dan Abramov
3e2680411e [Fiber] Fix reactComponentExpect (#8258)
* Add more reactComponentExpect tests

* Implement reactComponentExpect in Fiber
2016-11-10 21:19:57 +00:00
Toru Kobayashi
d0a8d8b951 [Fiber]Warn when shoulcComponentUpdate returns undefined (#8243)
* [Fiber]Warn when shoulcComponentUpdate returns undefined

* Remove unnecessary fallback
2016-11-09 16:30:41 +00:00
Sebastian Markbåge
84b8bbdfc9 Fixed batching reentrant controlled events (#8240)
If a controlled target fires within another controlled event, we should not
restore it until we've fully completed the event. Otherwise, if someone
reads from it afterwards, they'll get the restored value.

Not super happy with this particular solution.
2016-11-08 17:42:53 -08:00
Andrew Clark
f829e2f1f1 Meant to commit these changes with #8206... oops. 2016-11-08 13:47:31 -08:00
Andrew Clark
c33230e563 Merge pull request #8206 from acdlite/fibertasklifecycleupdates
[Fiber] Updates from inside componentDidMount/Update should have Task priority
2016-11-08 13:28:29 -08:00
Andrew Clark
d9d4ad60c5 Updates from inside componentDidMount/Update should have Task priority.
This is only observable in incremental mode.
2016-11-08 13:27:31 -08:00
Keyan Zhang
46609cb95c Fix error codes (#7999)
* took codes.json from the 15-dev branch

* fixed react:extract-errors task in gulpfile

* generated error codes

* Revert "generated error codes"

This reverts commit b8f3aeed9d8f0d469edd5f6623fa6090930594d8.

* Added a README for the error code system
2016-11-08 20:20:46 +00:00
Sebastian Markbåge
b2eaafaf3b Revert "Check for event listener in props instead of bank (#8192)" (#8239)
This reverts commit a878c3056d.

The previous stuff that this builds on didn't successfully land fully. Since I
want to measure this in isolation, I'll revert this for now.
2016-11-08 11:32:54 -08:00
Sebastian Markbåge
a878c3056d Check for event listener in props instead of bank (#8192)
This just reads events from the props instead of storing them in a
listener back.

I had to rewrite a bunch of tests to cover this model.
I removed the tests that just test the adding and removing over listeners
since there is no equivalent behavior anymore.
2016-11-07 20:36:58 -08:00
Sebastian Markbåge
2f893b5914 Revert normalized text node fix (#8231)
This reverts the implementation in 33325ad009.

I didn't mean to merge the implementation since it is incorrect and incomplete.
I meant to just merge the unit test.
2016-11-07 18:27:58 -08:00
Sebastian Markbåge
75691af209 Rerun tests (#8230)
* Ensure that we're listening to all onChange dependencies for controlled inputs

When there is no onChange event handler, we should still listen to it to
ensure controlled values get reset.

There is warning associated with this but the prod behavior should still be
respected.

* Rerun tests
2016-11-07 16:49:43 -08:00
Sebastian Markbåge
90878df08d Use explicit pass for restoring controlled state instead of asap (#8176)
* Use explicit pass for restoring controlled state instead of asap

This gets rid of the first class ReactUpdates.asap scheduling. Instead of
scheduling a first class function to invoke later, I introduce an explicit
phase for restoring controlled state after dispatching events.

We assume that the deepest event target is the thing that needs its state
restored.

* Drop special cases for onChange in wrappers

We're now not using anything special about onChange handling in the
wrappers. Yay!
2016-11-07 13:31:33 -08:00
Ben Alpert
75ff12e984 Run fiber tests just once on Travis (#8221)
Consolidate facts tracking with the other script.
2016-11-07 11:43:29 -08:00
Ben Alpert
c4b9330f2a Hide detailed failure output in scripts/fiber/record-tests (#8214)
![image](https://cloud.githubusercontent.com/assets/6820/20033841/a55fefa4-a367-11e6-99c0-44dfe38e1db7.png)
2016-11-07 11:43:02 -08:00
Ben Alpert
84c57ddc6d Fix errors in ReactNativeMount (#8223) 2016-11-07 11:42:39 -08:00
Robin Ricard
33325ad009 [Fiber] Attempt to fix ReactDOMTextComponent test in Fiber (#8146)
* Attempt to fix ReactDOMTextComponent test in Fiber

Obviously, some tests pass but the reconciliation is still incomplete on this in Fiber.

Those changes just ignore reconciliation Comments while asserting (this fixes 2 tests already) but now shows that Fiber lacks some reconciliation features.

* Transmit a parentInstance to commitTextUpdate

This is done in case a Node#normalize() was performed on the parent instance and that the TextInstance got desolidarized from the parent. We provide the parent known by the parent Fiber to reattach the DOM node in this case.

* Added a more complex case around split nodes

This test does not assume one split node substitution alone but also some non-split nodes.

* Fiber supports split text nodes

This is done by suppressing nodes appearing during the split. this is based by comparing against the old value known by the Fiber.

* Simplify siblings cleaning in commitTextUpdate

No need to assert instanceof Text since the length comparator will work correctly.

* Ensure non-text nodes won't be removed

* Fix flow for Fiber Text reconciliation additions

Mostly define types as optionals. Respects the strict DOM API around Node & Element.

* Append at any stack stage only if necessary

The direct parent of the TextNode fiber may not contain the host node. We have to go through the hierarchy. However, since this work may be expensive, we only do it if absolutely necessary!

* Use tag & ReactTypeOfWork to find an HostComponent

* Addfailing scenario when running Node.normalize()

It happens when non-text-elements are added in the mix. @sebmarkbage seems to have an idea on how to fix it. This is just a repro of the bug!

* Register failing/passing fiber tests
2016-11-07 11:39:52 -08:00
Sebastian Markbåge
95334fada0 Track if SelectEventPlugin is attached on a per document basis (#8190)
This gets rid of the global flag on if something has listened to onSelect
and instead reads the isListening map if all the events are covered.
This is required if we want to attach events locally at roots.

Could be slower perf wise to handle events. An alternative solution would
be to attach a special flag on the listener map for the document so we
don't have to check the full dependency list.

However, my favorite solution would be to just eagerly attach all event
listeners (except maybe wheel). Then we don't have to do any of this stuff
on a per element basis.
2016-11-07 11:30:34 -08:00
Ben Alpert
f705adb599 Re-record tests 2016-11-05 14:59:22 -07:00
Ben Alpert
5f49b63bde Move setState callback to right after didUpdate (#8204)
It's much easier to do it this way in Fiber and there shouldn't be much observable difference.
2016-11-05 14:37:43 -07:00
Robin Ricard
ba6b53afba [Fiber] Complete ES6 Class related errors support (#8156)
* Print a warning in fiber for lacking render method

* Reject initial non-object state in Fiber

Rejects Arrays, Strings & Numbers. Allows nulls.

* Centralize fiber checks on ES6 Classes

* Add classic & instance property checks on fiber

- check the absence of getInitialState & getDefaultProps as methods
- check the absence of propTypes & contextTypes at instance-level

* Convert to normalized React `warning` calls

* Support lifecycle typo detection in fiber

* Get the complete warnings from the existing code

* Only check classInstance once

Avoid rechecking while resuming

* Can warn component while resuming but only once

This is achieved by tracking the warning state in the Fiber structure.

* Remove warning deduplication

* Factor name retrieval in a getName helper

* Use invariant instead of throw

* Read inst.state only once for the invariant

* Fix condition on the instance state

* Register failing/passing fiber tests
2016-11-05 11:19:48 -07:00
Dan Abramov
c80f390823 Make error handling more resilient
* Ensure that errors in one root don't prevent work on another root
* Fix an issue where boundary state change would get ignored in incremental mode
2016-11-04 23:35:50 +00:00
Andrew Clark
4266f08e48 [Fiber] "Task" priority for error boundaries and batched updates (#8193)
* Refactor scheduling functions and introduce Task priority

There was lots of duplication across all the scheduling functions. I
think we're far enough along that we can start trying to clean some
stuff up.

Also introduces a new priority level provisionally called Task priority.
This is for work that completes at the end of the current tick, after
the current batch of work has been committed. It's different from
Synchronous priority, which needs to complete immediately.

A full implementation of Task priority will follow. It will replace
the current batching solution.

* Implement Task priority

Task priority is similar to Synchronous priority. Both are flushed in
the current tick. Synchronous priority is flushed immediately (e.g. sync
work triggered by setState will flush before setState exits), where as
Task is flushed after the current batch of work is committed.

Currently used for batchedUpdates and nested sync updates. Task should
also be used for componentDidUpdate/Mount and error boundary work. I'll
add this in a later commit.

* Make error boundaries use Task Priority

I have all but one error fixed. Not sure how tricky the last one is,
but I'm cautiously optimistic. Pushing to show my current progress.

* Remove recursion from handleErrors

Changed the algorithm of handleErrors a bit to ensure that boundaries
are not revisited once they are acknowledged.

* Add incremental error boundary test

Discovered an edge case: a noop error boundary will break in incremental
mode unless you explicitly schedule an update.

* Refactor error boundaries in Fiber

* Simplify trapError() calls

The existing logic was written before we had a proper error handling system.

* Remove unnecessary flags

* Prevent performTaskWork recursion

* Be stricter about preventing recursion
2016-11-04 19:40:50 +00:00
Ben Alpert
f4a42b872b Fiber: Fix reconciling after null (#8202)
Before, this code was bailing out after encoutering a null child because it thought it was out of old children. Seen when reconciling [null, <span />, <Image />] with [null, <span />, <Image />] in XUISelector.
2016-11-03 23:56:29 -07:00
Dan Abramov
857672f7e7 Update passing tests 2016-11-03 14:41:39 +00:00
Andrew Clark
29dbbc31c9 UpdateQueue fixes
- Incorrect comparison when computing hasUpdate
- isReplace should be a property of the node, not the queue
2016-11-02 23:00:00 -07:00
Dan Abramov
c894679b75 [Fiber] Schedule animation regardless of deferred work (#8187)
* Remove comments about implementation details

* Schedule animation regardless of deferred work
2016-11-02 20:46:20 +00:00
Dan Abramov
eb674e47c8 [Fiber] Add tests for scheduling inside callbacks (#8186)
* Add tests for scheduling inside callbacks

* Don't test implementation details
2016-11-02 20:11:27 +00:00