Commit Graph

4292 Commits

Author SHA1 Message Date
Josh Story 618388bc32
[Float] Support script preloads (#25432)
* support script preloads

* gates
2022-10-05 09:47:35 -07:00
Sebastian Silbermann 65b3449c89
Include install command for devtools-extension build instructions (#25053)
Include install command for devtools-extension build instructions
2022-10-05 11:27:09 -04:00
Josh Story 2872a26e14
track resources in different roots separately (#25388)
* track resources in different roots separately

* flow types

* add test demonstrating portals deep into shadowRoots

* revert hostcontext changes

* lints

* funge style cache key a la ReactDOMComponentTree

* hide hacks in componentTree
2022-10-04 16:11:15 -07:00
Jan Kassens ea04a486a7
Flow: remove unused suppressions (#25424)
Removes $FlowFixMe's that are no longer needed.

Used flow/tool from the Flow repo:

```
 ~/Developer/flow/tool update-suppressions .
```
2022-10-04 16:18:12 -04:00
Jan Kassens 9813edef29 Flow upgrade to 0.188
ghstack-source-id: 5c359b97cc
Pull Request resolved: https://github.com/facebook/react/pull/25423
2022-10-04 15:49:48 -04:00
Jan Kassens 3b6826ed9e Flow: inference_mode=constrain_writes
This mode is going to be the new default in Flow going forward.
There was an unfortuante large number of suppressions in this update.

More on the changes can be found in this [Flow blog post](https://medium.com/flow-type/new-flow-language-rule-constrained-writes-4c70e375d190).

Added some of the required annotations using the provided codemod:

```sh
node_modules/.bin/flow codemod annotate-declarations --write .
```

ghstack-source-id: 0b168e1b23
Pull Request resolved: https://github.com/facebook/react/pull/25422
2022-10-04 15:49:48 -04:00
Jan Kassens aed33a49cc Flow upgrade to 0.185
ghstack-source-id: 8104710c96
Pull Request resolved: https://github.com/facebook/react/pull/25420
2022-10-04 13:50:59 -04:00
Jan Kassens f02a5f5c79 Flow upgrade to 0.182
ghstack-source-id: b9bb8c1560
Pull Request resolved: https://github.com/facebook/react/pull/25419
2022-10-04 13:37:58 -04:00
Jan Kassens 72593f008e Flow upgrade to 0.176
This upgrade deprecated calling `new` on functions which introduced
the majority of breakages and I suppressed those.

ghstack-source-id: 545363f3c5
Pull Request resolved: https://github.com/facebook/react/pull/25418
2022-10-04 13:37:58 -04:00
Jan Kassens 46d40f306a Flow upgrade to 0.175
ghstack-source-id: 99008118ef
Pull Request resolved: https://github.com/facebook/react/pull/25417
2022-10-04 13:37:58 -04:00
Jan Kassens 1089faf0d8 Flow: run codemod to remove existential type
The existential type `*` was deprecated and a codemod provided to replace it. Ran that and did some manual fixups:

```sh
node_modules/.bin/flow codemod replace-existentials --write .
```

ghstack-source-id: 4c98b8db6a
Pull Request resolved: https://github.com/facebook/react/pull/25416
2022-10-04 13:37:58 -04:00
Lauren Tan 3fd9bd8e74 Add RulesOfHooks support for `use`
Usage of the new `use` hook needs to conform to the rules of hooks, with
the one exception that it can be called conditionally.

ghstack-source-id: 7ea5beceaf
Pull Request resolved: https://github.com/facebook/react/pull/25370
2022-10-04 12:41:29 -04:00
Jan Kassens 338e6a967c Flow upgrade to 0.155
This version banned use of this in object functions.

ghstack-source-id: f49fd5e1b7
Pull Request resolved: https://github.com/facebook/react/pull/25414
2022-10-04 11:49:15 -04:00
Jan Kassens 8bc95bb3c8 Flow upgrade to 0.154
ghstack-source-id: d84024950a
Pull Request resolved: https://github.com/facebook/react/pull/25413
2022-10-04 11:49:14 -04:00
Jan Kassens 9f8a98a390 Flow upgrade to 0.153
- method unbinding is no longer supported in Flow for soundness, this added a bunch of suppressions
- Flow now prevents objects to be supertypes of interfaces/classes

ghstack-source-id: d7749cbad8
Pull Request resolved: https://github.com/facebook/react/pull/25412
2022-10-04 11:30:06 -04:00
Jan Kassens adb58f529d Flow upgrade to 0.152
- 0.147 removes access to Object.prototype via the global object.
- 0.149 removed deprecated config options

ghstack-source-id: c77f9b3739
Pull Request resolved: https://github.com/facebook/react/pull/25411
2022-10-04 11:30:06 -04:00
Jan Kassens 64fe791be8 Flow upgrade to 0.146
This upgrade made more expressions invalidate refinements. In some
places this lead to a large number of suppressions that I automatically
suppressed and should be followed up on when the code is touched.
I think most of them might require either manual annotations or moving
a value into a const to allow refinement.

ghstack-source-id: a45b40abf0
Pull Request resolved: https://github.com/facebook/react/pull/25410
2022-10-04 11:01:50 -04:00
Jan Kassens d3c6c16a03 Flow upgrade to 0.145
Fixed a RN library definition that defined `CustomEvent` as a reference to itself.

ghstack-source-id: 90da2e316f
Pull Request resolved: https://github.com/facebook/react/pull/25409
2022-10-04 11:01:50 -04:00
Jan Kassens 00a2f81508 Flow upgrade to 0.143
This was a large upgrade that removed "classic mode" and made "types first" the only option.
Most of the needed changes have been done in previous PRs, this just fixes up the last few instances.

ghstack-source-id: 9612d95ba4
Pull Request resolved: https://github.com/facebook/react/pull/25408
2022-10-04 11:01:50 -04:00
Jan Kassens 0a3072278e
Flow: complete types first migration (#25389)
This complete the "types first" migration and enables the config everywhere.
2022-10-03 21:59:33 -04:00
Jan Kassens bcc05671fc
Flow: types first in shared (#25343) 2022-10-03 20:57:34 -04:00
Jan Kassens b1f34aa307
Flow: types first in react-native-renderer (#25363) 2022-10-03 17:03:33 -04:00
Jan Kassens 9143864ae1
Flow: well formed exports for smaller packages (#25361)
Enforces well formed exports for packages where the fixes are small.
2022-10-03 16:52:41 -04:00
Alexandru Tasica 21a851e035 Fix devtools typos and grammar (#24587)
Closes #24587
2022-10-03 10:11:40 -04:00
Kerim Büyükakyüz cfafeb6858
Remove extra space in Wedge.js (#24611) 2022-10-03 10:03:56 -04:00
Jan Kassens 9c3de25e1c
Flow: types first in reconciler (#25362)
This contains one code change, renaming the local function `ChildReconciler` to `createChildReconciler` as it's called as a function, not a constructor and to free up the name for the return value.
2022-10-01 18:47:32 -04:00
Sebastian Silbermann 0033d1a98c
Fix failing tests in latest 16.x and 18.x Node versions (#25378) 2022-10-01 17:12:28 -04:00
Josh Story 7b25b961df
[Fizz/Float] Float for stylesheet resources (#25243)
* [Fizz/Float] Float for stylesheet resources

This commit implements Float in Fizz and on the Client. The initial set of supported APIs is roughly

1. Convert certain stylesheets into style Resources when opting in with precedence prop
2. Emit preloads for stylesheets and explicit preload tags
3. Dedupe all Resources by href
4. Implement ReactDOM.preload() to allow for imperative preloading
5. Implement ReactDOM.preinit() to allow for imperative preinitialization

Currently supports
1. style Resources (link rel "stylesheet")
2. font Resources (preload as "font")

later updates will include support for scripts and modules
2022-09-30 16:14:04 -07:00
zhangrenyang 4c016e7aaf
Refactor: use property shorthand (#25366) 2022-09-30 17:50:08 -04:00
Lauren Tan 06066c1a5a Make RulesOfHooks-test more consistent with ExhaustiveDeps-test
Small formatting changes to make the tests consistent.

ghstack-source-id: 7013a37f1f
Pull Request resolved: https://github.com/facebook/react/pull/25369
2022-09-30 15:16:22 -04:00
Lauren Tan 49ae0fad84 Fix RulesOfHooks test case indentation
Just a small formatting fix.

ghstack-source-id: c71ff02ed9
Pull Request resolved: https://github.com/facebook/react/pull/25368
2022-09-30 15:16:22 -04:00
Samuel Susla abbbdf4cec
Put modern StrictMode behind a feature flag (#25365)
* Put modern StrictMode behind a feature flag

* Remove unneeded flag
2022-09-30 17:06:11 +01:00
Igor Berlenko 434110390a
ReactHooks.js - delete emptyObject (#25031)
It's not mentioned in docs and never used by projects.. should be removed..
2022-09-30 11:29:51 -04:00
jerry-lllman 31400ce293
Refactor: merge duplicate imports (#25364) 2022-09-30 09:57:50 -04:00
Lauren Tan 3517bd9f77
Refactor useEvent (#25336)
* Refactor useEvent

Previously, the useEvent implementation made use of effect infra under
the hood. This was a lot of extra overhead for functionality we didn't
use (events have no deps, and no clean up functions). This PR refactors
the implementation to instead use a queue to ensure that the callback is
stable across renders.

Additionally, the function signature was updated to infer the callback's argument types and return value. While this doesn't affect anything internal it more accurately describes what's being passed.
2022-09-29 13:45:27 -07:00
Sreecharan 8ee4f52989
Fix: Documentation typos (#24471)
* fix: typo

Co-authored-by: Jan Kassens <jkassens@meta.com>
2022-09-29 12:46:53 -04:00
zhangenming 6cf06a9297
Remove outdated comments. (#24464)
fixed by https://github.com/facebook/react/pull/20894
2022-09-29 12:40:42 -04:00
Vic Graf 20a257c259
Refactor: more word doubles removed (#25352) 2022-09-29 09:57:49 -04:00
zhangrenyang 8cadcffd5d
Fix typo: reconcilation -> reconciliation (#25355) 2022-09-29 09:34:30 -04:00
Sebastian Markbåge 97d75c9c8b
Move react-dom implementation files to react-dom-bindings (#25345)
This lets us share it with react-server-dom-webpack while still having a
dependency on react-dom. It also makes somewhat sense from a bundling
perspective since react-dom is an external to itself.
2022-09-28 19:05:50 -04:00
dan 3de9264496
[Fizz] experimental_useEvent (#25325)
* [Fizz] useEvent

* Use same message on client and server
2022-09-27 20:42:16 +01:00
Vic Graf 5b59dd6400
Fix duplicate words tests (#25333)
* refactor: removed duplicated words in comments
* refactor: removed duplicate words in tests
2022-09-27 10:07:06 -04:00
Lauren Tan cb5084d1c4
[ESLint] Check useEvent references instead (#25319)
* [ESLint] Check useEvent references instead

Previously the useEvent check in RulesOfHooks would collect all
definitions of useEvent functions at the top level, record them as
violations, then clear those violations if the useEvent function was
later called or referened inside of an effect or another event.

The flaw with this approach was in the special case where useEvent
functions could be passed by reference inside of effects or events. The
violation would be cleared here (since it was called at least once)
and subsequent usages of the useEvent function would not be properly
checked.

This PR changes it so we check all identifiers that resolve to a
useEvent function, and if they are not in an effect or event must be
called or a lint error is emitted.

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>

* Add comment

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
2022-09-24 01:34:17 +01:00
Lauren Tan c89a83695c
Update RulesOfHooks with useEvent rules (#25285)
This update to the RulesOfHooks rule checks that functions created with
`useEvent` can only be invoked in a `useEffect` callback, in another
event function, or a closure.
They can't be passed down directly as a reference to child components.

This PR also updates the ExhaustiveDeps lint rule to treat useEvent's 
return value as stable, so it can be omitted from dependency lists.

Currently this all gated behind an experimental flag.

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
2022-09-23 14:55:12 -07:00
Josh Story efc6a08e98
[Flight] Implement error digests for Flight runtime and expose errorInfo in getDerivedStateFromError (#25302)
Similar to Fizz, Flight now supports a return value from the user provided onError option. If a value is returned from onError it will be serialized and provided to the client.

The digest is stashed on the constructed Error on the client as .digest
2022-09-23 13:19:29 -07:00
Samuel Susla c1d414d758
Add ref to Offscreen component (#25254)
* Expose ref to Offscreen if mode is manual

* Prepend private fields on OffscreenInstance with underscore

* Schedule Ref effect unconditionally on Offscreen

* Make sure Offscreen's ref is detached when unmounted

* Make sure ref is mounted/unmounted in all scenarious

* Nit: pendingProps -> memoizedProps

Co-authored-by: Andrew Clark <git@andrewclark.io>
2022-09-23 11:31:34 -04:00
Jan Kassens 135e33c954
Flow: typing of Scheduler (#25317)
Enables well formed exports for /scheduler. Some of the modules there were missing `@flow` and were therefore completely unchecked (despite some spurious types sprinkled around).
2022-09-23 10:28:34 -04:00
Jan Kassens cc8cb145f0
Flow: add some missing types in react-reconciler (#25316)
To enable the next Flow version, we need to annotate exported values. This adds a few automatically inferred types that didn't look huge or just `any`.
2022-09-23 10:28:00 -04:00
Josh Story 112d0498c8
[Fizz] Move digest from errorInfo to Error instance (#25313)
* suspense boundary error digest to Error instance and deprecate digest from errorInfo for onRecoverableError

* fix closure escape
2022-09-22 12:40:30 -07:00
Andrew Clark d1bb1c5861
Fix memory leak after repeated setState bailouts (#25309)
There's a global queue (`concurrentQueues` in the
ReactFiberConcurrentUpdates module) that is cleared at the beginning of
each render phase.

However, in the case of an eager `setState` bailout where the state is
updated to same value as the current one, we add the update to the queue
without scheduling a render. So the render phase never removes it from
the queue. This can lead to a memory leak if it happens repeatedly
without any other updates.

There's only one place where this ever happens, so the fix was pretty
straightforward.

Currently there's no great way to test this from a Jest test, so I
confirmed locally by checking in an existing test whether the array gets
reset. @sompylasar had an interesting suggestion for how to catch these
in the future: in the development build (perhaps behind a flag), use a
Babel plugin to instrument all module-level variables. Then periodically
sweep to confirm if something has leaked. The logic is that if there's
no React work scheduled, and a module-level variable points to an
object, it very likely indicates a memory leak.
2022-09-22 11:19:54 -04:00