Commit Graph

1138 Commits

Author SHA1 Message Date
Dan Abramov
89b610969d Bump versions for 17 2020-10-20 21:33:44 +01:00
Shivam Sandbhor
4ead6b5305
Treat <time> tag as a normal HTML tag. (#19951)
<time> tag has been supported by Chrome since Chrome 62.0.
Remove workarounds which were in place to avoid friction with
versions before Chrome 62.

Signed-off-by: Shivam Sandbhor <shivam.sandbhor@gmail.com>
2020-10-06 03:15:32 +01:00
Dan Abramov
480626a9e9
Create Synthetic Events Lazily (#19909) 2020-09-25 13:33:28 +01:00
Dan Abramov
0a00804494
Remove Array.from() from hot path (#19908)
* Remove Array.from() from hot path

* Fix build

Don't declare block variables inside loops
2020-09-25 11:33:07 +01:00
Dan Abramov
1890159a5d
Separate SyntheticEvent constructors to prevent deopts (#19907)
* Remove arguments from hot path

* Make SyntheticEvent subtypes monomorphic

* Maybe fix Flow?
2020-09-25 11:31:00 +01:00
Dan Abramov
6fddca27e7
Remove passive intervention flag (#19849) 2020-09-17 15:37:12 +01:00
Andrew Clark
b93f3e7d2d
Fix act bundle size regression (#19832)
Adds back the `TestUtils.act` implementation that I had removed
in #19745. This version of `act` is implemented in "userspace" (i.e. not
the reconciler), so it doesn't add to the production bundle size.

I had removed this in #19745 in favor of the `act` exported by the
reconciler because I thought we would remove support for `act` in
production in the impending major release. (It currently warns.)

However, we've since decided to continue supporting `act` in prod for
now, so that it doesn't block people from upgrading to v17. We'll drop
support in a future major release.

So, to avoid bloating the production bundle size, we need to move the
public version of `act` back to "userspace", like it was before.

This doesn't negate the main goal of #19745, though, which was to
decouple the public version(s) of `act` from the internal one that we
use to test React itself.
2020-09-14 10:11:47 -07:00
Dan Abramov
11ee82df45
[Events] Make passiveness and priority non-configurable (#19807) 2020-09-14 13:54:08 +01:00
Dan Abramov
a08ae9f147
Listen to onScroll during hydration (#19803) 2020-09-10 11:00:02 +01:00
Andrew Clark
e7b255341b
Internal act: Flush timers at end of scope (#19788)
If there are any suspended fallbacks at the end of the `act` scope,
force them to display by running the pending timers (i.e. `setTimeout`).

The public implementation of `act` achieves the same behavior with an
extra check in the work loop (`shouldForceFlushFallbacks`). Since our
internal `act` needs to work in both development and production, without
additional runtime checks, we instead rely on Jest's mock timers.

This doesn't not affect refresh transitions, which are meant to delay
indefinitely, because in that case we exit the work loop without
posting a timer.
2020-09-08 21:55:23 -07:00
Andrew Clark
d17086c7c8
Decouple public, internal act implementation (#19745)
In the next major release, we intend to drop support for using the `act`
testing helper in production. (It already fires a warning.) The
rationale is that, in order for `act` to work, you must either mock the
testing environment or add extra logic at runtime. Mocking the testing
environment isn't ideal because it requires extra set up for the user.
Extra logic at runtime is fine only in development mode — we don't want
to slow down the production builds.

Since most people only run their tests in development mode, dropping
support for production should be fine; if there's demand, we can add it
back later using a special testing build that is identical to the
production build except for the additional testing logic.

One blocker for removing production support is that we currently use
`act` to test React itself. We must test React in both development and
production modes.

So, the solution is to fork `act` into separate public and
internal implementations:

- *public implementation of `act`* – exposed to users, only works in
  development mode, uses special runtime logic, does not support partial
  rendering
- *internal implementation of `act`* – private, works in both
  development and productionm modes, only used by the React Core test
  suite, uses no special runtime logic, supports partial rendering (i.e.
  `toFlushAndYieldThrough`)

The internal implementation should mostly match the public
implementation's behavior, but since it's a private API, it doesn't have
to match exactly. It works by mocking the test environment: it uses a
mock build of Scheduler to flush rendering tasks, and Jest's mock timers
to flush Suspense placeholders.

---

In this first commit, I've added the internal forks of `act` and
migrated our tests to use them. The public `act` implementation is
unaffected for now; I will leave refactoring/clean-up for a later step.
2020-09-08 08:11:45 -07:00
Dan Abramov
bcc0aa4633
Revert "Revert "Remove onScroll bubbling flag (#19535)" (#19655)" (#19761)
This reverts commit 64ddef44c6.
2020-09-03 17:06:20 +01:00
Andrew Clark
1f38dcff67
Remove withSuspenseConfig (#19724)
Removes `withSuspenseConfig` and migrates relevant tests to
`startTransition` instead.

We only had one caller in www, which I've removed.
2020-08-31 09:16:49 -07:00
Andrew Clark
4f5fb56100
Use gate pragma instead of if (__EXPERIMENTAL__) (#19722)
* Use gate pragma instead of if (__EXPERIMENTAL__)

* Fix stream error handling in tests

Added an error listener so that the tests fail within their Jest scope,
instead of crashing the whole process.
2020-08-28 14:21:01 -07:00
Andrew Clark
ddd1faa197
Remove config argument from useTransition (#19719)
And `useDeferredValue`.

The options were already disabled in previous commits, so this doesn't
change any behavior. I upated type signatures and cleaned up the hook
implementation a bit — no longer have to wrap the `start` method with
`useCallback`, because its only remaining dependency is a `setState`
method, which never changes. Instead, we can store the `start` method
on a ref.
2020-08-28 11:49:01 -07:00
Andrew Clark
92fcd46cc7
Replace SuspenseConfig object with an integer (#19706)
Now that the options in SuspenseConfig are no longer supported, the
only thing we use it for is to track whether an update is part of
a transition.

I've renamed `ReactCurrentBatchConfig.suspense` to
`ReactCurrentBatchConfig.transition`, and changed the type to a number.
The number is always either 0 or 1. I could have made it a boolean;
however, most likely this will eventually be either a Lane or an
incrementing identifier.

The `withSuspenseConfig` export still exists until we've removed
all the callers from www.
2020-08-28 10:52:56 -07:00
Dan Abramov
b754caaaf2
Enable eager listeners in open source (#19716)
* Enable eager listeners in open source

* Fix tests

* Enable in all places
2020-08-28 12:23:28 +01:00
Andrew Clark
8da0da0937
Disable timeoutMs argument (#19703)
* Remove distinction between long, short transitions

We're removing the `timeoutMs` option, so there's no longer any
distinction between "short" and "long" transitions. They're all treated
the same.

This commit doesn't remove `timeoutMs` yet, only combines the internal
priority levels.

* Disable `timeoutMs` argument

tl;dr
-----

- We're removing the `timeoutMs` argument from `useTransition`.
- Transitions will either immediately switch to a skeleton/placeholder
  view (when loading new content) or wait indefinitely until the data
  resolves (when refreshing stale content).
- This commit disables the `timeoutMS` so that the API has the desired
  semantics. It doesn't yet update the types or migrate all the test
  callers. I'll do those steps in follow-up PRs.

Motivation
----------

Currently, transitions initiated by `startTransition` / `useTransition`
accept a `timeoutMs` option. You can use this to control the maximum
amount of time that a transition is allowed to delay before we give up
and show a placeholder.

What we've discovered is that, in practice, every transition falls into
one of two categories: a **load** or a **refresh**:

- **Loading a new screen**: show the next screen as soon as possible,
  even if the data hasn't finished loading. Use a skeleton/placeholder
  UI to show progress.
- **Refreshing a screen that's already visible**: keep showing the
  current screen indefinitely, for as long as it takes to load the fresh
  data, even if the current data is stale. Use a pending state (and
  maybe a busy indicator) to show progress.

In other words, transitions should either *delay indefinitely* (for a
refresh) or they should show a placeholder *instantly* (for a load).
There's not much use for transitions that are delayed for a
small-but-noticeable amount of time.

So, the plan is to remove the `timeoutMs` option. Instead, we'll assign
an effective timeout of `0` for loads, and `Infinity` for refreshes.

The mechanism for distinguishing a load from a refresh already exists in
the current model. If a component suspends, and the nearest Suspense
boundary hasn't already mounted, we treat that as a load, because
there's nothing on the screen. However, if the nearest boundary is
mounted, we treat that as a refresh, since it's already showing content.

If you need to fix a transition to be treated as a load instead of a
refresh, or vice versa, the solution will involve rearranging the
location of your Suspense boundaries. It may also involve adding a key.

We're still working on proper documentation for these patterns. In the
meantime, please reach out to us if you run into problems that you're
unsure how to fix.

We will remove `timeoutMs` from `useDeferredValue`, too, and apply the
same load versus refresh semantics to the update that spawns the
deferred value.

Note that there are other types of delays that are not related to
transitions; for example, we will still throttle the appearance of
nested placeholders (we refer to this as the placeholder "train model"),
and we may still apply a Just Noticeable Difference heuristic (JND) in
some cases. These aren't going anywhere. (Well, the JND heuristic might
but for different reasons than those discussed above.)
2020-08-26 14:35:13 -07:00
Dan Abramov
848bb2426e
Attach Listeners Eagerly to Roots and Portal Containers (#19659)
* Failing test for #19608

* Attach Listeners Eagerly to Roots and Portal Containers

* Forbid createEventHandle with custom events

We can't support this without adding more complexity. It's not clear that this is even desirable, as none of our existing use cases need custom events. This API primarily exists as a deprecation strategy for Flare, so I don't think it is important to expand its support beyond what Flare replacement code currently needs. We can later revisit it with a better understanding of the eager/lazy tradeoff but for now let's remove the inconsistency.

* Reduce risk by changing condition only under the flag

Co-authored-by: koba04 <koba0004@gmail.com>
2020-08-24 16:50:20 +01:00
Dominic Gannaway
8c9fc4e90f
Remove usage of PossiblyWeakSet from createEventHandle (#19686) 2020-08-24 16:10:23 +01:00
Toru Kobayashi
2ada4bd0c2
Add a test for non-passive event handlers for events affected by the browsers' intervention (#19658) 2020-08-24 14:30:17 +01:00
Dan Abramov
90d212d326
Fix movementX/Y polyfill with capture events (#19672)
* Fix movementX/Y polyfill with capture events

* Remove unnecesary call for better inlining
2020-08-21 16:55:41 +01:00
Hemakshi Sachdev
f912186012
Fix: Unspecified error for IE11 (#19530) (#19664) 2020-08-20 21:53:23 +01:00
Dan Abramov
08e69f65b4
Fix incorrect copy-paste in test (#19657) 2020-08-20 01:47:32 +01:00
Dan Abramov
64ddef44c6
Revert "Remove onScroll bubbling flag (#19535)" (#19655)
This reverts commit e9721e14e4.
2020-08-19 20:54:54 +01:00
Dan Abramov
dd651df05e
Keep onTouchStart, onTouchMove, and onWheel passive (#19654)
* Keep onTouchStart, onTouchMove, and onWheel passive

* Put it behind a feature flag on WWW
2020-08-19 18:42:33 +01:00
Sebastian Silbermann
87b3e2d257
Add flow to SyntheticEvent (#19564)
* Add flow to SyntheticEvent

* Minimal implementation of known and unknown synthetic events

* less casting

* Update EnterLeaveEventPlugin.js

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
2020-08-19 14:16:48 +01:00
Toru Kobayashi
32ca313060
refactor: remove unnecessary return statements (#19625) 2020-08-19 14:10:41 +01:00
Brian Vaughn
bcca5a6ca7
Always skip unmounted/unmounting error boundaries (#19627)
The behavior of error boundaries for passive effects that throw during cleanup was recently changed so that React ignores boundaries which are also unmounting in favor of still-mounted boundaries. This commit implements that same behavior for layout effects (useLayoutEffect, componentWillUnmount, and ref-detachment).

The new, skip-unmounting-boundaries behavior is behind a feature flag (`skipUnmountedBoundaries`).
2020-08-17 15:01:06 -04:00
Jack Works
1287670191
Fix: React cannot render in ShadowRoot (#15894)
* fix: render in shadow root

* fix: flow typing

* Remove types and turn invariant into warning

Co-authored-by: Dan Abramov <dan.abramov@me.com>
2020-08-17 15:47:49 +01:00
CY Lim
702fad4b1b
refactor fb.me redirect link to reactjs.org/link (#19598)
* refactor fb.me url to reactjs.org/link

* Update ESLintRuleExhaustiveDeps-test.js

* Update ReactDOMServerIntegrationUntrustedURL-test.internal.js

* Update createReactClassIntegration-test.js

* Update ReactDOMServerIntegrationUntrustedURL-test.internal.js

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
2020-08-17 13:25:50 +01:00
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
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
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
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
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
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
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
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
Dan Abramov
dff97a6915
Fix onGot/LostPointerCapture events (#19487) 2020-07-29 21:54:48 +01:00
Dan Abramov
291db05a75
Add regression tests for all events (#19485) 2020-07-29 21:13:56 +01:00
Dan Abramov
0eea16601c
Event propagation test suite (#19483) 2020-07-29 15:34:57 +01:00
Sebastian Silbermann
feb134c30d
feat(react-dom): Add enterKeyHint (#18634) 2020-07-27 21:07:08 +01:00
Dominic Gannaway
144297165b
Bail-out of attaching non-delegated listeners (#19466)
* Bail-out of attaching non-delegated listeners

Revise comment

* Fix tests/add tests

* Add onInvalid test
2020-07-27 17:47:14 +01:00