Commit Graph

38 Commits

Author SHA1 Message Date
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
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
Dan Abramov
95084bedbb Fix lint by removing unneeded type import 2016-11-02 12:45:15 -07:00
Andrew Clark
c3ab541e0f New effect type: Callback
This solves the problem I had with enqueueSetState and enqueueCallback
being separate.
2016-11-02 12:40:21 -07:00
Dan Abramov
2b26ea614d Fix the build (these tests were renamed) 2016-11-02 19:28:26 +00:00
Dan Abramov
99be3781ef [Fiber] Add more tests for scheduling (#8183)
* Add more tests for scheduling

* Remove ambiguous terms
2016-11-02 17:49:22 +00:00
Sebastian Markbåge
576542d0cf Handle the radio button case completely in the asap case (#8170)
Instead of scheduling individual callbacks to asap, we schedule one and
then do all the work in that one.

I'm doing this for architectural refactoring reasons.

Nevertheless, I'm adding a contrived unit test that this fixes. :)
2016-11-01 18:54:11 -07:00
Dan Abramov
1a49b5f563 [Fiber] Fix infinite loop in scheduler and add more tests (#8172)
* Make test more complete

* Add a failing test for scheduling in reverse order

It hangs forever because we don't clear next pointer when unscheduling a root. Therefore, when it's scheduled again, it brings all its previous chain with it, potentially creating a cycle.

* Clear the next pointer when unscheduling a root

Fixes a potential infinite cycle when we reschedule a root.

* Add new tests to Fiber test tracker
2016-11-01 17:44:57 +00:00
Ben Alpert
08b4cc53b8 Track passing/failing tests in fiber (#8169)
* Work around jest toEqual bug in ReactTreeTraversal

![image](https://cloud.githubusercontent.com/assets/6820/19879640/1cd7595a-9fb2-11e6-94ac-8c38bdfc90d3.png)

* Track passing/failing tests in fiber

Run scripts/fiber/record-tests to re-record, then check git diff to see what you changed.
2016-10-31 23:26:38 -07:00