Commit Graph

13495 Commits

Author SHA1 Message Date
Brian Vaughn
ffb749c95e Improve error boundary handling for unmounted subtrees (#19542)
A passive effect's cleanup function may throw after an unmount. Prior to this commit, such an error would be ignored. (React would not notify any error boundaries.) After this commit, React's behavior varies depending on which reconciler fork is being used.

For the old reconciler, React will call componentDidCatch for the nearest unmounted error boundary (if there is one). If there are no unmounted error boundaries, React will still swallow the error because the return pointer has been disconnected, so the normal error handling logic does not know how to traverse the tree to find the nearest still-mounted ancestor.

For the new reconciler, React will skip any unmounted boundaries and look for a still-mounted boundary. If one is found, it will call getDerivedStateFromError and/or componentDidCatch (depending on the type of boundary).

Tests have been added for both reconciler variants for now.
2020-08-14 16:46:46 -04:00
Brian Vaughn
9b35dd2fcc Permanently removed component stacks from scheduling profiler data (#19615)
These stacks improve the profiler data but they're expensive to generate and generating them can also cause runtime errors in larger applications (although an exact repro has been hard to nail down). Removing them for now. We can revisit adding them after this profiler has been integrated into the DevTools extension and we can generate them lazily.
2020-08-14 15:21:13 -04:00
Andrew Clark
3f8115cdd1 Remove didTimeout check from work loop
No longer need this, since we have starvation protection in userspace.

This will also allow us to remove the concept from the Scheduler
package, which is nice because `postTask` doesn't currently support it.
2020-08-14 10:45:24 -04:00
Andrew Clark
9abc2785cb Remove wasteful checks from shouldYield
`shouldYield` will currently return `true` if there's a higher priority
task in the Scheduler queue.

Since we yield every 5ms anyway, this doesn't really have any practical
benefit. On the contrary, the extra checks on every `shouldYield` call
are wasteful.
2020-08-14 10:45:11 -04:00
Clay Tercek
fe6d05229f fix event.relatedTarget fallback logic for firefox (#19607)
* fix event.relatedTarget fallback logic for firefox

* check if relatedTarget is undefined for fallback
2020-08-14 13:05:53 +01:00
Jordan Eldredge
1d5e10f703 [eslint-plugin-react-hooks] Report constant constructions (#19590)
* [eslint-plugin-react-cooks] Report constant constructions

The dependency array passed to a React hook can be thought of as a list of cache keys. On each render, if any dependency is not `===` its previous value, the hook will be rerun. Constructing a new object/array/function/etc directly within your render function means that the value will be referentially unique on each render. If you then use that value as a hook dependency, that hook will get a "cache miss" on every render, making the dependency array useless.

This can be especially dangerous since it can cascade. If a hook such as `useMemo` is rerun on each render, not only are we bypassing the option to avoid potentially expensive work, but the value _returned_ by `useMemo` may end up being referentially unique on each render causing other downstream hooks or memoized components to become deoptimized.

* Fix/remove existing tests

* Don't give an autofix of wrapping object declarations

It may not be safe to just wrap the declaration of an object, since the object may get mutated.

Only offer this autofix for functions which are unlikely to get mutated.

Also, update the message to clarify that the entire construction of the value should get wrapped.

* Handle the long tail of nodes that will be referentially unique

* Catch let/var constant constructions on initial assignment

* Trim trailing whitespace

* Address feedback from @gaearon

* Rename "assignment" to "initialization"

* Add test for a constant construction used in multiple dependency arrays
2020-08-13 20:54:33 +01:00
Sebastian Markbåge
dab0854c5e Move commit passive unmount/mount to CommitWork (#19599) 2020-08-13 09:17:33 -07:00
Brian Vaughn
c3ee973c56 Fix emoji character displayed in Chrome extension (#19603) 2020-08-13 11:16:35 -04:00
inottn
ccb6c39451 Remove unused argument (#19600) 2020-08-13 15:11:01 +01:00
Andrew Clark
629125555f [Scheduler] Re-throw unhandled errors (#19595)
Because `postTask` returns a promise, errors inside a `postTask`
callback result in the promise being rejected.

If we don't catch those errors, then the browser will report an
"Unhandled promise rejection" error. This is a confusing message to see
in the console, because the fact that `postTask` is a promise-based API
is an implementation detail from the perspective of the developer.
"Promise rejection" is a red herring.

On the other hand, if we do catch those errors, then we need to report
the error to the user in some other way.

What we really want is the default error reporting behavior that a
normal, non-Promise browser event gets.

So, we'll re-throw inside `setTimeout`.
2020-08-12 20:06:43 -07:00
Pascal Fong Kye
b6e1d08604 DevTools bug fix: Proxied methods should be safely dehydrated for display 2020-08-12 12:15:53 -04:00
Andrew Clark
b8ed6a1aa5 [Scheduler] Call postTask directly (#19551)
This updates the experimental Scheduler postTask build to call postTask
directly, instead of managing our own custom queue and work loop.

We still use a deadline 5ms mechanism to implement `shouldYield`.

The main thing that postTask is currently missing is the continuation
feature — when yielding to the main thread, the yielding task is sent
to the back of the queue, instead of maintaining its position.

While this would be nice to have, even without it, postTask may be good
enough to replace our userspace implementation.

We'll run some tests to see.
2020-08-12 08:39:47 -05:00
Ricky
c8d9b8878a Speed up yarn cache in circle (#19566) 2020-08-11 14:05:15 -04:00
Dan Abramov
ce37bfad5f Remove resolutions from test renderer package.json (#19577) 2020-08-10 20:45:12 +01:00
Kartik Choudhary
2704bb5374 Add ReactVersion to SchedulingProfiler render scheduled marks (#19553)
* Add ReactVersion to SchedulingProfiler render scheduled marks

* Move ReactVersion to a new --react-init-* mark

Co-authored-by: E-Liang Tan <eliang@eliangtan.com>
2020-08-10 10:51:25 -04:00
Brian Vaughn
0c52e24cb6 Support inner component _debugOwner in memo (#19556)
* Support inner component _debugOwner in memo

* test with devtool context

* remove memo test

* Merged master; tweaked test and snapshot

* Pass owner to createFiber fn when creating a memo component.

Co-authored-by: Theodore Han <tqhan317@gmail.com>
2020-08-10 10:49:10 -04:00
Dan Abramov
94c0244bab Fix double-firing mouseenter (#19571)
* test: Simulate mouseover in browser

* Fix duplicate onMouseEnter event when relatedTarget is a root

* Test leave as well

Co-authored-by: Sebastian Silbermann <silbermann.sebastian@gmail.com>
2020-08-10 15:08:22 +01:00
Dan Abramov
aa99b0b08e Rename test files 2020-08-10 12:58:42 +01:00
Sebastian Silbermann
7f696bd99c fix: onFocus/onBlur/onBeforeInput have a matching event type (#19561)
* test: Add current behavior for event types of onFocus/onBlur

* fix: onFocus/onBlur have a matching event type

* fix useFocus

* fix: don't compare native event types with react event types

* Add FocusIn/FocusOutEventInterface

* A simpler alternative fix

* Add regression tests

* Always pass React event type and fix beforeinput

Co-authored-by: Dan Abramov <dan.abramov@me.com>
2020-08-10 12:54:10 +01:00
Sebastian Silbermann
7c30fb3b0b Update outdated lockfile (#19568) 2020-08-10 11:59:37 +01:00
Andrew Clark
0cd9a6de55 Parallelize Jest in CI (#19552)
Uses CircleCI's `parallelism` key to split our test jobs across multiple
processes, like we do for the build job.
2020-08-07 16:32:59 -04:00
Dan Abramov
2d9ec9199c Indent a command 2020-08-07 19:24:49 +01:00
Dan Abramov
db2f229110 Fix command 2020-08-07 19:23:43 +01:00
Dan Abramov
336729856a Nesting Fixture (#19531)
* Nesting Fixture

* Add README to nesting fixture

* Apply suggestions from code review

Co-authored-by: Ricky <rickhanlonii@gmail.com>

* Fixes

* Add Redux

* Use different versions

* Use Consumer API

* Rename helper

* Write docs

* Update README.md

* Update README.md

Co-authored-by: Rick Hanlon <rickhanlonii@gmail.com>
2020-08-07 02:08:41 +01:00
Brian Vaughn
a63893ff32 Warn about undefined return value for memo and forwardRef (#19550) 2020-08-06 16:12:32 -04:00
Ricky
32ff428687 Add feature flag for setting update lane priority (#19401)
* Add feature flag for setting update lane priority

* Remove second feature flag

* Refactor feature flag locations

* Add missing else
2020-08-06 12:47:32 -04:00
Gustavo Saiani
5bdd4c8c60 Remove unused argument from call to jest method (#19546) 2020-08-06 16:55:01 +01:00
Mateusz Burzyński
a5fed98a96 Register more node types that are used later as JSXIdentifiers (#19514) 2020-08-06 16:37:32 +01:00
DaniAcu
50893dbcb7 fix(react-dom): unnecesary path on DOMEventProperties (#19544) 2020-08-06 16:37:06 +01:00
Dominic Gannaway
f77c7b9d76 Re-add discrete flushing timeStamp heuristic (behind flag) (#19540) 2020-08-06 13:21:05 +01:00
Brian Vaughn
e67a6b1603 Fix runtime error that happens if a passive destroy function throws within an unmounted tree (#19543)
A passive effect's cleanup function may throw after an unmount. In that event, React sometimes threw an uncaught runtime error trying to access a property on a null stateNode field. This commit fixes that (and adds a regression test).
2020-08-05 18:22:18 -04:00
Emilis Baliukonis
5cff775502 [Scheduler] Get current time from performance.now in non-DOM environments (#19532)
* Get current time from performance.now in non-DOM environments

* Use local references to native APIs for Date and Performance

* Refactored to read globals directly
2020-08-05 17:29:06 +01:00
Dan Abramov
e9721e14e4 Remove onScroll bubbling flag (#19535) 2020-08-05 16:07:58 +01:00
Dominic Gannaway
b61174fb7b Remove the deprecated React Flare event system (#19520) 2020-08-05 15:13:29 +01:00
Halit Ogunc
8d57ca519a fix: typo in React Release Scripts (#19524) 2020-08-04 13:22:50 -04:00
Ricky
a437f3ff30 Use RN fork in default branch of feature flags (#19522) 2020-08-03 17:40:58 -04:00
Ricky
86314d5b45 Turn off new component stacks for React Native (#19521) 2020-08-03 14:45:50 -04:00
Andrew Clark
5f1890f12b Bugfix: Don't unmount siblings of deleted node (#19516)
* Test: Don't unmount siblings of deleted node

Adds a failing regression test. Will fix in the next commit.

* Refactor to accept deleted fiber, not child list

A deleted fiber is passed to
flushPassiveUnmountEffectsInsideOfDeletedTree, but the code is written
as if it accepts the first node of a child list. This is likely because
the function was based on similar functions like
`flushPassiveUnmountEffects`, which do accept a child list.

Unfortunately, types don't help here because we use the first node
in the list to represent the whole list, so in both cases, the type
is Fiber.

Might be worth changing the other functions to also accept individual
fibers instead of a child list, to help avoid confusion.

* Add layout effect to regression test, just in case
2020-08-03 08:57:41 -07:00
Andrew Clark
93a0c28305 Add static version of Passive subtree tag (#19510)
Creates new subtree tag, PassiveStatic, that represents whether a
tree contains any passive effect hooks.

It corresponds to the PassiveStatic effect tag, which represents the
same concept for an individual fiber.

This allows us to remove the PassiveStatic effect tag from PassiveMask.
Its presence was causing us to schedule a passive effect phase callback
on every render, instead of only when something changed. That's now
fixed; this is reflected in the SchedulerProfiler tests.

(The naming is getting really confusing. Need to do some bikeshedding.)
2020-08-01 08:15:46 -05:00
Dan Abramov
a1c0864d19 Support untagged releases (#19509) 2020-07-31 20:47:28 +01:00
Dan Abramov
5d271fc3b1 Revert "Support untagged releases (#19507)" (#19508)
This reverts commit 58b3ee7a88.
2020-07-31 19:57:32 +01:00
Dan Abramov
58b3ee7a88 Support untagged releases (#19507)
* Support untagged releases

* Fix
2020-07-31 19:18:37 +01:00
Dan Abramov
7543459a48 Allow publishing untagged releases (#19505) 2020-07-31 16:10:01 +01:00
Dan Abramov
3d0895557a Disable onScroll bubbling statically except for WWW (#19503) 2020-07-31 15:09:24 +01:00
Dan Abramov
332eceface Revert "Statically enable enableFilterEmptyStringAttributesDOM (#19502)" (#19504)
This reverts commit 815ee89bf5.
2020-07-31 15:01:27 +01:00
Dan Abramov
815ee89bf5 Statically enable enableFilterEmptyStringAttributesDOM (#19502) 2020-07-31 14:57:57 +01:00
Andrew Clark
ede9170648 Move passive logic out of layout phase (#19500)
* setCurrentFiber per fiber, instead of per effect

* Re-use safelyCallDestroy

Part of the code in flushPassiveUnmountEffects is a duplicate of the
code used for unmounting layout effects. I did some minor refactoring to
so we could use the same function in both places.

Closure will inline anyway so it doesn't affect code size or
performance, just maintainability.

* Don't check HookHasEffect during deletion

We don't need to check HookHasEffect during a deletion; all effects are
unmounted.

So we also don't have to set HookHasEffect during a deletion, either.

This allows us to remove the last remaining passive effect logic from
the synchronous layout phase.
2020-07-30 21:43:03 -07:00
Dan Abramov
22d16cc15d Remove event constants (#19276)
* Remove opaque event type

* Rename type and merge files

* Use literals where we have Flow coverage

* Flowify some plugins

* Remove constants except necessary ones
2020-07-30 21:52:37 +01:00
Andrew Clark
6ef997b534 Check for passive effects on the root fiber (#19488)
The root fiber doesn't have a parent from which we can read the
`subtreeTag`, so we need to check its `effectTag` directly.

The root fiber previously did not have any pending passive effects,
but it does now that deleted fibers are cleaned up in the passive phase.

This allows us to remove a `schedulePassiveEffectCallback` call from the
synchronous unmount path.

Co-authored-by: Brian Vaughn <bvaughn@fb.com>
2020-07-30 09:17:22 -04:00
Andrew Clark
e1f96b82b4 Check PassiveStatic instead of Passive (#19489)
Saves us from having to set a flag on `current` during the layout phase.

Could result in some redundant traversal, since PassiveStatic includes
effects that don't need clean-up. But it's worth it to remove the work
from the layout phase.

While I was editing this, I also re-arranged it so that we check the
`effectTag` check before we check the `tag`, since the `effectTag` check
is the one that's more likely to fail.
2020-07-30 09:13:04 -04:00