Commit Graph
121 Commits
Author SHA1 Message Date
Jan KassensandGitHub ea7805058c [flow] make Flow suppressions explicit on the error (#26487)
Added an explicit type to all $FlowFixMe suppressions to reduce
over-suppressions of new errors that might be caused on the same lines.

Also removes suppressions that aren't used (e.g. in a `@noflow` file as
they're purely misleading)

Test Plan:
yarn flow-ci
2023-03-27 13:43:04 +02:00
Tianyu YaoandGitHub 0afc8f5587 Convert more Scheduler.unstable_flushAll in tests to new test utils (#26369)
`Scheduler.unstable_flushAll` in existing tests doesn't work with
microtask. This PR converts most of the remaining
`Scheduler.unstable_flushAll()` calls to using internal test utilities
to unblock refactoring `ensureRootIsScheduled` with scheduling a
microtask.
2023-03-10 20:56:13 -05:00
Andrew ClarkandGitHub df7d322402 Codemod redundant async act scopes (#26350)
Prior to #26347, our internal `act` API (not the public API) behaved
differently depending on whether the scope function returned a promise
(i.e. was an async function), for historical reasons that no longer
apply. Now that this is fixed, I've codemodded all async act scopes that
don't contain an await to be sync.

No pressing motivation other than it looks nicer and the codemod was
easy. Might help avoid confusion for new contributors who see async act
scopes with nothing async inside and infer it must be like that for a
reason.
2023-03-08 16:40:23 -05:00
Andrew ClarkandGitHub 6f6a41da6d Move internalAct to internal-test-utils package (#26344)
This is not a public API. We only use it for our internal tests, the
ones in this repo. Let's move it to this private package. Practically
speaking this will also let us use async/await in the implementation.
2023-03-08 12:58:31 -05:00
Andrew ClarkandGitHub 346d17951e Codemod act -> await act (1/?) (#26334)
Similar to the rationale for `waitFor` (see
https://github.com/facebook/react/pull/26285), we should always await
the result of an `act` call so that microtasks have a chance to fire.

This only affects the internal `act` that we use in our repo, for now.
In the public `act` API, we don't yet require this; however, we
effectively will for any update that triggers suspense once `use` lands.
So we likely will start warning in an upcoming minor.
2023-03-07 10:15:34 -05:00
Jan KassensandGitHub 1aa5d9cf56 [flow] enable LTI inference mode (#26104)
This is the next generation inference mode for Flow.
2023-02-09 17:07:39 -05:00
Jan KassensandGitHub 5d81201dc2 [flow] enable enforce_local_inference_annotations (#25921)
This setting is an incremental path to the next Flow version enforcing
type annotations on most functions (except some inline callbacks).

Used
```
node_modules/.bin/flow codemod annotate-functions-and-classes --write .
```
to add a majority of the types with some hand cleanup when for large
inferred objects that should just be `Fiber` or weird constructs
including `any`.

Suppressed the remaining issues.

Builds on #25918
2023-01-09 15:46:48 -05:00
Andrew ClarkandGitHub 6dd316c347 [Codemod] Update copyright header to Meta (#25315)
* Facebook -> Meta in copyright

rg --files | xargs sed -i 's#Copyright (c) Facebook, Inc. and its affiliates.#Copyright (c) Meta Platforms, Inc. and affiliates.#g'

* Manual tweaks
2022-10-18 11:19:24 -04:00
Jan KassensandGitHub 81b1364ec6 Flow: remove explicit object syntax (#25223) 2022-09-09 16:03:48 -04:00
Jan KassensandGitHub 964b1fbdfc Flow: implicit-inexact-object=error (#25210)
* implicit-inexact-object=error
* default everything ambiguous to exact object
* inexact where exact causes errors
2022-09-09 10:13:58 -04:00
abd56036d5 Move createRoot/hydrateRoot to react-dom/client (#23385)
* Move createRoot/hydrateRoot to /client

We want these APIs ideally to be imported separately from things you
might use in arbitrary components (like flushSync). Those other methods
are "isomorphic" to how the ReactDOM tree is rendered. Similar to hooks.

E.g. importing flushSync into a component that only uses it on the client
should ideally not also pull in the entry client implementation on the
server.

This also creates a nicer parity with /server where the roots are in a
separate entry point.

Unfortunately, I can't quite do this yet because we have some legacy APIs
that we plan on removing (like findDOMNode) and we also haven't implemented
flushSync using a flag like startTransition does yet.

Another problem is that we currently encourage these APIs to be aliased by
/profiling (or unstable_testing). In the future you don't have to alias
them because you can just change your roots to just import those APIs and
they'll still work with the isomorphic forms. Although we might also just
use export conditions for them.

For that all to work, I went with a different strategy for now where the
real API is in / but it comes with a warning if you use it. If you instead
import /client it disables the warning in a wrapper. That means that if you
alias / then import /client that will inturn import the alias and it'll
just work.

In a future breaking changes (likely when we switch to ESM) we can just
remove createRoot/hydrateRoot from / and move away from the aliasing
strategy.

* Update tests to import from react-dom/client

* Fix fixtures

* Update warnings

* Add test for the warning

* Update devtools

* Change order of react-dom, react-dom/client alias

I think the order matters here. The first one takes precedence.

* Require react-dom through client so it can be aliased

Co-authored-by: Andrew Clark <[email protected]>
2022-03-01 00:13:28 -05:00
Sebastian MarkbågeandGitHub a0d178bf8c Update the exports field (#23257)
* Add .browser and .node explicit entry points

This can be useful when the automatic selection doesn't work properly.

* Remove react/index

I'm not sure why I added this in the first place. Perhaps due to how our
builds work somehow.

* Remove build-info.json from files field
2022-02-08 21:07:26 -05:00
hiroandGitHub 2a40fc5845 fix(typo): Esacpe -> Escape (#22780) 2021-11-16 16:43:25 -05:00
Andrew ClarkandGitHub 66bcc9758c Remove internal act builds from public modules (#21721)
* Move internal version of act to shared module

No reason to have three different copies of this anymore.

I've left the the renderer-specific `act` entry points because legacy
mode tests need to also be wrapped in `batchedUpdates`. Next, I'll update
the tests to use `batchedUpdates` manually when needed.

* Migrates tests to use internal module directly

Instead of the `unstable_concurrentAct` exports. Now we can drop those
from the public builds.

I put it in the jest-react package since that's where we put our other
testing utilities (like `toFlushAndYield`). Not so much so it can be
consumed publicly (nobody uses that package except us), but so it works
with our build tests.

* Remove unused internal fields

These were used by the old act implementation. No longer needed.
2021-06-22 14:29:35 -07:00
Sebastian MarkbågeandGitHub 137f4efe14 Resolve the true entry point during tests (#21505)
* Resolve the entry point for tests the same way builds do

This way the source tests, test the same entry point configuration.

* Gate test selectors on www

These are currently only exposed in www builds

* Gate createEventHandle / useFocus on www

These are enabled in both www variants but not OSS experimental.

* Temporarily disable www-modern entry point

Use the main one that has all the exports until we fix more tests.

* Remove enableCache override that's no longer correct

* Open gates for www

These used to not be covered because they used Cache which wasn't exposed.
2021-06-02 18:03:29 -07:00
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