Commit Graph
1424 Commits
Author SHA1 Message Date
eps1lon 7b03e140c4 [Fizz] Skip past hidden inputs when attempting to hydrate hydration boundaries (#34302)
DiffTrain build for [4123f6b771](https://github.com/facebook/react/commit/4123f6b771bb71a2831b1c450c385c38530125a0)
2025-08-26 08:35:03 -07:00
josephsavona e0be527bfc [compiler] Script to produce markdown of lint rule docs (#34260)
The docs site is in a separate repo, but this gives us a semi-automated
way to update the docs about our lint rules. The script generates
markdown files from the rule definitions which we can then manually
copy/paste into the docs site somewhere. In the future we can automate
this fully.

DiffTrain build for [425ba0ad6d](https://github.com/facebook/react/commit/425ba0ad6d3ebd1779f6a658dcbf5c666d054948)
2025-08-22 10:06:12 -07:00
a2b19a6a0b Add support for ARIA 1.3 attributes (#34264)
Co-authored-by: Abdulwahab Omira <abdulwahabomira@gmail.com>
Co-authored-by: Sebastian Sebbie Silbermann <sebastian.silbermann@vercel.com>

DiffTrain build for [698bb4deb7](https://github.com/facebook/react/commit/698bb4deb7c77010c040ac49630c26db94e6e28c)
2025-08-22 07:30:07 -07:00
josephsavonaandMofei Zhang f7eb4653b7 [compiler] Aggregate error reporting, separate eslint rules (#34176)
NOTE: this is a merged version of @mofeiZ's original PR along with my
edits per offline discussion. The description is updated to reflect the
latest approach.

The key problem we're trying to solve with this PR is to allow
developers more control over the compiler's various validations. The
idea is to have a number of rules targeting a specific category of
issues, such as enforcing immutability of props/state/etc or disallowing
access to refs during render. We don't want to have to run the compiler
again for every single rule, though, so @mofeiZ added an LRU cache that
caches the full compilation output of N most recent files. The first
rule to run on a given file will cause it to get cached, and then
subsequent rules can pull from the cache, with each rule filtering down
to its specific category of errors.

For the categories, I went through and assigned a category roughly 1:1
to existing validations, and then used my judgement on some places that
felt distinct enough to warrant a separate error. Every error in the
compiler now has to supply both a severity (for legacy reasons) and a
category (for ESLint). Each category corresponds 1:1 to a ESLint rule
definition, so that the set of rules is automatically populated based on
the defined categories.

Categories include a flag for whether they should be in the recommended
set or not.

Note that as with the original version of this PR, only
eslint-plugin-react-compiler is changed. We still have to update the
main lint rule.

## Test Plan

* Created a sample project using ESLint v9 and verified that the plugin
can be configured correctly and detects errors
* Edited `fixtures/eslint-v9` and introduced errors, verified that the w
latest config changes in that fixture it correctly detects the errors
* In the sample project, confirmed that the LRU caching is correctly
caching compiler output, ie compiling files just once.

Co-authored-by: Mofei Zhang <feifei0@meta.com>

DiffTrain build for [7d29ecbeb2](https://github.com/facebook/react/commit/7d29ecbeb24327fdcd889fe184311bbeb0f04c30)
2025-08-21 15:03:15 -07:00
kassens a03985db6c Update Flow to 0.261 (#34255)
- 0.261 required to pull out a constant to preserve refinement
- 0.259 needed some updated suppressions for hacky stuff

DiffTrain build for [d73b6f1110](https://github.com/facebook/react/commit/d73b6f111057e09b9886e8edd2bc70fa56229489)
2025-08-21 12:12:59 -07:00
poteto 133db888c0 Add flow suppression for Constant Condition rollout (#34243)
DiffTrain build for [83c7379b96](https://github.com/facebook/react/commit/83c7379b9601f25463826449256f0cd3d283702d)
2025-08-20 15:31:40 -07:00
jackpope 34a9496a51 [eslint-plugin-react-hooks][RulesOfHooks] handle React.useEffect in addition to useEffect (#34076)
## Summary

This is a fix for https://github.com/facebook/react/issues/34074

## How did you test this change?

I added tests in the eslint package, and ran `yarn jest`. After adding
the new tests, I have this:

On main | On this branch
-|-
<img width="356" height="88" alt="image"
src="https://github.com/user-attachments/assets/4ae099a1-0156-4032-b2ca-635ebadcaa3f"
/> | <img width="435" height="120" alt="image"
src="https://github.com/user-attachments/assets/b06c04b8-6cec-43de-befa-a8b4dd20500e"
/>

## Changes

- Add tests to check that we are checking both `CallExpression`
(`useEffect(`), and `MemberExpression` (`React.useEffect(`). To do that,
I copied the `getNodeWithoutReactNamespace(` fn from `ExhaustiveDeps.ts`
to `RulesOfHooks.ts`

DiffTrain build for [87a45ae37f](https://github.com/facebook/react/commit/87a45ae37f4014b6df548a5d9b06bad5dc557992)
2025-08-18 06:21:23 -07:00
josephsavona dd5e4fd26c [compiler] Remove now-unused FunctionEffect type (#34029)
The new mutation/aliasing model significantly expands on the idea of
FunctionEffect. The type (and its usage in HIRFunction.effects) was only
necessary for the now-deleted old inference model so we can clean up
this code now.

DiffTrain build for [5063b3283f](https://github.com/facebook/react/commit/5063b3283fcae4bb43756d0d18d32008e3910bea)
2025-08-15 15:33:47 -07:00
josephsavona 2ea3843722 [compiler][wip] Remove old mutation/aliasing implementation (#34028)
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34028).
* #34029
* __->__ #34028

DiffTrain build for [eaf6adb127](https://github.com/facebook/react/commit/eaf6adb1277e4cb4f91d1b7f687f773657a5751b)
2025-08-15 15:27:27 -07:00
josephsavona 87b4e0d792 [compiler] Add support for diagnostic hints (#34126)
Hints are meant as additional information to present to the developer
about an error. The first use-case here is for the suggestion to name
refs with "-Ref" if we encounter a mutation that looks like it might be
a ref. The original error printing used a second error detail which
printed the source code twice, a hint with just extra text is less
noisy.

DiffTrain build for [6ffcac8558](https://github.com/facebook/react/commit/6ffcac8558efbd204c7df5d52787a90e507dd8d7)
2025-08-15 15:16:08 -07:00
josephsavona 8ef2e214bb [compiler] Add hint to name variables with "Ref" suffix (#34125)
If you have a ref that the compiler doesn't know is a ref (say, a value
returned from a custom hook) and try to assign its `.current = ...`, we
currently fail with a generic error that hook return values are not
mutable. However, an assignment to `.current` specifically is a very
strong hint that the value is likely to be a ref. So in this PR, we
track the reason for the mutation and if it ends up being an error, we
use it to show an additional hint to the user. See the fixture for an
example of the message.

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34125).
* #34126
* __->__ #34125
* #34124

DiffTrain build for [724b324b96](https://github.com/facebook/react/commit/724b324b966343f08ff0cb16ec9d8013e3891dfd)
2025-08-15 15:12:24 -07:00
jackpope 52f44c7f0f Add compareDocumentPosition to Fabric FragmentInstance (#34103)
Stacked on https://github.com/facebook/react/pull/34069

Same basic semantics as the react-dom for determining document position
of a Fragment compared to a given node. It's simpler here because we
don't have to deal with inserted nodes or portals. So we can skip a
bunch of the validation logic.

The logic for handling empty fragments is the same so I've split out
`compareDocumentPositionForEmptyFragment` into a shared module. There
doesn't seem to be a great place to put shared DOM logic between Fabric
and DOM configs at the moment. There may be more of this coming as we
add more and more DOM APIs to RN.

For testing I've written Fantom tests internally which pass the basic
cases on this build. The renderer we have configured for Fabric tests in
the repo doesn't support the Element APIs we need like
`compareDocumentPosition`.

DiffTrain build for [45a6532a08](https://github.com/facebook/react/commit/45a6532a088432010c40cbcac1fb6b6f8d56dd69)
2025-08-15 12:13:56 -07:00
jackpope f2a70d1c1b Fix fragmentInstance#compareDocumentPosition nesting and portal cases (#34069)
Found a couple of issues while integrating
FragmentInstance#compareDocumentPosition into Fabric.

1. Basic checks of nested host instances were inaccurate. For example,
checking the first child of the first child of the Fragment would not
return CONTAINED_BY.
2. Then fixing that logic exposed issues with Portals. The DOM
positioning relied on the assumption that the first and last top-level
children were in the same order as the Fiber tree. I added additional
checks against the parent's position in the DOM, and special cased a
portaled Fragment by getting its DOM parent from the child instance,
rather than taking the instance from the Fiber return. This should be
accurate in more cases. Though its still a guess and I'm not sure yet
I've covered every variation of this. Portals are hard to deal with and
we may end up having to push more results towards
IMPLEMENTATION_SPECIFIC if accuracy is an issue.

DiffTrain build for [a96a0f3903](https://github.com/facebook/react/commit/a96a0f3903ea0a9d45ff7c30a3fd9efe830c4628)
2025-08-15 09:35:53 -07:00
eps1lon 1288c47483 Include stack of cause in React instrumentation errors (#34198)
DiffTrain build for [379a083b9a](https://github.com/facebook/react/commit/379a083b9a95b0409cff4771bd9887e9e589777b)
2025-08-13 10:37:38 -07:00
sebmarkbage c2ce99cd5e [Fiber] Don't bind retry listener if it's in the cache (#34183)
This did an unnecessary bind allocation even if there's cache hit.

DiffTrain build for [f1222f7652](https://github.com/facebook/react/commit/f1222f76521fa7645badaa0c972ad4b2b1dc0b78)
2025-08-12 18:51:01 -07:00
sebmarkbage a92676fceb [DevTools] Fix index (#34187)
I used the wrong indexer and tested with one entry.

DiffTrain build for [47fd2f5e14](https://github.com/facebook/react/commit/47fd2f5e1487fb48c561a6f8f30c534d8f8c7747)
2025-08-12 11:04:25 -07:00
eps1lon a0b63cce3b Create fresh Offscreen instance when replaying (#34127)
DiffTrain build for [ac7820a99e](https://github.com/facebook/react/commit/ac7820a99efac29dcd5a69f6d2438f6d31b7abbf)
2025-08-11 12:03:38 -07:00
kassens f1bbe87949 [easy] remove leftover reference to disableDefaultPropsExceptForClasses (#34169)
Noticed that I missed this in some earlier cleanup diff.

Test Plan:
grep for disableDefaultPropsExceptForClasses

DiffTrain build for [f1e70b5e0a](https://github.com/facebook/react/commit/f1e70b5e0aeffeba634f05a1524bf083f0340d5a)
2025-08-11 09:22:37 -07:00
sophiebits de51778a0a Hot reloading: Avoid stack overflow on wide trees (#34145)
Every sibling added to the stack here. Not sure this needs to be
recursive at all but certainly for siblings this can just be a loop.

DiffTrain build for [cf6e502ed2](https://github.com/facebook/react/commit/cf6e502ed23ab3357e58965789324ddfa0e12821)
2025-08-09 08:08:31 -07:00
sebmarkbage aacecdda22 [Fiber] Try to give a stack trace to every entry in the Scheduler Performance Track (#34123)
For "render" and "commit" phases we don't give any specific stack atm.
This tries to always provide something useful to say the cause of the
render.

For normal renders this will now show the same thing as the "Event" and
"Update" entries already showed. We stash the task that was used for
those and use them throughout the render and commit phases.

For Suspense (Retry lane) and Idle (Offscreen lane), we don't have any
updates. Instead for those there's a component that left work behind in
previous passes. For those I use the debugTask of the `<Suspense>` or
`<Activity>` boundary to indicate that this was the root of the render.

Similarly when an Action is invoked on a `<form action={...}>` component
using the built-in submit handler, there's no actionable stack in user
space that called it. So we use the stack of the JSX for the form
instead.

DiffTrain build for [4c9c109cea](https://github.com/facebook/react/commit/4c9c109cea9be3622d9d70f81f96e72528bdad16)
2025-08-07 07:33:40 -07:00
josephsavona 63256ad2e4 [compiler] remove use of inspect module (#34124)
DiffTrain build for [f468d37739](https://github.com/facebook/react/commit/f468d37739cbce9caff88c3b83aca47b0ea7bdbc)
2025-08-07 00:07:12 -07:00
josephsavona 7da6014535 [compiler] Delete PropagatePhiTypes (#34107)
We moved this logic into InferTypes a long time ago and the PRs to clean
it up keep getting lost in the shuffle.

DiffTrain build for [7deda941f7](https://github.com/facebook/react/commit/7deda941f7f77e82de0311fc3e0cf94d8a863069)
2025-08-04 15:25:12 -07:00
josephsavona 313c51425e [compiler] rebase #32285 (#34102)
Redo of #32285 which was created with ghstack and is tedious to rebase
with sapling.

DiffTrain build for [d3b26b2953](https://github.com/facebook/react/commit/d3b26b2953c7e780abaa49f422c53fd4cda08e47)
2025-08-04 12:11:18 -07:00
sebmarkbage a6b6ccf3c0 Allow returning a temporary reference inside an async function (#33761)
<!--
  Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.

Before submitting a pull request, please make sure the following is
done:

1. Fork [the repository](https://github.com/facebook/react) and create
your branch from `main`.
  2. Run `yarn` in the repository root.
3. If you've fixed a bug or added code that should be tested, add tests!
4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch
TestName` is helpful in development.
5. Run `yarn test --prod` to test in the production environment. It
supports the same options as `yarn test`.
6. If you need a debugger, run `yarn test --debug --watch TestName`,
open `chrome://inspect`, and press "Inspect".
7. Format your code with
[prettier](https://github.com/prettier/prettier) (`yarn prettier`).
8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only
check changed files.
  9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`).
  10. If you haven't already, complete the CLA.

Learn more about contributing:
https://reactjs.org/docs/how-to-contribute.html
-->

## Summary

Fixes `await`-ing and returning temporary references in `async`
functions. These two operations invoke `.then()` under the hood if it is
available, which currently results in an "Cannot access then on the
server. You cannot dot into a temporary client reference..." error. This
can easily be reproduced by returning a temporary reference from a
server function.

Fixes #33534

## How did you test this change?
I added a test in a new test file. I wasn't sure where else to put it.
<img width="771" height="138" alt="image"
src="https://github.com/user-attachments/assets/09ffe6eb-271a-4842-a9fe-c68e17b3fb41"
/>

<!--
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.
-->

DiffTrain build for [1d163962b2](https://github.com/facebook/react/commit/1d163962b21f9396d26930e31719bd8b10d9e107)
2025-08-02 15:19:50 -07:00
josephsavona 789bae0c1e [compiler] Add definitions for Object entries/keys/values (#34047)
Fixes remaining issue in #32261, where passing a previously useMemo()-d
value to `Object.entries()` makes the compiler think the value is
mutated and fail validatePreserveExistingMemo. While I was there I added
Object.keys() and Object.values() too.

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34047).
* #34049
* __->__ #34047
* #34044

DiffTrain build for [0860b9cc1f](https://github.com/facebook/react/commit/0860b9cc1f4a7188b41204bddc57a127a8bbf6e9)
2025-08-01 13:06:43 -07:00
poteto ad524e50a1 [compiler] Emit more specific error when making identifiers with reserved words (#34080)
This currently throws an invariant which may be misleading. I checked
the ecma262 spec and used the same list of reserved words in our check.
To err on the side of being conservative, we also error when strict mode
reserved words are used.

DiffTrain build for [52612a7cbd](https://github.com/facebook/react/commit/52612a7cbdd8e1fee9599478247f78725869ebad)
2025-08-01 12:18:45 -07:00
josephsavona ceea1fc141 Enable ref validation in linter (#34044)
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34044).
* #34027
* __->__ #34044

DiffTrain build for [88b40f6e41](https://github.com/facebook/react/commit/88b40f6e41004773f19d37827980c66a8cf1865b)
2025-07-29 12:37:24 -07:00
josephsavona e3d076194c [compiler] Allow assigning ref-accessing functions to objects if not mutated (#34026)
Allows assigning a ref-accessing function to an object so long as that
object is not subsequently transitively mutated. We should likely
rewrite the ref validation to use the new mutation/aliasing effects,
which would provide a more consistent behavior across instruction types
and require fewer special cases like this.

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34026).
* #34027
* __->__ #34026

DiffTrain build for [04a7a61918](https://github.com/facebook/react/commit/04a7a61918522734a083bff37843865d7815d466)
2025-07-29 11:05:18 -07:00
josephsavona 491b4aaa84 [compiler] disallow ref access in state initializer, reducer/initializer (#34025)
Per title, disallow ref access in `useState()` initializer function,
`useReducer()` reducer, and `useReducer()` init function.

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34025).
* #34027
* #34026
* __->__ #34025

DiffTrain build for [c2326b1336](https://github.com/facebook/react/commit/c2326b1336e38a52899fad6c2ddbb71ea7ddd3ee)
2025-07-29 11:03:37 -07:00
josephsavona daaa3f089b [compiler] treat ref-like identifiers as refs by default (#34005)
`@enableTreatRefLikeIdentifiersAsRefs` is now on by default. I made one
small fix to the render helper logic as part of this, uncovered by
including more tests.

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34005).
* #34027
* #34026
* #34025
* #34024
* __->__ #34005

DiffTrain build for [6891dcb87d](https://github.com/facebook/react/commit/6891dcb87db831db17ab109730dea63706875dd7)
2025-07-29 10:59:10 -07:00
josephsavona 0d2d171574 [compiler] Allow mergeRefs pattern (and detect refs passed as ref prop) (#34004)
Two related changes:
* ValidateNoRefAccessInRender now allows the mergeRefs pattern, ie a
function that aggregates multiple refs into a new ref. This is the main
case where we have seen false positive no-ref-in-render errors.
* Behind `@enableTreatRefLikeIdentifiersAsRefs`, we infer values passed
as the `ref` prop to some JSX as refs.

The second change is potentially helpful for situations such as

```js
function Component({ref: parentRef}) {
  const childRef = useRef(null);
  const mergedRef = mergeRefs(parentRef, childRef);
  useEffect(() => {
    // generally accesses childRef, not mergedRef
  }, []);
  return <Foo ref={mergedRef} />;
}
```

Ie where you create a merged ref but don't access its `.current`
property. Without inferring `ref` props as refs, we'd fail to allow this
merge refs case.

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34004).
* #34027
* #34026
* #34025
* #34024
* #34005
* #34006
* __->__ #34004

DiffTrain build for [1d7e942da7](https://github.com/facebook/react/commit/1d7e942da76c794c3cbf52a8c214d90a69814a8f)
2025-07-29 10:12:39 -07:00
josephsavona 1d149910da [compiler] Improve ref validation error message (#34003)
Improves the error message for ValidateNoRefAccessInRender, using the
new diagnostic type as well as providing a longer but succinct summary
of what refs are for and why they're unsafe to access in render.

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34003).
* #34027
* #34026
* #34025
* #34024
* #34005
* #34006
* #34004
* __->__ #34003

DiffTrain build for [79dc706498](https://github.com/facebook/react/commit/79dc706498c4f8ef077167898492693197e1b975)
2025-07-29 10:11:27 -07:00
josephsavona 263abf8d70 [compiler] Fixes to enableTreatRefLikeIdentifiersAsRefs (#34000)
We added the `@enableTreatRefLikeIdentifiersAsRefs` feature a while back
but never enabled it. Since then we've continued to see examples that
motivate this mode, so here we're fixing it up to prepare to enable by
default. It now works as follows:

* If we find a property load or property store where both a) the
object's name is ref-like (`ref` or `-Ref`) and b) the property is
`current`, we infer the object itself as a ref and the value of the
property as a ref value. Originally the feature only detected property
loads, not stores.
* Inferred refs are not considered stable (this is a change from the
original implementation). The only way to get a stable ref is by calling
`useRef()`. We've seen issues with assuming refs are stable.

With this change, cases like the following now correctly error:

```js
function Foo(props) {
  const fooRef = props.fooRef;
  fooRef.current = true;
  ^^^^^^^^^^^^^^ cannot modify ref in render
}
```

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34000).
* #34027
* #34026
* #34025
* #34024
* #34005
* #34006
* #34004
* #34003
* __->__ #34000

DiffTrain build for [85bbe39ef8](https://github.com/facebook/react/commit/85bbe39ef8e24a192b5e9f2987b1babf8ce772e1)
2025-07-29 10:05:50 -07:00
poteto d75704db4e [eslint] Disallow use within try/catch blocks (#34040)
Follow up to #34032. The linter now ensures that `use` cannot be used
within try/catch.

DiffTrain build for [820af20971](https://github.com/facebook/react/commit/820af2097103309fdc5675d2bde744103a439eff)
2025-07-29 09:40:25 -07:00
sebmarkbage fad31e901a [Fiber] Treat unwrapping React.lazy more like a use() (#34031)
While we want to get rid of React.lazy's special wrapper type and just
use a Promise for the type, we still have the wrapper.

However, this is still conceptually the same as a Usable in that it
should be have the same if you `use(promise)` or render a Promise as a
child or type position.

This PR makes it behave like a `use()` when we unwrap them. We could
move to a model where it actually reaches the internal of the Lazy's
Promise when it unwraps but for now I leave the lazy API signature
intact by just catching the Promise and then "use()" that.

This lets us align on the semantics with `use()` such as the suspense
yield optimization. It also lets us warn or fork based on legacy
throw-a-Promise behavior where as `React.lazy` is not deprecated.

DiffTrain build for [9be531cd37](https://github.com/facebook/react/commit/9be531cd37f5558c72f7de360eb921b0074e8544)
2025-07-29 08:57:03 -07:00
poteto d31235a22c [compiler] Enable validateNoVoidUseMemo in eslint & playground (#34022)
Enables `validateNoVoidUseMemo` by default only in eslint (it defaults
to false otherwise) as well as the playground.

DiffTrain build for [7ee7571212](https://github.com/facebook/react/commit/7ee7571212bc02354b852752a98b23bc90546fdf)
2025-07-28 10:49:06 -07:00
poteto bc990fa413 [compiler] Aggregate all errors reported from DropManualMemoization (#34002)
Noticed this from my previous PR that this pass was throwing on the
first error. This PR is a small refactor to aggregate every violation
and report them all at once.

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/34002).
* #34022
* __->__ #34002

DiffTrain build for [6b22f31f1a](https://github.com/facebook/react/commit/6b22f31f1ac88cce1b38c67a5c97c7ab0e832823)
2025-07-28 10:42:25 -07:00
poteto 8c18e42044 [compiler] Add new ValidateNoVoidUseMemo pass (#33990)
Adds a new validation pass to validate against `useMemo`s that don't
return anything. This usually indicates some kind of "useEffect"-like
code that has side effects that need to be memoized to prevent
overfiring, and is an anti-pattern.

A follow up validation could also look at the return value of `useMemo`s
to see if they are being used.

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/33990).
* #34022
* #34002
* #34001
* __->__ #33990
* #33989

DiffTrain build for [c60eebffea](https://github.com/facebook/react/commit/c60eebffea94a67f35c6ebbf7019e5b2145d4284)
2025-07-28 10:00:36 -07:00
poteto 53be33885b [compiler] Disambiguate between void, implicit, and explicit returns (#33989)
Adds a new property to ReturnTerminals to disambiguate whether it was
explicit, implicit (arrow function expressions), or void (where it was
omitted). I will use this property in the next PR adding a new
validation pass.

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/33989).
* #34022
* #34002
* #34001
* #33990
* __->__ #33989

DiffTrain build for [5dd622eabe](https://github.com/facebook/react/commit/5dd622eabe38e01781b3699d0d81c4a16e302f09)
2025-07-28 09:53:42 -07:00
eps1lon 6d509fd780 [Runtime] Fix CI (#33999)
DiffTrain build for [19baee813c](https://github.com/facebook/react/commit/19baee813cb08fc5971a3b301814faa6cd530ec8)
2025-07-25 12:11:41 -07:00
josephsavona 3b71e2f85c [compiler] Enable additional lints by default (#33752)
Enable more validations to help catch bad patterns, but only in the
linter. These rules are already enabled by default in the compiler _if_
violations could produce unsafe output.

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/33752).
* #33981
* #33777
* #33767
* #33765
* #33760
* #33759
* #33758
* #33751
* __->__ #33752
* #33753

DiffTrain build for [0d39496eab](https://github.com/facebook/react/commit/0d39496eab710b5a3efc07d34c0db3f2475c04f8)
2025-07-24 16:03:36 -07:00
josephsavona ccbdf63a2c [compiler] Fix for false positive mutation of destructured spread object (#33786)
When destructuring, spread creates a new mutable object that _captures_
part of the original rvalue. This new value is safe to modify.

When making this change I realized that we weren't inferring array
pattern spread as creating an array (in type inference) so I also added
that here.

DiffTrain build for [448f781a52](https://github.com/facebook/react/commit/448f781a52d62042341d2411d1352d705ce2cbfe)
2025-07-24 15:41:31 -07:00
sebmarkbage e5d64ee8e3 [Fiber] Don't throw away the Error object retaining the owner stack (#33976)
We currently throw away the Error once we've used to the owner stack of
a Fiber once. This maybe helps a bit with memory and redoing it but we
really don't expect most Fibers to hit this at all. It's not very hot.

If we throw away the Error, then we can't use native debugger protocols
to inspect the native stack. Instead, we'd have to maintain a url to
resource map indefinitely like what Chrome DevTools does to map a url to
a resource. Technically it's not even technically correct since the file
path might not be reversible and could in theory conflict.

DiffTrain build for [4f34cc4a2e](https://github.com/facebook/react/commit/4f34cc4a2e1198493375867d1876509ae9771aee)
2025-07-24 10:44:28 -07:00
eps1lon 8d853aeb6f [Flight] Remove superfluous whitespace when console method is called with non-strings (#33953)
DiffTrain build for [f6fb1a07a5](https://github.com/facebook/react/commit/f6fb1a07a5fda2aa436f6ddf9a31025945cd67b3)
2025-07-23 01:13:47 -07:00
jbrown215 e674366e63 Change autodeps configuration (#33800)
DiffTrain build for [074e92777c](https://github.com/facebook/react/commit/074e92777c22a56269647d614fdae80bf6406485)
2025-07-21 13:10:15 -07:00
sammy-SC c8dd9b6eb2 Clean up feature flag to use lazy public instances in Fabric (#33943)
## Summary

We have thoroughly tested this flag in production and proved stability
and performance, so we can clean it up and "ship it".

DiffTrain build for [e9638c33d7](https://github.com/facebook/react/commit/e9638c33d7e79162516b89da31549af4090997a5)
2025-07-21 02:33:51 -07:00
jbrown215 e55cc20718 InferEffectDeps takes a React.AUTODEPS sigil (#33799)
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/33799).
* #33800
* __->__ #33799

DiffTrain build for [dffacc7b80](https://github.com/facebook/react/commit/dffacc7b8094576c19790fe8341996f743ba4a89)
2025-07-17 05:38:47 -07:00
hoxyq 54d3118dd9 fix: log renders from passive effects for only newly finished work (#33797)
This fixes displaying incorrect component render entries on a timeline,
when we are reconnecting passive effects.

### Before
<img width="2318" height="1127" alt="1"
src="https://github.com/user-attachments/assets/9b6b2824-d2de-43a3-8615-2c45d67c3668"
/>

The cloned nodes will persist original `actualStartTime`, when these
were first mounted. When we "replay", the end time will be "now" or
whatever the actual start time of the sibling. Depending on when this is
being recorded, the diff between end and start could be tens of seconds
and doesn't represent what React was doing.

We shouldn't log these entries at all.

### After
We are only logging newly finished renders, but could potentially loose
renders that never commit.

DiffTrain build for [9fec565a9b](https://github.com/facebook/react/commit/9fec565a9b9f78558323adff1013291cf46f7de7)
2025-07-16 10:17:28 -07:00
josephsavona 981b703a40 [compiler] Check TSAsExpression and TSNonNullExpression reorderability (#33788)
## Summary

The `TSAsExpression` and `TSNonNullExpression` nodes are supported by
`lowerExpression()` but `isReorderableExpression()` does not check if
they can be reordered. This PR updates `isReorderableExpression()` to
handle these two node types by adding cases that fall through to the
existing `TypeCastExpression` case.

We ran `react-compiler-healthcheck` at scale on several of our repos and
found dozens of `` (BuildHIR::node.lowerReorderableExpression)
Expression type `TSAsExpression` cannot be safely reordered`` errors and
a handful for `TSNonNullExpression`.

## How did you test this change?

In this case I added two fixture tests

DiffTrain build for [fe813143e2](https://github.com/facebook/react/commit/fe813143e23675963f92d25fa1fb35b39db40272)
2025-07-15 12:02:20 -07:00
jbrown215 d151b55a3d [eslint] Do not allow useEffectEvent fns to be called in arbitrary closures (#33544)
Summary:

useEffectEvent is meant to be used specifically in combination with
useEffect, and using
the feature in arbitrary closures can lead to surprising reactivity
semantics. In order to
minimize risk in the experimental rollout, we are going to restrict its
usage to being
called directly inside an effect or another useEffectEvent, effectively
enforcing the function
coloring statically. Without an effect system this is the best we can
do.

DiffTrain build for [97cdd5d3c3](https://github.com/facebook/react/commit/97cdd5d3c33eda77be4f96a43f72d6916d3badbb)
2025-07-10 13:57:17 -07:00