Commit Graph

15470 Commits

Author SHA1 Message Date
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
Samuel Susla 0cac4d54c3
Double invoked effects on suspended children (#25307)
Co-authored-by: Robert Balicki <robertbalicki@fb.com>
2022-09-21 16:58:04 +01:00
Brandon Chan b2748907c3
Updated the URL link for serve (#25296) 2022-09-19 13:13:38 -04:00
Victoria Graf 3d615fc14a
Grammar. Removed doubles of the word "the". (#25295) 2022-09-19 10:04:03 -04:00
Tianyu Yao e099e1dc0e
React DevTools 4.25.0 -> 4.26.0 (#25283) 2022-09-16 12:35:00 -07:00
Tianyu Yao 6e3bc8a2e8
[DevTools] Check if Proxy exists before creating DispatcherProxy (#25278) 2022-09-16 11:24:03 -07:00
Tianyu Yao 8951c5fc9d
[DevTools][BE] Read username using gh in release script (#25270)
* [DevTools][BE] Read username using gh in release script

* better regex & fix lint
2022-09-15 18:12:46 -07:00
Josh Story e7fc04b297
[react-dom] Reorganize react-dom internals to match react (#25277)
* reorganize react-dom internals to match react

* refactor and make forks work for flow and internal imports

* flew too close to the sun

* typo
2022-09-15 15:31:31 -07:00
Jan Kassens fc16293f3f
Flow: well_formed_exports for devtools (#25266) 2022-09-15 16:45:29 -04:00
Sebastian Markbåge 0b54e00475
Handle rejections to avoid uncaught rejections (#25272) 2022-09-14 23:22:27 -04:00
Sebastian Markbåge c5d06fdc5d
[Flight] Fix Webpack Chunk Loading (#25271)
* Fix acorn import

I'm not sure how this ever worked.

* Fix cache to wait for entries already added to the chunk cache

* Modernize API
2022-09-14 22:57:35 -04:00
Sebastian Markbåge 975b644643
[Flight] response.readRoot() -> use(response) (#25267)
* [Flight] Move from suspensey readRoot() to use(thenable)

* Update noop tests

These are no longer sync so they need some more significant updating.

Some of these tests are written in a non-idiomatic form too which is not
great.

* Update Relay tests

I kept these as sync for now and just assume a sync Promise.

* Updated the main tests

* Gate tests

* We need to cast through any because Thenable doesn't support unknown strings
2022-09-14 20:20:33 -04:00
Sebastian Markbåge 60fbb7b143
[Flight] Implement FlightClient in terms of Thenable/Promises instead of throwing Promises (#25260)
* [Flight] Align Chunks with Thenable used with experimental_use

Use the field names used by the Thenable data structure passed to use().
These are considered public in this model.

This adds another field since we use a separate field name for "reason".

* Implement Thenable Protocol on Chunks

This doesn't just ping but resolves/rejects with the value.

* Subclass Promises

* Pass key through JSON parsing

* Wait for preloadModules before resolving module chunks

* Initialize lazy resolved values before reading the result

* Block a model from initializing if its direct dependencies are pending

If a module is blocked, then we can't complete initializing a model.
However, we can still let it parse, and then fill in the missing pieces
later.

We need to block it from resolving until all dependencies have filled in
which we can do with a ref count.

* Treat blocked modules or models as a special status

We currently loop over all chunks at the end to error them if they're
still pending. We shouldn't do this if they're pending because they're
blocked on an external resource like a module because the module might not
resolve before the Flight connection closes and that's not an error.

In an alternative solution I had a set that tracked pending chunks and
removed one at a time. While the loop at the end is faster it's more
work as we go.

I figured the extra status might also help debugging.

For modules we can probably assume no forward references, and the first
async module we can just use the promise as the chunk.

So we could probably get away with this only on models that are blocked by
modules.
2022-09-14 20:13:33 -04:00
Lauren Tan c91a1e03be
experimental_useEvent (#25229)
This commit adds a new hook `useEvent` per the RFC [here](https://github.com/reactjs/rfcs/pull/220), gated as experimental. 

Co-authored-by: Rick Hanlon <rickhanlonii@gmail.com>
Co-authored-by: Rick Hanlon <rickhanlonii@fb.com>
Co-authored-by: Lauren Tan <poteto@users.noreply.github.com>
2022-09-14 11:39:06 -07:00
Srikanth Kolli 2248dccfb3
[DevTools] Show DevTools icons in Edge browser panel (#25257)
Show DevTools icons in Edge browser panel
2022-09-14 13:50:57 -04:00
Jan Kassens c327b91d22
CI: try to make caching more reliable (#25259)
- `~/.yarn/cache` is now restored from an hierarchical cache key, if no precise match is found, we fallback to less precise ones. 
- The yarn install in `fixtures/dom` is also cached. Notably, is utilizes the cache from root, but stores into its more precise key.
- Steps running in root no longer have a `yarn install` and rely on the cache from the setup step.
- Retry `yarn install` once on failure.
2022-09-14 13:22:20 -04:00
Jan Kassens afe664d9d7
Flow: upgrade to 0.142 (#25255) 2022-09-13 18:39:26 -04:00
Jan Kassens 346c7d4c43
straightford explicit types (#25253) 2022-09-13 17:57:38 -04:00
Jan Kassens aca7f30c95
CI: extract node_modules cache key computation (#25258) 2022-09-13 17:54:00 -04:00
Joseph Savona 3401e9200e
useMemoCache implementation (#25143)
* useMemoCache impl
* test for multiple calls in a component (from custom hook)
* Use array of arrays for multiple calls; use alternate/local as the backup
* code cleanup
* fix internal test
* oops we do not support nullable property access
* Simplify implementation, still have questions on some of the PR feedback though
* Gate all code based on the feature flag
* refactor to use updateQueue
* address feedback
* Try to eliminate size increase in prod bundle
* update to retrigger ci
2022-09-13 14:44:32 -07:00
Luna Ruan 0556bab32c
[Transition Tracing] More Accurate End Time (#25105)
add more accurate end time for transitions and update host configs with `requestPostPaintCallback` function and move post paint logic to another module and use it in the work loop
2022-09-13 10:55:56 -07:00
Jan Kassens 5fdcd23aaa
Flow: upgrade to 0.140 (#25252)
This update range includes:

- `types_first` ([blog](https://flow.org/en/docs/lang/types-first/), all exports need annotated types) is default. I disabled this for now to make that change incremental.
- Generics that escape the scope they are defined in are an error. I fixed some with explicit type annotations and some are suppressed that I didn't easily figure out.
2022-09-13 13:33:43 -04:00
Jan Kassens e6a062bd2a
Flow: add simple explicit export types to Devtools (#25251) 2022-09-13 12:03:20 -04:00
Robert Balicki 271bf90a94
[react devtools][easy] Centralize calls to patchConsoleUsingWindowValues (#25222)
* Instead of reading from window in two separate places, do this in a single function
* Add some type safety
2022-09-13 11:24:10 -04:00
Sebastian Markbåge 5c43c6f026
Unwind the current workInProgress if it's suspended (#25247)
Usually we complete workInProgress before yielding but if that's the
currently suspended one, we don't yet complete it in case we can
immediately unblock it.

If we get interrupted, however, we must unwind it. Where as we usually
assume that we've already completed it.

This shows up when the current work in progress was a Context that pushed
and then it suspends in its immediate children. If we don't unwind,
it won't pop and so we get an imbalance.
2022-09-13 11:18:57 -04:00
Samuel Susla e52fa4c575
Add early exit to strict mode (#25235) 2022-09-13 12:08:51 +01:00
Akul Srivastava f2e4ff082d
fix: prettier ignore removed and fixed (#24811) 2022-09-12 21:16:29 -04:00
Jan Kassens 6aa38e74c7
Flow: enable unsafe-addition error (#25242) 2022-09-12 16:22:50 -04:00
Jan Kassens ba7b6f4183
Flow: upgrade to 0.132 (#25244) 2022-09-12 14:36:02 -04:00
Jan Kassens 9328988c02
Flow: fix Fiber typed as any (#25241) 2022-09-12 13:44:58 -04:00
Jan Kassens c739cef2fc
Flow: ReactFiberHotReloading recursive type (#25225) 2022-09-12 10:25:01 -04:00
Sebastian Markbåge c156ecd483
Add some test coverage for some error cases (#25240) 2022-09-11 21:53:00 -04:00
mofeiZ 3613284dce
experimental_use(context) for server components and ssr (#25226)
implements the experimental use(context) API for the server components (Flight) and SSR (Fizz) runtimes
2022-09-09 21:19:28 -04:00
Jan Kassens d5ddc6543e
Flow: upgrade to 0.131 (#25224)
This also downgrades the new lint warning to avoid new suppressions with this upgrade.
2022-09-09 16:21:32 -04:00
Samuel Susla 269c4e975f
Prevent infinite re-renders in StrictMode + Offscreen (#25203)
* Prevent infinite re-render in StrictMode + Offscreen

* Only fire effects for Offscreen when it is revealed

* Move setting debug fiber into if branch

* Move settings of debug fiber out of if branch
2022-09-09 21:10:26 +01:00
Jan Kassens 8003ab9cf5
Flow: remove explicit object syntax (#25223) 2022-09-09 16:03:48 -04:00
Jan Kassens 492c6e29e7
Flow: upgrade to 0.127 (#25221)
A smaller incremental update as some next version was changing more.
2022-09-09 12:21:44 -04:00
Jan Kassens bbd56b278c
Flow: enable exact_by_default (#25220)
With this change, a simple object type `{ }` means an exact object `{| |}` which most people assume.
Opting for inexact requires the extra `{ a: number, ... }` syntax at the end.

A followup, someone could replace all the `{| |}` with `{ }`.
2022-09-09 12:16:40 -04:00
Robert Balicki 425f9fbba0
[react devtools] Don't check for NODE_ENV==='test' because it never is (#25186)
* remove useless condition
2022-09-09 11:31:32 -04:00
Robert Balicki 540ba5b403
[react devtools][easy] Change variable names, etc. (#25211)
* Change variable names, put stuff in constants, etc. in preparation for next diff
2022-09-09 11:09:30 -04:00
dependabot[bot] b0593dd964
Bump async from 2.6.3 to 2.6.4 in /fixtures/concurrent/time-slicing (#24443)
Bumps [async](https://github.com/caolan/async) from 2.6.3 to 2.6.4.
- [Release notes](https://github.com/caolan/async/releases)
- [Changelog](https://github.com/caolan/async/blob/v2.6.4/CHANGELOG.md)
- [Commits](https://github.com/caolan/async/compare/v2.6.3...v2.6.4)

---
updated-dependencies:
- dependency-name: async
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-09-09 10:56:21 -04:00
Jan Kassens 8a9e7b6cef
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
Sebastian Markbåge 37cc6bf124
Remove useDeferredValue and useTransition from Flight subset (#25215) 2022-09-09 09:32:40 -04:00
Andrew Clark c28f313e6d
experimental_use(promise) for SSR (#25214)
Follow up to #25084 and #25207. Implements experimental_use(promise) API
in the SSR runtime (Fizz).

This is largely a copy-paste of the Flight implementation. I have
intentionally tried to keep both as close as possible.
2022-09-08 21:47:33 -04:00