Commit Graph
106 Commits
Author SHA1 Message Date
Dan AbramovandGitHub e73ba7897f Bump versions for 17 (#20062) 2020-10-20 21:41:18 +01:00
Dan AbramovandGitHub 1671bc8c80 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 AbramovandGitHub ce7ae12cf9 [Events] Make passiveness and priority non-configurable (#19807) 2020-09-14 13:54:08 +01:00
Andrew ClarkandGitHub 636cc7f810 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
c07648fdc2 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 <[email protected]>
2020-08-10 12:54:10 +01:00
Dominic GannawayandGitHub cd2ab43b72 Remove the deprecated React Flare event system (#19520) 2020-08-05 15:13:29 +01:00
Haseeb KhanandGitHub 4f2af510c7 Added the word "events" to clear ambiguousness. (#19409) 2020-07-20 18:26:41 +01:00
Dominic GannawayandGitHub 560465adc4 Sync latest useFocus/useFocusWithin changes (#19397) 2020-07-17 16:26:40 +01:00
Dominic GannawayandGitHub 0fda4c6c21 Modern Event System: use focusin/focusout for onFocus/onBlur (#19186) 2020-07-16 18:12:03 +01:00
Dominic GannawayandGitHub 009e7ad30e Tidy up React Scope API (#19352) 2020-07-16 16:21:21 +01:00
Brian VaughnandGitHub 7df0d0646c Fix Suspense-wrapping heuristic (and bump version numbers) (#19373)
* Fixed suspense wrapping heuristic

* Bump package numbers 16.13.1 -> 17.0.0-alpha.0 to fix DevTools Suspense heuristic
2020-07-15 12:25:27 -04:00
Dominic GannawayandGitHub 9f9be25750 Revise useFocus/useFocusWithin (#19310) 2020-07-10 17:23:00 +01:00
Dominic GannawayandGitHub 3e20503634 Update useEvent implementation (#19271) 2020-07-07 14:44:56 +01:00
Dominic GannawayandGitHub 894eeff0ea Refactor createEventHandle signature (#19174) 2020-07-07 13:05:06 +01:00
Dominic GannawayandGitHub 21cd8582f4 Refine event registration + event signatures (#19244)
* Refine event registration + event signatures

* Address feedback
2020-07-06 17:42:01 +01:00
Dan AbramovandGitHub e7bd4e2c09 Enable modern event system and delete dead code (#19230) 2020-07-01 17:43:34 +01:00
Dominic GannawayandGitHub 96a726eeb4 Remove React Flare Keyboard responder (#19222) 2020-07-01 15:43:16 +01:00
RickyandGitHub 7c9c5ff51c Fix spelling errors and typos (#19138) 2020-06-15 19:59:44 -04:00
Dominic GannawayandGitHub bef0be8e45 React Flare: fix PressLegacy preventDefault issue (#18904) 2020-05-13 13:59:32 +01:00
Dominic GannawayandGitHub fc738832a6 Add experimental ReactDOM.createEventHandle (#18756) 2020-05-12 20:24:25 +01:00
Sebastian MarkbågeandGitHub eb0c6bcdb1 Remove old CM exports (#18710) 2020-05-04 21:39:57 -07:00
Dominic GannawayandGitHub 3e71688532 Remove ReactDOM.useEvent and associated types+tests (#18689) 2020-04-21 16:40:44 +01:00
Dominic GannawayandGitHub 261fbfda82 Revert "Pressable click fix (#18625)" (#18688)
This reverts commit adaef59079.
2020-04-21 11:08:30 +01:00
Naman GoelandGitHub adaef59079 Pressable click fix (#18625)
* Update press-legacy to use native click events

* update tests for pressable change

* fix formatting issue

* Address comments. Bring back some tests, remove others. Cleanup

* Fix flow and lint errors

* formatting fix missed by yarn lint
2020-04-20 23:13:17 +01:00
Dominic GannawayandGitHub 7e2f380123 Refine the heuristics around beforeblur/afterblur (#18668)
* Refine the heuristics around beforeblur/afterblur
2020-04-20 19:32:22 +01:00
Dominic GannawayandGitHub 9782279def Revert "Revert focus event PRs (#18655)" (#18671)
This reverts commit 978e42f108.
2020-04-20 16:00:33 +01:00
Dominic GannawayandGitHub 978e42f108 Revert focus event PRs (#18655)
* Revert "Further cleanup to before/after blur (#18649)"

This reverts commit 3de3ed5195.

* Revert "Unify Flare FocusWithin responder with useFocusWithin (#18636)"

This reverts commit 8024c7d097.
2020-04-17 16:27:19 +01:00
Dominic GannawayandGitHub 3de3ed5195 Further cleanup to before/after blur (#18649) 2020-04-17 11:52:29 +01:00
Dominic GannawayandGitHub 8024c7d097 Unify Flare FocusWithin responder with useFocusWithin (#18636) 2020-04-16 19:35:41 +01:00
Dominic GannawayandGitHub 2a236c5fe0 ReactDOM.useEvent: add useEvent interaction hook (#18604) 2020-04-14 22:06:46 +01:00
Dominic GannawayandGitHub 04eb83d80d Move beforeblur phase to prepareForCommit (#18609) 2020-04-14 21:30:54 +01:00
Andrew ClarkandGitHub 5b8975dcdf Migrate conditional tests to gate pragma (#18585)
* Migrate conditional tests to gate pragma

I searched through the codebase for this pattern:

```js
describe('test suite', () => {
  if (!__EXPERIMENTAL__) { // or some other condition
    test("empty test so Jest doesn't complain", () => {});
    return;
  }

  // Unless we're in experimental mode, none of the tests in this block
  // will run.
})
```

and converted them to the `@gate` pragma instead.

The reason this pattern isn't preferred is because you end up disabling
more tests than you need to.

* Add flag for www release channels

Using a heuristic where I check a flag that is known to only be enabled
in www. I left a TODO to instead set the release channel explicitly in
each test config.
2020-04-13 14:45:52 -07:00
Andrew ClarkandGitHub 8635170ab7 Codemod it.experimental to gate pragma (#18582)
* Codemod it.experimental to gate pragma

Find-and-replace followed by Prettier

* Delete it.experimental

Removes the API from our test setup script
2020-04-13 10:28:59 -07:00
Sebastian MarkbågeandGitHub d7c8ea3d11 Port more tests to the Scheduler.unstable_yieldValue pattern and drop internal.js (#18549)
* Drop the .internal.js suffix on some files that don't need it anymore

* Port some ops patterns to scheduler yield

* Fix triangle test to avoid side-effects in constructor

* Move replaying of setState updaters until after the effect

Otherwise any warnings get silenced if they're deduped.

* Drop .internal.js in more files

* Don't check propTypes on a simple memo component unless it's lazy

Comparing the elementType doesn't work for this because it will never be
the same for a simple element.

This caused us to double validate these. This was covered up because in
internal tests this was deduped since they shared the prop types cache
but since we now inline it, it doesn't get deduped.
2020-04-08 20:54:54 -07:00
Dan AbramovandGitHub c434f936af Update to Jest 25 (#18480)
* Revert "Revert "Upgrade to jest 25 (#17896)" (#18376)"

This reverts commit a038264fcc.

* Other fixes

* Fix a broken test
2020-04-03 16:37:36 +01:00
Dan AbramovandGitHub 0c5dfaaae9 Run more flags in VARIANT tests (#18461)
* Run more flags in VARIANT tests

* Revert enabling modern system

* Fix
2020-04-02 16:19:09 +01:00
Sebastian MarkbågeandGitHub b4dbce0e7f Enable prefer-const lint rules (#18451)
* Enable prefer-const rule

Stylistically I don't like this but Closure Compiler takes advantage of
this information.

* Auto-fix lints

* Manually fix the remaining callsites
2020-04-01 12:35:52 -07:00
Andrew ClarkandGitHub a038264fcc Revert "Upgrade to jest 25 (#17896)" (#18376)
This reverts commit 626c0fd9d7.

The changes to the test code relate to changes in JSDOM that come with Jest 25:

* Several JSDOM workarounds are no longer needed.
* Several tests made assertions to match incorrect JSDOM behavior (e.g. setAttribute calls) that JSDOM has now patched to match browsers.
  * https://codesandbox.io/s/resets-value-of-datetime-input-to-fix-bugs-in-ios-safari-1ppwh
* JSDOM no longer triggers default actions when dispatching click events.
  * https://codesandbox.io/s/beautiful-cdn-ugn8f
* JSDOM fixed (jsdom/jsdom#2700) a bug so that calling focus() on an already focused element does not dispatch a FocusEvent.
* JSDOM now supports passive events.
* JSDOM has improved support for custom CSS properties.
  * But requires jsdom/cssstyle#112 to land to support webkit prefixed properties.
2020-03-24 10:51:48 -07:00
Sebastian MarkbågeandGitHub 96e5d57d2f Move some files out of /shared and rename to upper case (#18363)
* Rename lower case isomorphic default exports modules to upper case named exports

We're somewhat inconsistent here between e.g. ReactLazy and memo.

Let's pick one.

This also moves the responder, fundamental, scope creators from shared
since they're isomorphic and same as the other creators.

* Move some files that are specific to the react-reconciler from shared

Individual renderers are allowed to deep require into the reconciler.

* Move files specific to react-dom from shared

react-interactions is right now dom specific (it wasn't before) so we can
type check it together with other dom stuff. Avoids the need for
a shared ReactDOMTypes to be checked by RN for example.

* Move ReactWorkTags to the reconciler

* Move createPortal to export from reconciler

Otherwise Noop can't access it since it's not allowed deep requires.
2020-03-21 15:22:01 -07:00
Brian VaughnandGitHub c7e696b944 Fix flow types (#18204)
* Added missing @flow pragma to React.js

* Fixed useContext() return type definition

* Fixed previously masked Flow errors in DevTools and react-interactions packages

* Added displayName to internal Context Flow type

* Removed Flow generic annotations for createResponder

This seems to cause a parsing error. (Not sure why.) The API is deprecated anyway so I'm being lazy for now and just adding a .
2020-03-03 12:46:24 -08:00
Dominic GannawayandGitHub 720126dcdf Fix bug with PressLegacy blur (#18194) 2020-03-02 13:42:46 +00:00
Sebastian MarkbågeandGitHub fb8cb47f01 Move remaining things to named exports (#18165)
* Move remaining things to named exports

The interesting case here is the noop renderers. The wrappers around the
reconciler now changed to use a local export that gets mutated.

ReactNoop and ReactNoopPersistent now have to destructure the object to
list out the names it's going to export. We should probably refactor
ReactNoop away from createReactNoop. Especially since it's also not Flow
typed.

* Switch interactions to star exports

This will have esModule compatibility flag on them. They should ideally
export default instead.
2020-02-27 17:18:55 -08:00
Sebastian MarkbågeandGitHub ad1819c135 Export React as Named Exports instead of CommonJS (#18106)
* Add options for forked entry points

We currently fork .fb.js entry points. This adds a few more options.

.modern.fb.js - experimental FB builds
.classic.fb.js - stable FB builds
.fb.js - if no other FB build, use this for FB builds
.experimental.js - experimental builds
.stable.js - stable builds
.js - used if no other override exists

This will be used to have different ES exports for different builds.

* Switch React to named exports

* Export named exports from the export point itself

We need to re-export the Flow exported types so we can use them in our code.

We don't want to use the Flow types from upstream since it doesn't have the non-public APIs that we have.

This should be able to use export * but I don't know why it doesn't work.

This actually enables Flow typing of React which was just "any" before.
This exposed some Flow errors that needs fixing.

* Create forks for the react entrypoint

None of our builds expose all exports and they all differ in at least one
way, so we need four forks.

* Set esModule flag to false

We don't want to emit the esModule compatibility flag on our CommonJS
output. For now we treat our named exports as if they're CommonJS.

This is a potentially breaking change for scheduler (but all those apis
are unstable), react-is and use-subscription. However, it seems unlikely
that anyone would rely on this since these only have named exports.

* Remove unused Feature Flags

* Let jest observe the stable fork for stable tests

This lets it do the negative test by ensuring that the right tests fail.

However, this in turn will make other tests that are not behind
__EXPERIMENTAL__ fail. So I need to do that next.

* Put all tests that depend on exports behind __EXPERIMENTAL__

Since there's no way to override the exports using feature flags
in .intern.js anymore we can't use these APIs in stable.

The tradeoff here is that we can either enable the negative tests on
"stable" that means experimental are expected to fail, or we can disable
tests on stable. This is unfortunate since some of these APIs now run on
a "stable" config at FB instead of the experimental.

* Switch ReactDOM to named exports

Same strategy as React.

I moved the ReactDOMFB runtime injection to classic.fb.js

Since we only fork the entrypoint, the `/testing` entrypoint needs to
be forked too to re-export the same things plus `act`. This is a bit
unfortunate. If it becomes a pattern we can consider forking in the
module resolution deeply.

fix flow

* Fix ReactDOM Flow Types

Now that ReactDOM is Flow type checked we need to fix up its types.

* Configure jest to use stable entry for ReactDOM in non-experimental

* Remove additional FeatureFlags that are no longer needed

These are only flagging the exports and no implementation details so we
can control them fully through the export overrides.
2020-02-25 13:54:27 -08:00
Dominic GannawayandGitHub 8a89c1c87e [react-interactions] Ensure blur to window disengages press (#18125) 2020-02-25 14:14:19 +00:00
Sebastian MarkbågeandGitHub 33fea4647c Codemod to import * as React from "react"; (#18102)
* import * as React from "react";

This is the correct way to import React from an ES module since the ES
module will not have a default export. Only named exports.

* import * as ReactDOM from "react-dom"
2020-02-21 19:45:20 -08:00
Dominic GannawayandGitHub e9e66de873 Add guard around FocusWithin responder root events (#18080) 2020-02-19 18:32:18 +00:00
Dominic GannawayandGitHub 9226366a93 [react-interactions] Ensure onBeforeBlur fires for hideInstance (#18064) 2020-02-18 18:50:38 +00:00
Dominic GannawayandGitHub 15a6c89965 Do not export passiveBrowserEventsSupported from Focus responder (#18022)
Remove code
2020-02-11 15:57:37 -08:00
Simen BekkhusandNicolas Gallagher 626c0fd9d7 Upgrade to jest 25 (#17896)
The changes to the test code relate to changes in JSDOM that come with Jest 25:

* Several JSDOM workarounds are no longer needed.
* Several tests made assertions to match incorrect JSDOM behavior (e.g. setAttribute calls) that JSDOM has now patched to match browsers.
  * https://codesandbox.io/s/resets-value-of-datetime-input-to-fix-bugs-in-ios-safari-1ppwh
* JSDOM no longer triggers default actions when dispatching click events.
  * https://codesandbox.io/s/beautiful-cdn-ugn8f
* JSDOM fixed (jsdom/jsdom#2700) a bug so that calling focus() on an already focused element does not dispatch a FocusEvent.
* JSDOM now supports passive events.
* JSDOM has improved support for custom CSS properties.
  * But requires jsdom/cssstyle#112 to land to support webkit prefixed properties.
2020-01-25 08:43:02 -08:00
Nicolas GallagherandGitHub 617cc1c4ef Remove unused modules from legacy event responders (#17907) 2020-01-24 10:50:27 -08:00