498 Commits

Author SHA1 Message Date
Sebastian Markbage 6c22b6cad9 fix typo 2018-11-12 17:51:02 -08:00
Sebastian Markbåge b545546ccb Use unique thread ID for each partial render to access Context (#14182)
* BUG: ReactPartialRenderer / New Context polutes mutable global state

The new context API stores the provided values on the shared context instance. When used in a synchronous context, this is not an issue. However when used in an concurrent context this can cause a "push provider" from one react render to have an effect on an unrelated concurrent react render.

I've encountered this bug in production when using renderToNodeStream, which asks ReactPartialRenderer for bytes up to a high water mark before yielding. If two Node Streams are created and read from in parallel, the state of one can polute the other.

I wrote a failing test to illustrate the conditions under which this happens.

I'm also concerned that the experimental concurrent/async React rendering on the client could suffer from the same issue.

* Use unique thread ID for each partial render to access Context

This first adds an allocator that keeps track of a unique ThreadID index
for each currently executing partial renderer. IDs are not just growing
but are reused as streams are destroyed.

This ensures that IDs are kept nice and compact.

This lets us use an "array" for each Context object to store the current
values. The look up for these are fast because they're just looking up
an offset in a tightly packed "array".

I don't use an actual Array object to store the values. Instead, I rely
on that VMs (notably V8) treat storage of numeric index property access
as a separate "elements" allocation.

This lets us avoid an extra indirection.

However, we must ensure that these arrays are not holey to preserve this
feature.

To do that I store the _threadCount on each context (effectively it takes
the place of the .length property on an array).

This lets us first validate that the context has enough slots before we
access the slot. If not, we fill in the slots with the default value.
2018-11-12 17:50:46 -08:00
Heaven 1034e26fe5 Fix typos (#14124) 2018-11-09 10:17:49 -08:00
Alex Taylor 02e4848e3a Improved suspense support in ReactDOMServer (#14161) 2018-11-08 18:15:06 -08:00
Dominic Gannaway aa1ffe4e77 Show deprecated context object warnings usage in ReactDOM server (#14033)
* Applies context object warnings to ReactDOM server
2018-11-07 17:19:38 +00:00
Andrew Clark b50e63ef53 Updating package versions for release 16.6.1 2018-11-06 18:19:57 -08:00
locknono 2aecbcd6f1 "functional component" -> "function component" (#14123) 2018-11-06 17:33:26 -08:00
Nadav Kaner b4608dd24c Remove unused simulated flag parameter (#14127) 2018-11-06 17:33:01 -08:00
Dan Abramov 3c69a18814 Recover from errors with a boundary in completion phase (#14104)
* Recover from errors with a boundary in completion phase

* Use a separate field for completing unit of work

* Use a simpler fix with one boolean

* Reoder conditions

* Clarify which paths are DEV-only

* Move duplicated line out

* Make it clearer this code is DEV-only
2018-11-06 23:38:12 +00:00
Sophie Alpert e4512991c9 Fix unhiding in IE11 (#14126)
Setting to null isn't correct; setting to '' is. I opted to use dangerousStyleValue for consistency with the main path that we set things.

Fixes #14114.

Test Plan:
Verified setting to '' works in Chrome and IE11. (Setting to null works in Chrome but not in IE11.)
2018-11-06 11:24:44 -08:00
Dan Abramov 600651e68e Restore the Hooks dispatcher after using SSR (#14105) 2018-11-06 01:15:11 +00:00
Andrew Clark e9a2ec9156 [suspense] Avoid double commit by re-rendering immediately and reusing primary children (#14083)
* Avoid double commit by re-rendering immediately and reusing children

To support Suspense outside of concurrent mode, any component that
starts rendering must commit synchronously without being interrupted.
This means normal path, where we unwind the stack and try again from the
nearest Suspense boundary, won't work.

We used to have a special case where we commit the suspended tree in an
incomplete state. Then, in a subsequent commit, we re-render using the
fallback.

The first part — committing an incomplete tree — hasn't changed with
this PR. But I've changed the second part — now we render the fallback
children immediately, within the same commit.

* Add a failing test for remounting fallback in sync mode

* Add failing test for stuck Suspense fallback

* Toggle visibility of Suspense children in mutation phase, not layout

If parent reads visibility of children in a lifecycle, they should have
already updated.
2018-11-05 16:32:50 -08:00
Sophie Alpert ebdb47d2c1 DCE hooks code when flag is off (#14111) 2018-11-05 13:04:57 -08:00
Tiago Nunes b305c4e034 fix(react-dom): Fix crash during server render (#14103)
Check for existence of `setTimeout` and `clearTimeout` in the runtime
before using them, to ensure runtimes without them (like .NET ClearScript)
do not crash just by importing `react-dom`.
2018-11-05 17:08:07 +00:00
einarq 6c404d82aa Bugfix: Add back early return in setOffsets which was removed between 16.4.2 and 16.5.0. Fails in Edge in some scenarios. (#14095) 2018-11-05 15:19:50 +00:00
Simen Bekkhus 8eca0eff87 chore(tests): don't rely on jest fake timers scheduling real timers (#14003)
* chore: don't rely on jest fake timers scheduling real timers

* re-add one part not working with Jest 23
2018-11-02 16:54:23 -05:00
Mateusz Burzyński ae196e84b6 Rename inputsAreEqual to areHookInputsEqual & move it to shared (#14036) 2018-11-02 12:50:23 -07:00
Sophie Alpert 169f935f78 Flip expiration times (#13912)
See https://github.com/facebook/react/pull/13912 commit messages for how this was done.
2018-10-30 15:26:20 -07:00
Andrew Clark bf9fadfcf4 [Hooks] Remove dispatch callbacks (#14037)
Removes the `enableDispatchCallback` feature flag and deletes the
associated code. An earlier version of the Hooks proposal included this
feature but we've since decided to remove it.
2018-10-30 14:14:20 -07:00
Andrew Clark 8c67bbf183 [scheduler] Deadline object -> shouldYield (#14025)
* [scheduler] Deadline object -> shouldYield

Instead of using a requestIdleCallback-style deadline object, expose a
method Scheduler.shouldYield that returns true if there's a higher
priority event in the queue.

* Nits
2018-10-30 13:47:51 -07:00
Sophie Alpert 6efbbe0685 Prettier 2018-10-29 12:29:41 -07:00
Andrew Clark 5045763064 Swap order of function member in hook union types 2018-10-29 11:42:41 -07:00
Sophie Alpert 5fc84efacc Skip updating effect tag when skipping effect
For example, if you have `useEffect(..., [])`, there's no need to set .effectTag to `Update | Passive` on updates.
2018-10-29 11:26:54 -07:00
Alex Taylor 9f34eb79a3 Add readContext to ReactPartialRendererHooks 2018-10-29 11:26:54 -07:00
Sebastian Markbåge b772e0e26b "functional component" -> "function component" in hooks error messages 2018-10-29 11:26:53 -07:00
Sophie Alpert 9e9e3970e4 Warn for Hook set-state on unmounted component 2018-10-29 11:26:53 -07:00
Alex Taylor dd019d34db Add support for hooks to ReactDOMServer
Co-authored-by: Alex Taylor <alexmckenley@gmail.com>
Co-authored-by: Andrew Clark <acdlite@fb.com>
2018-10-29 11:26:53 -07:00
Rauno Freiberg 37c7fe0a5f Update createRoot warning message based on enableStableConcurrentModeAPIs (#14017) 2018-10-29 11:25:24 -07:00
Joseph 95f98a1873 fix typo (#13955) 2018-10-27 09:59:00 -07:00
Patrick e217f2f1ac Updated comment for getEventModifierState (#13918) 2018-10-27 09:52:01 -07:00
Brian Vaughn 275e76e83b Enable stable concurrent APIs flag for 16.7 alpha (#13928)
* Add enableStableConcurrentModeAPIs feature flag

* Conditionally name concurrent API based on enableStableConcurrentModeAPIs flag
2018-10-24 13:45:07 -07:00
Dan Abramov 6c29eabf78 Updating package versions for release 16.6.0 2018-10-23 16:23:41 -07:00
Dan Abramov d520b358d6 Revert all package versions to 16.5.2 state
Our release script is getting really confused so I'm resetting to last working state.
2018-10-23 16:18:28 -07:00
Dan Abramov 8f1ec7649e Bump versions to beta.0 2018-10-23 16:01:57 -07:00
Andrew Clark d8e03de4aa [react-cache] Remove cache as argument to read (#13865)
* [react-cache] Remove `cache` as argument to `read`

Updated is API is `Resource.read(key)` instead of
`Resource.read(cache, key)`.

The cache is read from context using `readContext`.

This also removes cache invalidation entirely (other than the default
LRU mechanism), as well as the ability to have multiple caches. We'll
add it back once `Context.write` lands and we can implement it the
right way.

Since there's now only a single cache (the global one), we don't
actually need to use context yet, but I've added a dummy context
anyway so the user gets an error if they attempt to read outside the
render phase.

* nits

* Add test for thenables that resolve multiple times
2018-10-23 14:38:51 -07:00
Brian Vaughn 915e4eab53 Add "unstable_" prefix to react-cache and jest-react (#13929)
* Add "unstable_" prefix to react-cache createResource and jest-react matchers
* Reverted accidental change to error-codes JSON
* Remove unstable_ prefix from internal React tests for jest-test
2018-10-23 13:55:37 -07:00
Sebastian Markbåge 4947fcd762 Fix lint (#13923) 2018-10-22 22:47:39 -07:00
Sebastian Markbåge d75c69e0cf Remove unstable_ prefix from Suspense (#13922)
We are using it with lazy and the combination Suspense + lazy seems pretty
stable. maxDuration is not but that's only enabled when you're in
ConcurrentMode which is still unstable.
2018-10-22 22:40:05 -07:00
John Lin c8ef2feda9 Remove redundant word "the" (#13919) 2018-10-22 22:39:23 -07:00
Abdul Rauf 663835a43a Add flow types in getEventModifierState (#13909) 2018-10-21 13:20:50 -05:00
Abdul Rauf 82710097f6 Add flow types in getNodeForCharacterOffset (#13908) 2018-10-21 13:18:32 -05:00
Andrew Clark b753f76a74 Fix failing async tests in Node 10
Dunno why they happened to work in Node 8 but whatever. Tested on both.
2018-10-20 16:06:23 -07:00
Dan Abramov b5c0852fdd Bump version to 16.6.0-beta.0 (#13906)
* Bump version to 16.6.0-beta.0

* Root too
2018-10-20 13:03:15 -04:00
Dan Abramov 769b1f270e pure -> memo (#13905) 2018-10-20 12:46:23 -04:00
Alex Taylor 8ecd4bd4f0 Add support for React.pure in ReactDOMServer (#13855)
* Add support for React.pure in ReactDOMServer

* Unwrap pure wrappers by creating an additional element as a single child

This is very slow but meh. We're rewriting this whole thing anyway.
2018-10-20 00:42:33 -07:00
Sebastian Markbåge 95a313ec0b Unfork Lazy Component Branches (#13902)
* Introduce elementType field

This will be used to store the wrapped type of an element. E.g. pure and
lazy.

The existing type field will be used for the unwrapped type within them.

* Store the unwrapped type on the type field of lazy components

* Use the raw tags for lazy components

Instead, we check if the elementType and type are equal to test if
we need to resolve props. This is slightly slower in the normal case
but will yield less code and branching.

* Clean up lazy branches

* Collapse work tag numbering

* Split IndeterminateComponent out from Lazy

This way we don't have to check the type in a hacky way in the
indeterminate path. Also, lets us deal with lazy that resolves to
indeterminate and such.

* Missing clean up in rebase
2018-10-19 22:22:45 -07:00
Sebastian Markbåge 6938dcaacb SSR support for class contextType (#13889) 2018-10-19 11:18:32 -07:00
Sebastian Markbåge fa65c58e15 Add readContext to SSR (#13888)
Will be used by react-cache.
2018-10-18 20:20:03 -07:00
Andrew Clark d9a3cc070c React.lazy constructor must return result of a dynamic import (#13886)
We may want to change the protocol later, so until then we'll be
restrictive. Heuristic is to check for existence of `default`.
2018-10-18 19:58:25 -07:00
Andrew Clark d9659e499e Lazy components must use React.lazy (#13885)
Removes support for using arbitrary promises as the type of a React
element. Instead, promises must be wrapped in React.lazy. This gives us
flexibility later if we need to change the protocol.

The reason is that promises do not provide a way to call their
constructor multiple times. For example:

const promiseForA = new Promise(resolve => {
  fetchA(a => resolve(a));
});

Given a reference to `promiseForA`, there's no way to call `fetchA`
again. Calling `then` on the promise doesn't run the constructor again;
it only attaches another listener.

In the future we will likely introduce an API like `React.eager` that
is similar to `lazy` but eagerly calls the constructor. That gives us
the ability to call the constructor multiple times. E.g. to increase
the priority, or to retry if the first operation failed.
2018-10-18 19:57:12 -07:00