Commit Graph

177 Commits

Author SHA1 Message Date
Dan Abramov
c87ffc0beb [Fiber] Support SVG (#8490)
* Test that SVG elements get created with the right namespace

* Pass root to the renderer methods

* Keep track of host instances and containers

* Keep instances instead of fibers on the stack

* Create text instances in begin phase

* Create instance before bailing on offscreen children

Otherwise, the parent gets skipped next time.
We could probably create it later but this seems simpler.

* Tweak magic numbers in incremental tests

I don't understand why they changed but probably related to us moving some work into begin phase?

* Only push newly created nodes on the parent stack

Previously I was pushing nodes on the parent stack regardless of whether they were already in current or not.
As a result, insertions during updates were duplicated, and nodes were added to existing parents before commit phase.
Luckily we have a test that caught that.

* Fix lint

* Fix Flow

I had to wrap HostContext API into a closure so that it's parameterizeable with I and C.

* Use the same destructuring style in scheduler as everywhere else

* Remove branches that don't seem to run anymore

I'm not 100% sure this is right but I can't get tests to fail.

* Be explicit about the difference between type and tag

I was confused by th HACK comment so I learned how DOM and SVG work with casing and tried to write a more descriptive comment.
It also seems like passing fiber.type into finalizeInitialChildren() is a potential problem because DOM code assumes tag is lowercase.
So I added a similar "hack" to finalizeInitialChildren() that is identical to the one we have prepareUpdate() so if we fix them later, we fix both.

* Save and restore host context when pushing and popping portals

* Revert parent context and adding children in the begin phase

We can address this later separately as it is a more hot path.
This doesn't affect correctness of SVG container behavior.

* Add a test for SVG updates

This tests the "jump" reuse code path in particular.

* Record tests

* Read ownerDocument from the root container instance

This way createInstance() depends on the innermost container only for reading the namespace.

* Track namespaces instead of creating instances early

While we might want to create instance in the begin phase, we shouldn't let DOM guide reconciler design.
Instead, we are adding a new concept of "host context". In case of ReactDOMFiber, it's just the current namespace.
We are keeping a stack of host context values, ignoring those that are referentially equal.
The renderer receives the parent context and type, and can return a new context.

* Pop child context before reading own context and clarify API

It wasn't quite clear from the API which context was being returned by the renderer. Changed the API to specifically ask for child context, and thus to pop it before getting the current context.

This fixes the case with <foreignObject> to which I intended to give SVG namespace.

* Give SVG namespace to <svg> itself

* Don't allocate unnecessarily when reconciling portals

We create stacks lazily so that if portal doesn't contain <svg>s, we don't need to allocate.
We also reuse the same object for portal host context state instead of creating a new one every time.

* Add more tests for edge cases

* Fix up math namespace

* Maintain a separate container stack

* Fix rebase mistakes

* Unwind context on errors

* Reset the container state when reusing the object

* Add getChildHostContext() to ReactART

* Record tests
2016-12-08 13:10:47 -08:00
Andrew Clark
f56eb89389 Add additional scheduling tests
Tests whether certain types of work can be performed after the deadline
has expired.
2016-12-07 23:09:08 -08:00
Andrew Clark
2508888a2b Errors thrown when detaching a ref should not interrupt unmount
If a ref throws while detaching, it should not prevent
componentWillUnmount from being called.

Additionally, errors thrown by removeChild should not be ignored, even
as the result of unmounting a failed subtree.
2016-12-07 23:09:08 -08:00
Andrew Clark
5fcdebf712 Move commit phase outside of performUnitOfWork
This gives us the ability to complete a tree without having to commit it
within the same frame.
2016-12-07 23:09:08 -08:00
Brian Vaughn
9510ecfc5e Merge pull request #8521 from bvaughn/react-art-fiber
New fiber-based ReactART renderer
2016-12-07 18:35:48 -08:00
Ben Alpert
4d71a9c580 Probably fix facts tracker 2016-12-07 16:04:47 -08:00
Brian Vaughn
81cb216288 Imported new ReactART fiber renderer
Split ReactART into stack and fiber targets. Added new ReactART test case for recently-fixed bug.
2016-12-07 15:35:53 -08:00
Brian Vaughn
9a3139121c Merge pull request #8520 from bvaughn/do-not-reset-inner-html-for-null-children
Do not reset inner html for null children
2016-12-07 15:35:13 -08:00
Brian Vaughn
bbdfc28002 Updated tests-passing 2016-12-07 15:34:32 -08:00
Sebastian Markbåge
343fb958f1 Add test for componentDidUpdate with a bailout in the middle (#8525)
This is one of the cases where Fiber diverges.
2016-12-07 15:14:32 -08:00
Ben Alpert
29a1707911 Support parallelism on Circle (#8511) 2016-12-07 14:55:34 -08:00
Ben Alpert
d8b591d584 Fix pull request detection on Circle 2016-12-07 13:45:06 -08:00
Brian Vaughn
2533fa8d35 Do not reset innerHTML for elements with null children
This is required to support certain third party scripts as well as other fiber renderers (eg the new ReactART renderer)
2016-12-07 12:06:06 -08:00
Ben Alpert
6ca66f70ca Update facts-tracker for Circle (#8510) 2016-12-06 22:24:19 -08:00
Sebastian Markbåge
facce3d736 Use Portals to test batching across roots (#8508)
This doesn't work by default in Fiber, you have to opt-in with a Portal to
get the explicit ordering guarantees.
2016-12-06 13:46:36 -08:00
Sebastian Markbåge
0723007e1e Merge pull request #8450 from sebmarkbage/fiberfinddomnode
[Fiber] Fix findDOMNode and findAllInRenderedTree
2016-12-02 16:34:46 -08:00
Ben Alpert
a104525e7f Only upload build if server exists (#8488) 2016-12-02 14:31:17 -08:00
Tom Occhino
153fe38403 Add circle.yml / CircleCI support (#8486) 2016-12-02 14:18:12 -08:00
Sebastian Markbage
a434f9e7af Fix findDOMNode and findAllInRenderedFiberTreeInternal
This strategy finds the current fiber. It traverses back up to the root if
the two trees are completely separate and determines which one is current.
If the two trees converge anywhere along the way, we assume that is the
current tree. We find the current child by searching the converged child
set.

This could fail if there's any way for both return pointers to point
backwards to the work in progress. I don't think there is but I could be
wrong.

This may also fail on coroutines where we have reparenting situations.
2016-12-01 21:21:05 -08:00
Sebastian Markbage
4fd1802ddf Additional findDOMNode tests
This is failing in Fiber without the fix. Because we have no deletions to rely
on in this case and the placement effects have already happened.
2016-12-01 21:03:24 -08:00
Ben Alpert
361ce5c00b Add test for unmount/remount in a single batch (#8470)
Fails in Fiber.
2016-12-01 14:19:00 -08:00
Ben Alpert
981f461b70 Merge pull request #8463 from spicyj/travis
Update Travis config for new token
2016-11-30 21:03:01 -08:00
Ben Alpert
cb2927665c Fix insecure shell escaping in facts tracker 2016-11-30 21:02:44 -08:00
Andrew Clark
aa6279c41a Clear existing text content before inserting children (#8331)
Fixes a bug when updating from a single text child (or
dangerouslySetInnerHTML) to regular children, where the previous
text content never gets deleted.
2016-11-30 18:08:41 -08:00
Ben Alpert
06e8cedc0d Update Travis config for new token 2016-11-30 17:17:04 -08:00
Andrew Clark
e7eed5874f [Fiber] New error boundary semantics (#8304)
* Exit early in scheduleUpdate if a node's priority matches

This is a performance optimization and is unobservable. However, it
helps protect against regressions on the following invariants on which
it relies:

- The priority of a fiber is greater than or equal to the priority of
all its descendent fibers.
- If a tree has pending work priority, its root is scheduled.

* New error boundary semantics

- Recovering from an error boundary no longer uses Task priority by
default. The work is scheduled using whatever priority created the
error.
- Error handling is now a side-effect that happens during the
commit phase.
- The default behavior of an error boundary is to render null. Errors
do not propagate except when an boundary fails. Conceptually, this would
be like throwing an error from a catch block.
- A host container is treated like a no-op error boundary. The first
error captured by a host container is thrown at the end of the batch.
Like with normal error boundaries, the entire tree is unmounted.

* Fix broken setState callback test

* Add test for "unwinding" context when an error interrupts rendering

* Switch over primary effect types only

This avoids the need to create an export for every combination of bits.

* Only continue the work loop if the error was successfully captured

* Add more tests for incremental error handling

These tests are currently failing:

  ✕ catches render error in a boundary during partial deferred mounting
  ✕ catches render error in a boundary during animation mounting
  ✕ propagates an error from a noop error boundary during full deferred mounting
  ✕ propagates an error from a noop error boundary during partial deferred mounting
  ✕ propagates an error from a noop error boundary during animation mounting

The observed behavior is that unstable_handleError() unexpected gets called twice:

      "ErrorBoundary render success",
      "BrokenRender",
      "ErrorBoundary unstable_handleError",
  +   "ErrorBoundary render success",
  +   "BrokenRender",
  +   "ErrorBoundary unstable_handleError",
      "ErrorBoundary render error"

* Verify batched updates get scheduled despite errors

* Add try/catch/finally blocks around commit phase passes

We'll consolidate all these blocks in a future PR that refactors the
commit phase to be separate from the perform work loop.

* NoopBoundary -> RethrowBoundary

* Only throw uncaught error once there is no more work to perform

* Remove outdated comment

It was fixed in #8451.

* Record tests

* Always reset nextUnitOfWork on error

This is important so that the test at the end of performAndHandleErrors() knows it's safe to rethrow.

* Add a passing test for unmounting behavior on crashed tree

* Top-level errors

An error thrown from a host container should be "captured" by the host
container itself

* Remove outdated comment

* Separate Rethrow and Noop scenarios in boundary tests

* Move try block outside the commit loops
2016-11-30 16:54:20 -08:00
Ben Alpert
705c9bcfd2 Refs between fiber and stack (#8458)
I feel gross. Better ideas welcome.
2016-11-30 12:17:03 -08:00
Dan Abramov
b1c988d0de Add tests for recovery from errors thrown in the reconciler (#8462)
Test that errors in the reconciler can be caught by error boundaries, and that we can still schedule updates if they are uncaught.
2016-11-30 17:00:14 +00:00
Dan Abramov
623f608aab [Fiber] Make bad element type message same as in Stack (#8460)
* Make bad element type message same as in Stack

This makes Fiber emit the same message as Stack (aside from the missing owner information).

* Add a separate test verifying error includes owner name

Fiber currently doesn't pass it. This is just to keep track of it as a todo.
2016-11-30 16:29:42 +00:00
Ben Alpert
6110c58584 Fix reordering of bailed out children (#8457) 2016-11-29 14:57:04 -08:00
Ben Alpert
16bf429029 Fix fiber feature flag for ReactDOMProduction-test (#8451) 2016-11-28 23:36:05 -08:00
Ben Alpert
cbe59521af Add test for updating parent state in cWRP (#8448)
Fails in Fiber.
2016-11-28 19:05:24 -08:00
Ben Alpert
492057c76f Fix context getting (#8407) 2016-11-28 18:33:46 -08:00
Dan Abramov
c74034589e [Fiber] Support iterables (#8446)
* Add iterable cases to MultiChildReconcile test

Stack currently supports rendering iterables, but Fiber does not.

Previously we didn't have any public API tests for iterables. We have tests for traverseAllChildren() which is shared between React.Children and Stack. However Fiber doesn't currently use it, and likely won't. So this commit is a first step towards actually testing iterable support via public API. The next step will be to port traverseAllChildren() tests to test React.Children API instead.

* Implement iterable reconciliation in Fiber

This uses the same exact algorithm as array reconciliation but uses iterator to step through.

This gets reconcile tests to pass again but introduces a regression in ReactMultiChildText case which uses Maps as children. It passed before because Maps were ignored, but now it's failing because this actually runs the Map code path in Fiber. We can throw early in this case when we want to follow up on this.

* Rewrite traverseAllChildren() tests against React.Children API

This function was used in React.Children and Stack.

The corresponding reconciliation functionality is being tested by ReactMultiChild tests.

So we can move these tests to ReactChildren and test its public API.
2016-11-28 23:44:56 +00:00
Ben Alpert
f1f07c4a23 Use latest instance when restoring controlled state (#8443) 2016-11-28 14:00:50 -08:00
Ben Alpert
a1feccd9e8 Record tests (#8444) 2016-11-28 11:37:21 -08:00
Sebastian Markbage
e2b9882a79 Move tests out of the Stack folder
So that we can share them with Fiber.

Also Server Rendering tests.
2016-11-28 10:55:28 -08:00
Brandon Dail
6947db1529 Use a closure to bind argument to callback in ReactErrorUtils (#8363)
* Use a closure to bind gaurded callback

This way the fake event isn't being implicitly passed into the event handler

* Add tests for ReactErrorUtils

Add fiber test report

Linting fixes
2016-11-28 16:54:57 +00:00
Christopher Chedeau
e24ec4a1b4 test 2016-11-26 17:08:10 -08:00
Christopher Chedeau
00c3ee40c2 Do not forward stderr 2016-11-26 16:53:05 -08:00
Dan Abramov
e34b995f84 Fix portal unmounting (#8422)
We used to terminate the search on host nodes, and then use the nested unmount algorithm.
However this means we didn't unmount portals inside the host nodes.

We will probably need to restructure this somehow but for now I just added a recursive call to unblock myself.
2016-11-25 21:43:56 +00:00
Dan Abramov
a4dd68fb3d Add a test for nested portals (#8416) 2016-11-24 18:43:45 +00:00
Sebastian Markbåge
0ba8434a33 [Fiber] Remove output field (#8406)
* Remove output field

The idea was originally that each fiber has a return value. In practice
most of what we're modelling here are void functions and we track side
effects instead of return values.

We do use this for coroutines to short cut access to terminal yields.
However, since this can be nested fragments we end up searching the tree
anyway. We also have to manage this in transferOutput so it ends up being
as expensive. Maybe we can save some traversal for updates when coroutine
branches bail out but meh.

* Unmount child from the first phase of a coroutine
2016-11-24 10:03:14 -08:00
Sebastian Markbåge
7d2be2c9a7 Merge pull request #8400 from sebmarkbage/fibercontainerchildren
[Fiber] Update root children using appendChild/insertBefore/removeChild
2016-11-23 18:09:50 -08:00
Ben Alpert
8791325db0 Finish ReactGenericBatching (#8405) 2016-11-23 17:40:20 -08:00
Sebastian Markbage
78add2dc63 Update root children using the appendChild/insertBefore/removeChild methods
This removes updateContainer and instead uses the regular child mutation
methods to insert into the root container and portals.

Since we're no longer clearing out the container DOM in updateContainer
we have to do that manually during initial mount. This now works on a
document and one of the tests end up unmounting the body when you render
into the document so I had to work around that bit since we don't yet
properly support rendering into the document root.
2016-11-23 17:38:35 -08:00
Ben Alpert
af659a2544 Re-record 2016-11-23 15:22:35 -08:00
Ben Alpert
0c885af183 Restore DOM selection and suppress events (#8353)
This makes Draft mostly work.
2016-11-23 13:43:00 -08:00
Ben Alpert
7ac2044bce Fix queueing updates in cWM/cWRP when batching (#8398)
I tried to add a temporary check for the correct state in https://gist.github.com/spicyj/338147e989215b6eeaf48a6ce2d68d93 and run our test suites over it, but none of our existing test cases would have triggered that invariant. The new one I added does.
2016-11-23 13:00:49 -08:00
Sebastian Markbåge
7ef856aa36 Change the behavior to always fail childContextTypes if there is a method (#8391)
Even if that method returns falsy values.
2016-11-23 10:59:49 -08:00