Commit Graph

16242 Commits

Author SHA1 Message Date
StyleShit a1433ca0ba fix(eslint-plugin-react-hooks): accepting as expressions as deps array (#28189)
## Summary

This PR closes #25844
The original issue talks about `as const`, but seems like it fails for
any `as X` expressions since it adds another nesting level to the AST.

EDIT: Also closes #20162

## How did you test this change?

Added unit tests
2024-02-01 20:30:17 +01:00
Andrew Clark 53b12e46a1 Add stable React.act export (#28160)
Starting in version 19, users can import the `act` testing API from the
`react` package instead of using a renderer specific API, like
`react-dom/test-utils`.
2024-02-01 13:28:14 -05:00
Jan Kassens 4384a7bcd3 [flow] ignore hidden directories (#28096)
[flow] ignore hidden directories
2024-02-01 11:24:04 -05:00
Josh Story 1219d57fc9 [Fizz] Support aborting with Postpone (#28183)
Semantically if you make your reason for aborting a Postpone instance
the render should not hit the error pathways but should instead follow
the postpone pathways. It's awkward today to actually get your hands on
a Postpone instance because you have to catch the throw from postpone
and then pass that into `abort()` or `AbortController.abort()`
(depending on the renderer API you are using)

This change makes it so that in most circumstances if you abort with a
postpone the `onPostpone` handler will be called and the Suspense
boundaries still pending will be put into client render mode with the
appropriate postpone digest to avoid trigger recoverable error pathways
on the client.

Similar to postponing in the shell during a resume or render however if
you abort before the shell is complete in a resume or render we will
fatally error. The fatal error is contextualized by React to avoid
passing the postpone object itself to the `onError` and related options.
2024-02-01 07:14:08 -08:00
Sebastian Silbermann d29f7d973d Enable enableFilterEmptyStringAttributesDOM everywhere (#28125)
## Summary

Stacked on [#28124](https://github.com/facebook/react/pull/28124) ([Diff
against
#28124](https://github.com/facebook/react/compare/eps1lon:fix/anchor-href-empty...eps1lon:feat/enableFilterEmptyStringAttributesDOM-canary))

Enables `enableFilterEmptyStringAttributesDOM` everywhere. I don't think
this needs to be enabled behind `__VARIANT__` for RN since this flag is
only used in DOM.

## How did you test this change?

- CI
2024-01-31 08:23:21 -08:00
Ruslan Lesiutin f7ce4164c9 chore: remove eslint-plugin-flowtype from dev dependencies (#28157)
While trying to resolve some issues with Flow in ESLint, noticed that we
are still listing `eslint-plugin-flowtype` as dev dependency, but it has
been deprecated in favour of `eslint-plugin-ft-flow`.
2024-01-31 14:52:52 +00:00
Ricky 45582c6c4d Add script to output flag values (#28115)
## Overview

Depends on: https://github.com/facebook/react/pull/28116

Add `yarn flags` to output at table of all feature flags. 

Provides options to output a csv file, diff two or more builds, and
sort.

### Options
<img width="1154" alt="Screenshot 2024-01-26 at 4 06 53 PM"
src="https://github.com/facebook/react/assets/2440089/c3dbd632-adb9-4416-9488-1c603ee4e789">

### `yarn flags --diff next canary`
<img width="637" alt="Screenshot 2024-01-26 at 4 15 03 PM"
src="https://github.com/facebook/react/assets/2440089/1a681ae8-ce33-42d0-9d1f-3f415a8e1c3d">


### `yarn flags --diff canary experimental`
<img width="637" alt="Screenshot 2024-01-26 at 4 14 51 PM"
src="https://github.com/facebook/react/assets/2440089/c66f66cb-3cee-4df6-a1d1-b24600ebd4b3">


### `yarn flags` (all flags)

<img width="1054" alt="Screenshot 2024-01-26 at 4 16 30 PM"
src="https://github.com/facebook/react/assets/2440089/4ce99c7c-825e-4bca-9b83-ca5d6e2bc1a9">
2024-01-30 23:15:50 -05:00
Sebastian Silbermann f3ce87ab65 Restore old behavior for empty href props on anchor tags (#28124)
Treat `<a href="" />` the same with and without
`enableFilterEmptyStringAttributesDOM`

in https://github.com/facebook/react/pull/18513 we started to warn and
ignore for empty `href` and `src` props since it usually hinted at a
mistake. However, for anchor tags there's a valid use case since `<a
href=""></a>` will by spec render a link to the current page. It could
be used to reload the page without having to rely on browser
affordances.

The implementation for Fizz is in the spirit of
https://github.com/facebook/react/pull/21153. I gated the fork behind
the flag so that the fork is DCE'd when the flag is off.
2024-01-31 00:43:40 +01:00
Sebastian Silbermann af7e8c7a71 Convert trustedTypes to createRoot (#28163) 2024-01-30 22:22:33 +01:00
Sebastian Silbermann 13aae52aea Convert SimpleEventPlugin to createRoot (#28164) 2024-01-30 22:22:02 +01:00
Ricky 417188314d Update www flags (#28150)
Adds an experiment for `enableFormActions` and hardcodes
`enableCustomElementPropertySupport` on www since this is shipped.
2024-01-30 14:24:41 -05:00
Andrew Clark 178f435194 Always warn if client component suspends with an uncached promise (#28159)
Previously we only warned during a synchronous update, because we
eventually want to support async client components in controlled
scenarios, like during navigations. However, we're going to warn in all
cases for now until we figure out how that should work.
2024-01-30 14:23:39 -05:00
Josh Story 554fc49f41 [Fizz] improve Hoistable handling for Elements and Resources inside Suspense Boundaries (#28069)
Updates Fizz to handle Hoistables (Resources and Elements) in a way that
better aligns with Suspense fallbacks

1. Hoistable Elements inside a fallback (regardless of how deep and how
many additional boundaries are intermediate) will be ignored. The
reasoning is fallbacks are transient and since there is not good way to
clean up hoistables because they escape their Suspense container its
better to not emit them in the first place. SSR fallbacks are already
not full fidelity because they never hydrate so this aligns with that
somewhat.
2. Hoistable stylesheets in fallbacks will only block the reveal of a
parent suspense boundary if the fallback is going to flush with that
completed parent suspense boundary. Previously if you rendered a
stylesheet Resource inside a fallback any parent suspense boundaries
that completed after the shell flushed would include that resource in
the set required to resolve before the boundary reveal happens on the
client. This is not a semantic change, just a performance optimization
3. preconnect and preload hoistable queues are gone, if you want to
optimize resource loading you shoudl use `ReactDOM.preconnect` and
`ReactDOM.preload`. `viewport` meta tags get their own queue because
they need to go before any preloads since they affect the media state.

In addition to those functional changes this PR also refactors the
boundary resource tracking by moving it to the task rather than using
function calls at the start of each render and flush. Tasks also now
track whether they are a fallback task

supercedes prior work here: https://github.com/facebook/react/pull/27534
2024-01-30 10:14:59 -08:00
Josh Story 1c958aa4ab [Fiber] Use a safer strategy to track the last precedence (#28110)
Uses a safer strategy to track the last precedence to avoid the need to
consistently remember to preprend `'p'` to the precedence value
2024-01-30 10:10:19 -08:00
Sebastian Silbermann 2477384650 Complete DOMPluginEventSystem migration to createRoot (#28148)
Follow-up to
https://github.com/facebook/react/pull/28139#discussion_r1468852457

I mistakenly kept the tests using comment nodes as containers as legacy
tests. It's not that comments nodes aren't allowed in createRoot
entirely. Only behind `disableCommentsAsDOMContainers`. We already had
one test following that pattern so I just applied the same pattern to
the other tests for consistency.

Now `DOMPluginEventSystem` no longer uses any legacy roots.
2024-01-30 09:11:58 +01:00
Ricky 4d6c47baa3 Clean up experimental flags (#28116)
## Overview

Adds a new global to disambiguate experimental flags that we intend to
land when we can make breaking changes.
2024-01-29 14:03:39 -05:00
Ricky 4c73da8cbd Convert ReactCompositeComponent to createRoot (#28099)
Moves tests depending on legacy APIs to `ReactLegacyCompositeComponents`
and updates the rest.
2024-01-29 14:03:16 -05:00
Ricky 61df8caa3b Remove duplicate dynamic scheduler flags (#28100)
These were made dynamic again in
https://github.com/facebook/react/pull/27919, and already have the
dynamic flags set. It's a bummer to push this around, we should come up
with a better way.
2024-01-29 13:39:39 -05:00
Ricky cc7d421629 Add lint tests that should fail (#28147)
These though fail.

Anon default export: https://github.com/facebook/react/issues/21181
Promise callbacks: https://github.com/facebook/react/issues/26186
Returning anon functions: https://github.com/facebook/react/issues/22520
2024-01-29 12:54:32 -05:00
Sebastian Silbermann 971b62f479 Convert useFocusWithin to createRoot (#28128) 2024-01-29 17:02:49 +01:00
Sebastian Silbermann cdfaae73c4 Convert ReactDOMTextarea to createRoot (#28126)
Also removes usage of `ReactTestUtils`
2024-01-29 17:02:20 +01:00
Sebastian Silbermann 00d42ac354 Convert DOMPluginEventSystem to createRoot (#28139) 2024-01-29 09:12:20 +01:00
Sebastian Silbermann 6d2a1d0334 Convert ReactMultiChildText to createRoot (#28140) 2024-01-29 09:11:24 +01:00
Sebastian Silbermann 313e4d4129 Convert ReactDOMTextComponent to createRoot (#28141) 2024-01-29 09:11:02 +01:00
Sebastian Silbermann 1c8901f750 Convert ReactDOMSelect to createRoot (#28142) 2024-01-29 09:10:34 +01:00
Sebastian Silbermann 7aa45db6a2 Convert refs to createRoot (#28113) 2024-01-28 10:41:47 +01:00
Sebastian Silbermann 3e58b0af0c Convert ReactDOMInvalidARIAHook to createRoot (#28129) 2024-01-27 16:08:01 -05:00
Matt Carroll e2b93afc60 Convert renderSubtreeIntoContainer-test.js to createRoot (#28114)
Co-authored-by: Ricky <rickhanlonii@gmail.com>
2024-01-26 19:30:02 -05:00
Jack Pope 407faf5a69 Remove ReactDOM.render tests in ReactDOMConsoleErrorReporting-test (#28053)
Each it block here was duplicated to cover ReactDOM.render and
ReactDOMClient.createRoot. Here we delete the ReactDOM.render coverage.

Co-authored-by: Jack Pope <jackpope@meta.com>
2024-01-26 19:29:45 -05:00
Jack Pope 91212b09ed Clean up legacy render from ReactTestUtilsAct-test (#28091)
Co-authored-by: Jack Pope <jackpope@meta.com>
2024-01-26 19:29:25 -05:00
Jack Pope 54f2314e9c Use createRoot in ReactMockedComponent-test (#28087)
Co-authored-by: Jack Pope <jackpope@meta.com>
2024-01-26 17:28:58 -05:00
Jack Pope 4c41c09ccc Use createRoot in ReactDOMComponentTree-test (#28112) 2024-01-26 17:18:03 -05:00
Jack Pope 38997cf19a Use createRoot in ReactTestUtilsActUnmockedScheduler-test (#28086) 2024-01-26 17:17:34 -05:00
Ricky 766eac46bb Remove outdated enableSchedulerDebugging flag (#28101)
This flag was moved to the scheduler feature flags, so these flags don't
do anything.
2024-01-26 16:53:01 -05:00
Matt Carroll 37bdff675c Convert ReactIdentity-test.js to createRoot (#28106) 2024-01-26 13:18:48 -08:00
Matt Carroll 759811b062 Convert ReactMultiChild-test.js to createRoot (#28117) 2024-01-26 13:18:19 -08:00
Matt Carroll 8f998bf93f Convert SyntheticEvent-test.js to createRoot (#28118) 2024-01-26 13:17:44 -08:00
Matt Carroll 7c79dafb71 Convert ReactDOMServerIntegrationUntrustedURL-test.js to createRoot (#28105) 2024-01-26 12:18:14 -08:00
Sebastian Silbermann 9aef5d225b Use modern rendering APIs for attribute-behavior fixture (#27883)
The attribute-behavior fixture now uses `createRoot().render()` and
`renderToReadableStream` instead of depdrecated APIs.

This revealed some changes to the snapshots that I annotated for
discussion.

I also added some new tests related to upcoming changes for easier
future diffing.

Also adds support for running the attribute-behavior fixture using Apple
Silicon chips (Apple MBP M-series).
2024-01-26 19:03:42 +01:00
Andrew Clark 60f190a559 Capture React.startTransition errors and pass to reportError (#28111)
To make React.startTransition more consistent with the hook form of
startTransition, we capture errors thrown by the scope function and pass
them to the global reportError function. (This is also what we do as a
default for onRecoverableError.)

This is a breaking change because it means that errors inside of
startTransition will no longer bubble up to the caller. You can still
catch the error by putting a try/catch block inside of the scope
function itself.

We do the same for async actions to prevent "unhandled promise
rejection" warnings.

The motivation is to avoid a refactor hazard when changing from a sync
to an async action, or from useTransition to startTransition.
2024-01-26 12:10:33 -05:00
Jack Pope 51c380d6ed Use createRoot in ReactEmptyComponent-test (#28095) 2024-01-26 11:37:51 -05:00
Tobias Koppers 763612647c fix incorrect insertion order of stylesheets (#28108)
## Summary

In the precendences Map every key is prefixed with `p`. This fixes one
case where this is missing.

## How did you test this change?

<!--
Demonstrate the code is solid. Example: The exact commands you ran and
their output, screenshots / videos if the pull request changes the user
interface.
How exactly did you verify that your PR solves the issue you wanted to
solve?
  If you leave this empty, your PR will very likely be closed.
-->
2024-01-26 07:54:58 -08:00
Sebastian Silbermann 6c64428d90 Convert ChangeEventPlugin to createRoot (#28090) 2024-01-26 10:20:26 +01:00
Sebastian Silbermann 36baa43560 Convert ReactDOMAttribute to createRoot (#28089) 2024-01-26 10:17:26 +01:00
Sebastian Silbermann 0c45e83071 Convert SelectEventPlugin to createRoot (#28076) 2024-01-26 10:17:13 +01:00
Sebastian Silbermann b30ec67c43 Convert ReactDOMSVG to createRoot (#28074) 2024-01-26 10:17:09 +01:00
Matt Carroll fbb21066a2 Convert SyntheticWheelEvent-test.js to createRoot (#28103) 2024-01-26 03:05:08 -05:00
Ricky 9bad8ed9a6 Convert validateDOMNesting to createRoot (#28098)
ezpz
2024-01-25 22:30:56 -05:00
Andrew Clark 85b296e9b6 Async action support for React.startTransition (#28097)
This adds support for async actions to the "isomorphic" version of
startTransition (i.e. the one exported by the "react" package).
Previously, async actions were only supported by the startTransition
that is returned from the useTransition hook.

The interesting part about the isomorphic startTransition is that it's
not associated with any particular root. It must work with updates to
arbitrary roots, or even arbitrary React renderers in the same app. (For
example, both React DOM and React Three Fiber.)

The idea is that React.startTransition should behave as if every root
had an implicit useTransition hook, and you composed together all the
startTransitions provided by those hooks. Multiple updates to the same
root will be batched together. However, updates to one root will not be
batched with updates to other roots.

Features like useOptimistic work the same as with the hook version.

There is one difference from from the hook version of startTransition:
an error triggered inside an async action cannot be captured by an error
boundary, because it's not associated with any particular part of the
tree. You should handle errors the same way you would in a regular
event, e.g. with a global error event handler, or with a local
`try/catch`.
2024-01-25 21:54:45 -05:00
Sebastian Markbåge 382190c595 [Flight/Fizz] Reset ThenableState Only in Branches Where It's Added (#28068)
Before, we used to reset the thenable state and extract the previous
state very early so that it's only the retried task that can possibly
consume it. This is nice because we can't accidentally consume that
state for any other node.

However, it does add a lot of branches of code that has to pass this
around. It also adds extra bytes on the stack per node. Even though it's
mostly just null.

This changes it so that where ever we can create a thenable state (e.g.
entering a component with hooks) we first extract this from the task.
The principle is that whatever could've created the thenable state in
the first place, must always be rerendered so it'll take the same code
paths to get there and so we'll always consume it.
2024-01-25 19:52:00 -05:00