Commit Graph

11160 Commits

Author SHA1 Message Date
Nicolas Gallagher
47656bf2a1 [Flare] Remove longpress from press responder (#16242)
Long press will move to a separate responder.
2019-07-29 13:12:12 -07:00
Dan Abramov
9914a19190 [Fresh] Transfer refs when remounting (#16241)
* Add a failing test for refs and remounting

* Transfer ref when remounting
2019-07-29 17:19:09 +01:00
Andrew Clark
75ab53b9e1 [scheduler] Yield many times per frame, no rAF (#16214)
Adds experimental flag to yield many times per frame using a message
event loop, instead of the current approach of guessing the next vsync
and yielding at the end of the frame.

This new approach forgoes a `requestAnimationFrame` entirely. It posts a
message event and performs a small amount of work (5ms) before yielding
to the browser, regardless of where it might be in the vsync cycle. At
the end of the event, if there's work left over, it posts another
message event.

This should keep the main thread responsive even for really high frame
rates. It also shouldn't matter if the hardware frame rate changes after
page load (our current heuristic only detects if the frame rate
increases, not decreases).

The main risk is that yielding more often will exacerbate main thread
contention with other browser tasks.

Let's try it and see.
2019-07-26 15:43:57 -07:00
Dominic Gannaway
0d7141dd49 [Flare] Fix SSR issue with serializing responders prop (#16227) 2019-07-26 22:47:37 +01:00
Andrew Clark
ed57bf8ed4 [Bugfix] Check tag before calling hook effects (#16215)
* Add failing test for #16215

Next commit fixes it.

* [Bugfix] Check tag before calling hook effects

TODO: Test that triggers this
2019-07-26 14:28:49 -07:00
Belmin Bedak
858c84206e Don't hyphenate custom CSS properties for ReactDOMServer (#16167)
* Do not hyphenate custom CSS property

* Move check into the processStyleName fn

* Formatting

* add test

* Put isCustomProperty check after conditional return

* add test to `ReactDOMServerIntegration` and supress warning

* Don't indexOf twice

* Simpler fix
2019-07-26 18:06:24 +01:00
Sunil Pai
d412eec839 [act] flush work correctly without a mocked scheduler (#16223)
Not returning the value of flushPassiveEffects() in flushWork() meant that with async act, we wouldn't flush all work with cascading effects. This PR fixes that oversight, and adds some tests to catch this in the future.
2019-07-26 17:48:42 +01:00
Sophie Alpert
b43785e151 Update use-subscription README (#16216)
It was a little confusing that the question asked when NOT to use this package, then the answer says when to use it. I think this is a little better.
2019-07-25 19:30:55 -07:00
Andrew Clark
c0830a0e63 [Scheduler] Test browser implementation details (#16198)
The Scheduler implementation uses browser APIs like `MessageChannel`,
`requestAnimationFrame`, and `setTimeout` to schedule work on the main
thread. Most of our tests treat these as implementation details;
however, the sequence and timing of these APIs are not precisely
specified, and can vary wildly across browsers.

To prevent regressions, we need the ability to simulate specific edge
cases that we may encounter in various browsers.

This adds a new test suite that mocks all browser methods used in our
implementation. It assumes as little as possible about the order and
timing of events. The only thing it assumes is that
requestAnimationFrame is passed a frame time that is equal to or less
than the time returned by performance.now. Everything else can be
controlled at will.

It also includes Scheduler-specific invariants, e.g. only one rAF
callback can be scheduled at a time.

It overlaps slightly with the existing SchedulerDOM-test suite, which
also mocks the browser APIs, but exposes a higher-level set of testing
primitives. I will consolidate the two suites in a follow-up.
2019-07-25 15:53:14 -07:00
lunaruan
857deb2ed5 Warn when Using DefaultProps on Function Components (#16210)
As part of the process to deprecate defaultProps on function components (as per a larger proposal outlined in (https://github.com/reactjs/rfcs/blob/createlement-rfc/text/0000-create-element-changes.md)), add a warning whenever someone does this.
2019-07-25 15:44:03 -07:00
Dominic Gannaway
e0472709c8 [Flare] Adds Keyboard event responder (#16204) 2019-07-25 17:47:44 +01:00
Dominic Gannaway
5b08f7b43f [Flare] Adds useListener implementation to ReactDebugHooks (#16205) 2019-07-25 16:55:39 +01:00
Dominic Gannaway
ed72f40257 [Flare] Remove references to EventComponent (#16206) 2019-07-25 16:41:26 +01:00
Sunil Pai
121bfb03bc update legacy context warning message (#16196)
The link in the legacy context message doesn't point to anything context related. This changes the link to point to https://fb.me/react-legacy-context, which points to https://reactjs.org/docs/context.html#legacy-api. Also adds a line that it'll probably be gone later.
2019-07-25 00:34:48 +01:00
Brian Vaughn
9ae5e38f18 Add guard to ensure Profiler onRender prop is function before calling (#16197) 2019-07-24 14:20:56 -07:00
Benoit Girard
144dba1a11 Fix suspenseCallback type warning, add a test (#16194) 2019-07-24 18:32:00 +01:00
Dominic Gannaway
7ad221126f [Flare] Ensure Flare components are no-ops for TestRenderer (#16192) 2019-07-24 11:31:33 +01:00
lunaruan
06cc996994 Edit Suspense Priority Warning Message (#16186)
* move 'component that triggered the update' in suspense priority warning message to the beginning of the message

* renamed warnings
2019-07-23 19:08:41 -07:00
Benoit Girard
42b75ab007 Add suspenseCallback feature for runtime tracing of loading states (#16134)
This adds a 'SuspenseCallback' feature flag. When the property is set on
a suspense component it will be called during the commit phase with a
set of the immediate thenable for this component. This will allow user
code to build runtime tracing of the cause for a suspense boundary.
2019-07-23 17:13:46 -07:00
Sunil Pai
c73e1f236f flush work on exiting outermost act(), with nested act()s from different renderers (#16181)
Given this snippet:
```jsx
    TestRenderer.act(() => {
      TestUtils.act(() => {
        TestRenderer.create(<Effecty />);
      });
    });
```
We want to make sure that all work is only flushed on exiting the outermost act().

Now, naively doing this based on actingScopeDepth would work with a mocked scheduler, where flushAll() would flush all work across renderers.

This doesn't work without mocking the scheduler though; and where flushing work only works per renderer. So we disable this behaviour for a non-mocked scenario. This seems like an ok tradeoff.
2019-07-24 00:20:28 +01:00
Dominic Gannaway
5098891193 [Flare] Redesign core event system (#16163) 2019-07-23 23:46:44 +01:00
Andrew Clark
19354db511 [Scheduler] Add names to inline functions (#16180)
Noticed when looking at the performance profiler with Luna that it's
hard to tell which event causes `performWorkUntilDeadline` to fire
because these functions are anonymous.
2019-07-23 11:08:24 -07:00
Andrew Clark
bff7abf6ba [Scheduler][Bugfix] Multiple rAFs in same frame (#16184)
Always sets `isRAFLoopRunning` back to false when an animation frame is
scheduled. Fixes a bug where two rAFs fire in the same frame, but the
second one exits and fails to schedule a new rAF.

Fixes bug observed in Safari.
2019-07-23 10:44:27 -07:00
Brian Vaughn
afb5991686 Enable profiler+tracing for test renderer (#16178)
This commit just brings the feature flags to parity with other renderers.
2019-07-23 08:20:12 -07:00
Dan Abramov
2237efcef9 [Fresh] Track unrecoverable errors (#16183)
* [Fresh] Track unrecoverable errors

* Only initial errors set the flag
2019-07-23 16:11:13 +01:00
Nicolas Gallagher
bbd21066e6 [Flare] Press: fix keyboard interactions (#16179)
Prevents Spacebar from scrolling the window.
Prevents Enter from triggering a navigation if preventDefault is true.
Fixes the emulated mouse events test.
2019-07-22 18:16:40 -07:00
lunaruan
03944bfb0b Update Suspense Priority Warning to Include Component that Triggered Update (#16030)
Improved warning whenever lower priority events (ex. data fetching, page load) happen during a high priority update (ex. hover/click events) to include:
1.) Name of component that triggered the high priority update or
2.) Information that the update was triggered on the root
2019-07-22 14:17:43 -07:00
Andrew Clark
3f2cafe8be [WIP][Scheduler] Use rIC to post first callback (#16166)
Scheduler uses `requestAnimationFrame` to post tasks to the browser.
If this happens at the beginning of a frame, the callback might not
fire until the subsequent frame, even if the main thread is idle.

Our theory was that this wouldn't be an issue in practice, because once
the first rAF fires, we schedule the next rAF as early as possible in
that frame. Combined with our heuristic for computing frame deadlines,
we shouldn't get any idle time in between frames — only before the
*first* frame.

This reasoning holds true when you have a small number of large tasks,
such as the ones posted by React. The idle time before the task starts
is negligible relative to the lifetime of the entire task.

However, it does not hold if you have many small tasks posted over a
span of time, perhaps spawned by a flurry of IO events. In this case,
instead of single, contiguous rAF loop preceded by an idle frame, you
get many rAF loops preceded by many idle frames. Our new theory is that
this is contributing to poor main thread utilization during page loads.

To try to reclaim as much idle time as possible, this PR adds two
experimental flags. The first one adds a `requestIdleCallback` call to
start the rAF loop, which will fire before rAF if there's idle time left
in the frame. (We still call rAF in case there isn't. We start working
in whichever event fires first.)

The second flag tries a similar strategy using `setTimeout(fn, 0)`. If
the timer fires before rAF, we'll assume that the main thread is idle.

If either `requestIdleCallback` or `setTimeout` fires before rAF, we'll
immediately peform some work. Since we don't have a real frame time that
we can use to compute the frame deadline, we'll do an entire frame
length of work. This will probably push us past the vsync, but this is
fine because we can catch up during the next frame, by which point a
real rAF will have fired and the loop can proceed the same way it
does today.

Test plan: Try this on Facebook to see if it improves load times
2019-07-22 13:12:33 -07:00
Andrew Clark
2bd88e38aa [Scheduler] Bugfix: Cancelling a continuation (#16151)
Cancelling the original task should also cancel its continuation.
2019-07-22 13:10:33 -07:00
Dominic Gannaway
783b8f4ae1 [Flare] Ensure mouse events can use target to validate press (#16172) 2019-07-22 12:31:19 +01:00
Dominic Gannaway
2c4d61e102 Adds experimental fundamental interface (#16049) 2019-07-19 22:20:28 +01:00
Paul Shen
b4178af81b clean up nextEffect pointers (#16115) 2019-07-17 17:21:19 -07:00
Nicolas Gallagher
997154bcc7 [Flare] Add FocusWithin responder (#16152)
FocusWithin is implemented as a separate responder, which keeps both focus
responders simple and allows for easier composition of behaviours.
2019-07-17 15:17:13 -07:00
Dominic Gannaway
65b80fdd94 [Flare] Add Input event responder surface (#16148) 2019-07-17 21:04:41 +01:00
Brian Vaughn
ce883a19d8 useSubscription hook (#15022)
* Added use-subscription package with README
2019-07-16 15:59:37 -07:00
Moti Zilberman
c45c2c3a26 Move ReactFiberErrorDialog RN fork into RN itself (#16141) 2019-07-16 09:38:14 +01:00
Sunil Pai
d9b4c55d53 unify deprecated/unsafe lifecycle warnings, pass tests (#16103)
- redoes #15431 from scratch, taking on the feedback there
- unifies the messaging between "deprecated" and UNSAFE_ lifecycle messages. It reorganizes ReactStrictModeWarnings.js to capture and flush all the lifecycle warnings in one procedure each.
- matches the warning from ReactPartialRenderer to match the above change
- passes all the tests
- this also turns on `warnAboutDeprecatedLifecycles` for the test renderer. I think we missed doing so it previously. In a future PR, I'll remove the feature flag altogether.
- this DOES NOT do the same treatment for context warnings, I'll do that in another PR too
2019-07-15 20:56:44 +01:00
Brian Vaughn
424099da60 Inject getCurrentFiber() function to DevTools (#16133)
This returns the current value of ReactCurrentFiber and enables DevTools to append a custom (owner-only) component stack to warnings and errors in DEV mode.
2019-07-15 07:38:44 -07:00
Brian Vaughn
9f395904c6 Inject ReactDebugCurrentFrame into DevTools so it can append component stacks to warnings in DEV mode (#16127) 2019-07-13 08:53:21 -07:00
Sebastian Markbåge
fcff9c57bc Add tail="hidden" option to SuspenseList (#16024)
* Move misaligned comment

* Add tail="hidden" option

* isShowingAnyFallbacks -> findFirstSuspended

* We can't reset Placement tags or we'll forget to insert them

* Delete hasSuspendedChildrenAndNewContent optimization
2019-07-12 15:55:47 -07:00
Brian Vaughn
8d413bf2c3 Remove React.error and React.warn (#16126)
* Remove React.error/React.warn with React.getComponentStack
2019-07-12 15:41:47 -07:00
Andrew Clark
29b4559635 .watchmanconfig must be valid json (#16118)
faceworldproblems?
2019-07-11 19:01:02 -07:00
Nicolas Gallagher
ca4d78f9b6 [Flare] Press: fix middle-click handling (#16114)
Make sure the root events are removed after middle-click completes
2019-07-11 22:12:10 +01:00
Sunil Pai
3f1dee09a4 expose act() sigil correctly for umd builds (#16110)
after https://github.com/facebook/react/pull/16039, act was broken for umd builds. This PR fixes it.
2019-07-11 14:56:03 +01:00
Sebastian Markbåge
b7669044d9 Use Map instead of object as map in ReactNativeComponentTree (#16107)
Real Maps should now be used in RN JS engines. In theory this should
be faster (but might not actually be in practice), and it avoids hitting
upper bounds of property max counts.

We don't use these types of Maps in Fabric.
2019-07-10 19:11:36 -07:00
Andrew Clark
d2d9b1f701 [Scheduler] Support inferring priority from stack (#16105)
When executing a task, wraps the callback in an extra function whose
name includes the current priority level. Profiling tools with access
to function names can use this to determine the priority of the task.
2019-07-10 18:59:44 -07:00
Sebastian Markbåge
48f6594474 Add warning when single item or nested arrays are used with SuspenseList (#16094) 2019-07-10 11:07:28 -07:00
Nicolas Gallagher
2073a7144e [Flare] Press includes button type (#16100)
1. Allow auxillary button clicks (i.e., middle mouse button) to trigger 'onPressStart' and 'onPressEnd', but never 'onPress'.
2. Report the button type – 'primary' or 'auxillary' – on the press event.
2019-07-10 17:52:10 +01:00
Dominic Gannaway
23b8a25345 [Flare] Remove responder flags to simplify logic (#16084) 2019-07-09 15:05:45 +01:00
Eli White
8533c0a168 [Fabric] Add dispatchCommand to React Native renderers (#16085)
* Add dispatchCommand to the public export of the React Native renderers

* Fixup invalid check

* Prettier

* Prettier
2019-07-08 13:03:57 -07:00