Commit Graph

7856 Commits

Author SHA1 Message Date
Brian Vaughn
8fbcd499bd Add callback validation to fiber-based renderers
Moved ReactFiberClassComponent validateCallback() helper function into a standalone util used by both fiber and stack implementations. Validation now happens in ReactFiberUpdateQueue so that non-DOM renderers will also benefit from it.
2017-01-03 12:10:06 -08:00
Brian Vaughn
0402106058 Merge pull request #8671 from bonham000/update-docs
update to codebase-overview.md
2017-01-03 09:01:53 -08:00
Brian Vaughn
323125b252 Merge pull request #8673 from madeinfree/patch-1
fiber example typo
2017-01-03 08:58:41 -08:00
Brian Vaughn
962974cef0 Merge pull request #8674 from neeldeep/patch-1
Update conferences.md
2017-01-03 08:56:30 -08:00
neeldeep
2825519505 Update conferences.md 2017-01-03 19:23:55 +05:30
Whien
3b005a7e75 fiber example typo 2017-01-03 13:52:48 +08:00
Sean Smith
2447894008 update to codebase-overview.md 2017-01-01 15:27:57 -08:00
Andrew Clark
7dc5f91d88 Merge pull request #8641 from jddxf/remove-superfluous-check
remove superfluous check in while loop
2016-12-29 13:25:22 -08:00
Andrew Clark
9b015184b7 Merge pull request #8634 from acdlite/fibersyncmount
[Fiber] Sync mount and unmount
2016-12-29 13:11:57 -08:00
Andrew Clark
79f01b2425 prepareForCommit returns info object to be passed resetAfterCommit
The DOM renderer assumes that resetAfterCommit is called after
prepareForCommit without any nested commits in between. That may not
be the case now that syncUpdates forces a nested update.

To address, this changes the type of prepareForCommit to return a value
which is later passed to resetAfterCommit.
2016-12-29 10:39:24 -08:00
Andrew Clark
ce8c978d63 Disallow forced sync updates during begin phase
Stack allows this, but in Fiber it may cause an infinite loop. Instead
we'll print a warning and defer the update by giving it Task priority.
2016-12-29 10:39:18 -08:00
Andrew Clark
21f6d4145f syncUpdates prevents Synchronous priority from being downgraded to Task
Typically, a sync update is downgraded to Task priority if it's
scheduled within another batch of work, e.g. within a lifecycle like
componentDidMount. But syncUpdates should force sync updates to not
be downgraded to Task. This will cause performWork to be
called recursively.
2016-12-29 10:23:33 -08:00
Andrew Clark
8090cf59e3 Allow performWork to be called recursively
Currently we assume that performWork is never called recursively.
Ideally that is the case. We shouldn't rely on recursion anywhere
in Fiber.

However, to support the use of syncUpdates as an opt-in to forced-
synchronous updates, we need the ability to call performWork
recursively.

At the beginning of performWork, the state of the scheduler is saved;
before exiting, that state is restored, so that the scheduler can
continue where it left off. I've decided to use local variables to stash
the previous state. We could also store them in a record and push it to
a stack, but this approach has the advantage of being isolated to
performWork.
2016-12-29 10:23:33 -08:00
Andrew Clark
3926a3566f If an error is thrown and there's no nextUnitOfWork, it's fatal error
This can only be caused by a bug in the renderer, but we should handle
it gracefully anyway.

Added a TODO to change capturedErrors and failedBoundaries so that they
are sets of instances (stateNodes) rather than fibers, to avoid having
to check the alternate. (This outside the scope of this PR.)
2016-12-29 10:23:26 -08:00
Andrew Clark
ffbb86b361 Wrap top-level mount and unmount in syncUpdates
For legacy purposes. Only enabled in the DOM renderer. We can remove
this in a future release when we enable incremental-by-default.

This change is unobservable because syncUpdates actually schedules
Task updates when it is called from inside another batch. The correct
behavior is to recursively begin another batch of work. We will fix it
in a subsequent commit.
2016-12-28 20:41:40 -08:00
Brian Vaughn
df6ca0e2c1 Merge pull request #8646 from bvaughn/focus-side-effect
Renderers can queue commit effects for initial mount
2016-12-28 15:16:50 -05:00
Brian Vaughn
a10131304b Renderers can schedule commit-time effects for initial mount
The finalizeInitialChildren HostConfig method now utilizes a boolean return type. Renderers can return true to indicate that custom effects should be processed at commit-time once host components have been mounted. This type of work is marked using the existing Update flag.

A new HostConfig method, commitMount, has been added as well for performing this type of work.

This change set is in support of the autoFocus prop.
2016-12-28 15:03:08 -05:00
gitanupam
9e461c715c Changed webpack's hyperlink (#8650)
..to point to 2.x documentation instead of 1.x (and to be consistent with other links on the page)
2016-12-28 11:34:00 -06:00
gitanupam
86765baaef 'npm init' needed before installing react via npm. (#8649)
* 'npm init' needed before installing react via npm.

I was trying to install react in my django project directory and was getting warnings about package.json not being present. Started this SO post (http://stackoverflow.com/questions/41340909/npm-cant-find-package-json-when-installing-react/41340975#41340975) to figure it out. I think it'll be useful to others too if we add it in the documentation itself.

* Tweak instructions
2016-12-28 04:04:21 -08:00
Dan Abramov
6b73073557 Include owner in invalid element type invariant (#8637) 2016-12-27 08:41:23 -08:00
Dan Abramov
38ed61f4c4 Relax test about rendering top-level null (#8640) 2016-12-27 08:38:24 -08:00
Dan Abramov
119294dcae Validate that update callback is a function (#8639) 2016-12-27 08:38:10 -08:00
jddxf
b359be74a1 remove superfluous check in while loop 2016-12-25 09:41:47 +08:00
Eric Pitcher
3baa47ca7b Update conditional-rendering.md (#8636)
Stating the fact that component lifecycle methods will still fire as normal even though you return null from the render method.
2016-12-24 09:18:30 -08:00
Sebastian Markbåge
5d153c9dbe Don't call sCU with null props (#8633)
I missed this case in 8613 and it broke the triangle demo.
2016-12-22 15:47:10 -08:00
Ben Alpert
6e47f43e89 Fix typo 2016-12-22 12:44:28 -08:00
Ben Alpert
13980e6536 Fiber: Fix reentrant mounting in synchronous mode (#8623) 2016-12-22 11:34:35 -08:00
Dan Abramov
c978f789cc [Fiber] Push class context providers even if they crash (#8627)
* Push class context providers early

Previously we used to push them only after the instance was available. This caused issues in cases an error is thrown during componentWillMount().

In that case we never got to pushing the provider in the begin phase, but in complete phase the provider check returned true since the instance existed by that point. As a result we got mismatching context pops.

We solve the issue by making the context check independent of whether the instance actually exists. Instead we're checking the type itself.

This lets us push class context early. However there's another problem: we might not know the context value. If the instance is not yet created, we can't call getChildContext on it.

To fix this, we are introducing a way to replace current value on the stack, and a way to read the previous value. This also helps remove some branching and split the memoized from invalidated code paths.

* Add a now-passing test from #8604

Also rename another test to have a shorter name.

* Move isContextProvider() checks into push() and pop()

All uses of push() and pop() are guarded by it anyway.

This makes it more similar to how we use host context.

There is only one other place where isContextProvider() is used and that's legacy code needed for renderSubtree().

* Clarify why we read the previous context

* Use invariant instead of throwing an error

* Fix off-by-one in ReactFiberStack

* Manually keep track of the last parent context

The previous algorithm was flawed and worked by accident, as shown by the failing tests after an off-by-one was fixed.

The implementation of getPrevious() was incorrect because the context stack currently has no notion of a previous value per cursor.

Instead, we are caching the previous value directly in the ReactFiberContext in a local variable.

Additionally, we are using push() and pop() instead of adding a new replace() method.
2016-12-22 10:36:42 -08:00
Dan Abramov
c79af45f1e Update to Jest 18 (#8621) 2016-12-21 19:28:27 -08:00
Ben Alpert
efaa26eb50 Upgrade jest APIs to match www (#8536)
D4298654, D4298713
2016-12-21 19:07:40 -08:00
Brian Vaughn
f1e193b32e Merge pull request #8611 from bvaughn/shared-context-stack
Added ReactFiberStack shared by ReactFiberContext and ReactFiberHostContext
2016-12-21 18:50:34 -08:00
Brian Vaughn
d1e604004a Removed redundant calls to ReactFiberStack.reset() 2016-12-21 17:39:39 -08:00
Brian Vaughn
2f2a44007c Improved Flowtypes in response to code review feedback 2016-12-21 17:32:53 -08:00
Brian Vaughn
cb66f5c440 Merge pull request #8622 from bvaughn/preproccessor-jest-cching
Jest preprocessor better aware of error-codes/codes.json WRT caching
2016-12-21 17:12:17 -08:00
Brian Vaughn
b209804cfb Jest preprocessor better aware of error-codes/codes.json WRT caching 2016-12-21 16:58:33 -08:00
Brian Vaughn
ea6530d13a Removed exact object type for StackCursor Flow type
This was causing the 'react:extract-errors' Gulp taks to fail.
2016-12-21 16:48:14 -08:00
Brian Vaughn
e7a591ed57 ReactFiberStack cursor values are no longer corrupted on pop 2016-12-21 15:11:49 -08:00
Brian Vaughn
1148e827b9 Avoid reading the same StackCursor current multiple times 2016-12-21 15:11:49 -08:00
Brian Vaughn
6b51e037ca Avoid popping hosts that do not provide unique contexts 2016-12-21 15:11:49 -08:00
Brian Vaughn
0b7c5ff1a0 Tightened up Fiber | null type in ReactFiberStack to always require Fiber 2016-12-21 15:11:49 -08:00
Brian Vaughn
0c1fdfd41d Combined unwindContext and unwindHostContext into unwindContexts 2016-12-21 15:11:49 -08:00
Brian Vaughn
a0902fc306 Generic type added to StackCursor. Default emptyObject replaced with null. 2016-12-21 15:11:49 -08:00
Brian Vaughn
3d0cf47d26 Added ReactFiberStack shared by ReactFiberContext and ReactFiberHostContext
ReactFiberStack is the new underlying stack used by ReactFiberContext and ReactFiberHostContext. The goal is to simplify the 2 context managers and to add more errors/dev-warnings when we pop unexpected.
This changeset currently causes a lot of tests to fail (as we are currently popping too many times and/or in the wrong order). I'm pushing this branch now to share with Sebastian as he is working on a related cleanup pass at beginWork.
2016-12-21 15:11:49 -08:00
Dan Abramov
a27e4f3361 [Fiber] Make requestIdleCallback() and requestAnimationFrame() shims async (#8591)
* Add a failing test for recursion check

* Make requestIdleCallback() and requestAnimationFrame() shims async

They no longer need to be sync in tests because we already made DOM renderer sync by default.
This fixes a crash when testing incrementalness in DOM renderer itself.

* Style fix

* Fix lint
2016-12-21 14:04:05 -08:00
Ben Alpert
2a5fe4c2b0 Call refs and lifecycles on indeterminate components (#8614)
This was a bug because of the split between ClassComponent and IndeterminateComponent -- we didn't mark effects or push context when we come from an indeterminate component. Now they behave the same way.

The code is even clumsier than before but I'm pretty worried we'll screw these up in the future if we don't unify the paths.

Not many components exercise this path but Relay containers do so it's noticeable.
2016-12-21 13:51:59 -08:00
Sebastian Markbåge
4a05c242e8 Merge pull request #8613 from sebmarkbage/fiberrefactorbailout
[Fiber] Refactor bailoutOnFinishedWork
2016-12-21 13:22:20 -08:00
Ben Alpert
eca5b1d48e Improve error messages for invalid element types (#8612) 2016-12-21 13:17:34 -08:00
Sebastian Markbage
26c82cea72 Move other branches out of the bail out
This is the same thing as the previous commit but with class, root and portal.

I noticed host and portal now already covers this case in their branches
since pushHostContainer is always at the top.
2016-12-21 11:34:18 -08:00
Sebastian Markbage
9a210114e4 Move isHostComponent branches out of bailout
Since we only call bailout from within the host component branch now, we
can just move this to the branch where we already know that this is a
host component.

As part of this I noticed that we don't always push the host context so
I moved that to the beginning of the branch.
2016-12-21 11:34:18 -08:00
Sebastian Markbage
b7548b2030 Delete hasPendingUpdate
This is no longer needed. It is effectively covered by other branches
that tries to being merging the update queue which yields the same state
object as before if there is no work. That in turn bails out.

We can shortcut in the relevant paths if needed.
2016-12-21 11:34:18 -08:00