Commit Graph
1379 Commits
Author SHA1 Message Date
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
josephsavona 5638224a7f [compiler] Add CompilerError.UnsupportedJS variant (#33750)
We use this variant for syntax we intentionally don't support: with
statements, eval, and inline class declarations.

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

DiffTrain build for [96c61b7f1f](https://github.com/facebook/react/commit/96c61b7f1f145b9fe5103051b636959cdeb20cc8)
2025-07-09 22:31:11 -07:00
josephsavona 1f5d41f4df [compiler] Errors for eval(), with statments, class declarations (#33746)
* Error for `eval()`
* More specific error message for `with (expr) { ... }` syntax
* More specific error message for class declarations

---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/33746).
* #33752
* #33751
* #33750
* #33748
* #33747
* __->__ #33746

DiffTrain build for [4a3ff8eed6](https://github.com/facebook/react/commit/4a3ff8eed65f96cda7617150f92de3544d5ddf6a)
2025-07-09 22:25:09 -07:00
josephsavona 1ee60a49ed [compiler] Improve IIFE inlining (#33726)
We currently inline IIFEs by creating a temporary and a labeled block w
the original code. The original return statements turn into an
assignment to the temporary and break out of the label. However, many
cases of IIFEs are due to inlining of manual `useMemo()`, and these
cases often have only a single return statement. Here, the output is
cleaner if we avoid the temporary and label - so that's what we do in
this PR.

Note that the most complex part of the change is actually around
ValidatePreserveExistingMemo - we have some logic to track the IIFE
temporary reassignmetns which needs to be updated to handle the simpler
version of inlining.

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

DiffTrain build for [956d770adf](https://github.com/facebook/react/commit/956d770adf59e1f8a00a7b7c52b5727ef9e353e7)
2025-07-08 16:44:05 -07:00
sebmarkbage e5e1168f47 [Fiber] Name content inside "Suspense fallback" (#33724)
Same as #33723 but for Fiber.

DiffTrain build for [b44a99bf58](https://github.com/facebook/react/commit/b44a99bf58d69d52b5288d9eadcc6d226d705e11)
2025-07-07 21:08:26 -07:00
sebmarkbage aef297a35f [Fiber] Highlight a Component with Deeply Equal Props in the Performance Track (#33660)
Stacked on #33658 and #33659.

If we detect that a component is receiving only deeply equal objects,
then we highlight it as potentially problematic and worth looking into.

<img width="1055" alt="Screenshot 2025-06-27 at 4 15 28 PM"
src="https://github.com/user-attachments/assets/e96c6a05-7fff-4fd7-b59a-36ed79f8e609"
/>

It's fairly conservative and can bail out for a number of reasons:

- We only log it on the first parent that triggered this case since
other children could be indirect causes.
- If children has changed then we bail out since this component will
rerender anyway. This means that it won't warn for a lot of cases that
receive plain DOM children since the DOM children won't themselves get
logged.
- If the component's total render time including children is 100ms or
less then we skip warning because rerendering might not be a big deal.
- We don't warn if you have shallow equality but could memoize the JSX
element itself since we don't typically recommend that and React
Compiler doesn't do that. It only warns if you have nested objects too.
- If the depth of the objects is deeper than like the 3 levels that we
print diffs for then we wouldn't warn since we don't know if they were
equal (although we might still warn on a child).
- If the component had any updates scheduled on itself (e.g. setState)
then we don't warn since it would rerender anyway. This should really
consider Context updates too but we don't do that atm. Technically you
should still memoize the incoming props even if you also had unrelated
updates since it could apply to deeper bailouts.

DiffTrain build for [0b78161d7d](https://github.com/facebook/react/commit/0b78161d7d76b7fb9786f25dd222010b9e417191)
2025-07-02 14:39:53 -07:00
kassens f029349313 Remove now dead argument from resolveClassComponentProps (#33682)
No longer used after https://github.com/facebook/react/pull/33648

DiffTrain build for [73aa744b70](https://github.com/facebook/react/commit/73aa744b7029556430f409ec3887a714940698ba)
2025-07-02 07:54:25 -07:00
kassens 5fcf94686b Cleanup disableDefaultPropsExceptForClasses flag (#33648)
DiffTrain build for [602917c8cb](https://github.com/facebook/react/commit/602917c8cb521e6f9b8eae7070985e2a698fc0d0)
2025-07-01 13:00:04 -07:00
hoxyq 32628e27fb fix: rename bottom stack frame (#33680)
`react-stack-bottom-frame` -> `react_stack_bottom_frame`.

This survives `@babel/plugin-transform-function-name`, but now frames
will be displayed as `at Object.react_stack_bottom_frame (...)` in V8.
Checks that were relying on exact function name match were updated to
use either `.indexOf()` or `.includes()`

For backwards compatibility, both React DevTools and Flight Client will
look for both options. I am not so sure about the latter and if React
version is locked.

DiffTrain build for [91d097b2c5](https://github.com/facebook/react/commit/91d097b2c588a0977a7a10ed12512dc8a34e3a5b)
2025-07-01 10:13:44 -07:00
huntie 59b630fc80 Align AttributeConfiguration type in ReactNativeTypes (#33671)
DiffTrain build for [1e0d12b6f2](https://github.com/facebook/react/commit/1e0d12b6f273d7345e32c16cd937475ed7c512ad)
2025-06-30 07:43:31 -07:00
sebmarkbage 627421f141 Special case printing Promises in Performance Track Properties (#33670)
Before:
<img width="266" alt="Screenshot 2025-06-30 at 8 32 23 AM"
src="https://github.com/user-attachments/assets/98aae5e1-4b2c-49bd-9b71-040b788c36ba"
/>

After:
<img width="342" alt="Screenshot 2025-06-30 at 8 39 17 AM"
src="https://github.com/user-attachments/assets/cd91c4a6-f6ae-4bec-9cd9-f42f4af468fe"
/>

DiffTrain build for [e9cab42ece](https://github.com/facebook/react/commit/e9cab42ece435ac3478ec85847e352177e596ae0)
2025-06-30 06:28:50 -07:00
sebmarkbage d75b43973d Include Component Props in Performance Track (#33655)
Similar to how we can include a Promise resolved value we can include
Component Props.

For now I left out props for Client Components for perf unless they
error. I'll try it for Client Components in general in a separate PR.

<img width="730" alt="Screenshot 2025-06-26 at 5 54 29 PM"
src="https://github.com/user-attachments/assets/f0c86911-2899-4b5f-b45f-5326bdbc630f"
/>
<img width="762" alt="Screenshot 2025-06-26 at 5 54 12 PM"
src="https://github.com/user-attachments/assets/97540d19-5950-4346-99e6-066af086040e"
/>

DiffTrain build for [d2a288febf](https://github.com/facebook/react/commit/d2a288febf61a1755b78ce98b3cb17dd412b81e3)
2025-06-27 05:52:12 -07:00
unstubbableandSebastian Sebbie Silbermann 54d04bebad [Flight] Add tests for component and owner stacks of halted components (#33644)
This PR adds tests for the Node.js and Edge builds to verify that
component stacks and owner stacks of halted components appear as
expected, now that recent enhancements for those have been implemented
(the latest one being #33634).

---------

Co-authored-by: Sebastian "Sebbie" Silbermann <silbermann.sebastian@gmail.com>

DiffTrain build for [9b2a545b32](https://github.com/facebook/react/commit/9b2a545b32ef19c6b67812d2c3444a709406a58b)
2025-06-25 13:45:58 -07:00
sebmarkbageandHendrik Liebau d0c88dba51 [Flight] Log aborted await and component renders (#33641)
<img width="926" alt="Screenshot 2025-06-25 at 1 02 14 PM"
src="https://github.com/user-attachments/assets/1877d13d-5259-4cc4-8f48-12981e3073fe"
/>

The I/O entry doesn't show as aborted in the Server Request track
because technically it wasn't. The end time is just made up. It's still
going. It's not aborted until the abort signal propagates and if we do
get that signal wired up before it emits, it instead would show up as
rejected.

---------

Co-authored-by: Hendrik Liebau <mail@hendrik-liebau.de>

DiffTrain build for [bb6c9d521e](https://github.com/facebook/react/commit/bb6c9d521e7f44eb9a9754a14cde62c8e6439e5e)
2025-06-25 13:40:13 -07:00
josephsavona 74404dc86a [compiler] Fix bug with reassigning function param in destructuring (#33624)
Closes #33577, a bug with ExtractScopeDeclarationsFromDestructuring and
codegen when a function param is reassigned.

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

DiffTrain build for [9894c488e0](https://github.com/facebook/react/commit/9894c488e0d9a4d9759d80ba8666d4d094b894e9)
2025-06-25 11:25:10 -07:00
josephsavona e2d000654a [compiler] Consolidate HIRFunction return information (#33640)
We now have `HIRFunction.returns: Place` as well as `returnType: Type`.
I want to add additional return information, so as a first step i'm
consolidating everything under an object at `HIRFunction.returns:
{place: Place}`. We use the type of this place as the return type. Next
step is to add more properties to this object to represent things like
the return kind.

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

DiffTrain build for [123ff13b19](https://github.com/facebook/react/commit/123ff13b193cd361a61b99056dd08f2decd7f55d)
2025-06-25 11:19:06 -07:00
josephsavona 094fa5e535 [compiler] Avoid empty switch cases (#33625)
Small cosmetic win, found this when i was looking at some code
internally with lots of cases that all share the same logic. Previously,
all the but last one would have an empty block.

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

DiffTrain build for [e130c08b06](https://github.com/facebook/react/commit/e130c08b06470b5fc4ec8095310d19e782924427)
2025-06-25 11:17:05 -07:00
javache fc97c65ed0 [react-native] Consume ReactNativeAttributePayloadFabric from ReactNativePrivateInterface (#33616)
## Summary

ReactNativeAttributePayloadFabric was synced to react-native in
https://github.com/facebook/react-native/commit/0e42d33cbcfadcf5d787108da785d56a83d07a9f.
We should now consume these methods from the
ReactNativePrivateInterface.

Moving these methods to the React Native repo gives us more flexibility
to experiment with new techniques for bridging and diffing props
payloads.

I did have to leave some stub implementations for existing unit tests,
but moved all detailed tests to the React Native repo.

## How did you test this change?

* `yarn prettier`
* `yarn test ReactFabric-test`

DiffTrain build for [7a3ffef703](https://github.com/facebook/react/commit/7a3ffef70339c10f8d65a27b88cd73bfbe13eb8a)
2025-06-25 02:31:15 -07:00
sebmarkbageandHendrik Liebau 6db4aa0298 [Flight] Emit Partial Debug Info if we have any at the point of aborting a render (#33632)
When we abort a render we don't really have much information about the
task that was aborted. Because before a Promise resolves there's no
indication about would have resolved it. In particular we don't know
which I/O would've ultimately called resolve().

However, we can at least emit any information we do have at the point
where we emit it. At the least the stack of the top most Promise.

Currently we synchronously flush at the end of an `abort()` but we
should ideally schedule the flush in a macrotask and emit this debug
information right before that. That way we would give an opportunity for
any `cacheSignal()` abort to trigger rejections all the way up and those
rejections informs the awaited stack.

---------

Co-authored-by: Hendrik Liebau <mail@hendrik-liebau.de>

DiffTrain build for [e67b4fe22e](https://github.com/facebook/react/commit/e67b4fe22e0c3c267303ee6737aec1db48055022)
2025-06-24 13:43:57 -07:00
josephsavona 99aa3a2717 [compiler] New inference repros/fixes (#33584)
Substantially improves the last major known issue with the new inference
model's implementation: inferring effects of function expressions. I
knowingly used a really simple (dumb) approach in
InferFunctionExpressionAliasingEffects but it worked surprisingly well
on a ton of code. However, investigating during the sync I saw that we
the algorithm was literally running out of memory, or crashing from
arrays that exceeded the maximum capacity. We were accumluating data
flow in a way that could lead to lists of data flow captures compounding
on themselves and growing very large very quickly. Plus, we were
incorrectly recording some data flow, leading to cases where we reported
false positive "can't mutate frozen value" for example.

So I went back to the drawing board. InferMutationAliasingRanges already
builds up a data flow graph which it uses to figure out what values
would be affected by mutations of other values, and update mutable
ranges. Well, the key question that we really want to answer for
inferring a function expression's aliasing effects is which values
alias/capture where. Per the docs I wrote up, we only have to record
such aliasing _if they are observable via mutations_. So, lightbulb:
simulate mutations of the params, free variables, and return of the
function expression and see which params/free-vars would be affected!
That's what we do now, giving us precise information about which such
values alias/capture where. When the "into" is a param/context-var we
use Capture, iwhen the destination is the return we use Alias to be
conservative.

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

DiffTrain build for [94cf60bede](https://github.com/facebook/react/commit/94cf60bede7cd6685e07a4374d1e3aa90445130b)
2025-06-24 10:09:13 -07:00
eps1lon 2939511af5 Fix CI (#33578)
DiffTrain build for [a947eba4f2](https://github.com/facebook/react/commit/a947eba4f2c8741d2c61a3b33fd79cf13bf9f39d)
2025-06-19 14:51:27 -07:00
sebmarkbage 3f8abf8acf Expose cacheSignal() alongside cache() (#33557)
This was really meant to be there from the beginning. A `cache()`:ed
entry has a life time. On the server this ends when the render finishes.
On the client this ends when the cache of that scope gets refreshed.

When a cache is no longer needed, it should be possible to abort any
outstanding network requests or other resources. That's what
`cacheSignal()` gives you. It returns an `AbortSignal` which aborts when
the cache lifetime is done based on the same execution scope as a
`cache()`ed function - i.e. `AsyncLocalStorage` on the server or the
render scope on the client.

```js
import {cacheSignal} from 'react';
async function Component() {
  await fetch(url, { signal: cacheSignal() });
}
```

For `fetch` in particular, a patch should really just do this
automatically for you. But it's useful for other resources like database
connections.

Another reason it's useful to have a `cacheSignal()` is to ignore any
errors that might have triggered from the act of being aborted. This is
just a general useful JavaScript pattern if you have access to a signal:

```js
async function getData(id, signal) {
  try {
     await queryDatabase(id, { signal });
  } catch (x) {
     if (!signal.aborted) {
       logError(x); // only log if it's a real error and not due to cancellation
     }
     return null;
  }
}
```

This just gets you a convenient way to get to it without drilling
through so a more idiomatic code in React might look something like.

```js
import {cacheSignal} from "react";

async function getData(id) {
  try {
     await queryDatabase(id);
  } catch (x) {
     if (!cacheSignal()?.aborted) {
       logError(x);
     }
     return null;
  }
}
```

If it's called outside of a React render, we normally treat any cached
functions as uncached. They're not an error call. They can still load
data. It's just not cached. This is not like an aborted signal because
then you couldn't issue any requests. It's also not like an infinite
abort signal because it's not actually cached forever. Therefore,
`cacheSignal()` returns `null` when called outside of a React render
scope.

Notably the `signal` option passed to `renderToReadableStream` in both
SSR (Fizz) and RSC (Flight Server) is not the same instance that comes
out of `cacheSignal()`. If you abort the `signal` passed in, then the
`cacheSignal()` is also aborted with the same reason. However, the
`cacheSignal()` can also get aborted if the render completes
successfully or fatally errors during render - allowing any outstanding
work that wasn't used to clean up. In the future we might also expand on
this to give different
[`TaskSignal`](https://developer.mozilla.org/en-US/docs/Web/API/TaskSignal)
to different scopes to pass different render or network priorities.

On the client version of `"react"` this exposes a noop (both for
Fiber/Fizz) due to `disableClientCache` flag but it's exposed so that
you can write shared code.

DiffTrain build for [e1dc03492e](https://github.com/facebook/react/commit/e1dc03492eedaec517e14a6e32b8fda571d00767)
2025-06-17 14:10:59 -07:00
jbrown215 15a6dc7dcf [compiler] Add repro for IIFE in ternary causing a bailout (#33546)
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/33546).
* #33548
* __->__ #33546

DiffTrain build for [75e78d243f](https://github.com/facebook/react/commit/75e78d243f749d009fa1c5c09c3464301b992718)
2025-06-16 19:06:07 -07:00
jbrown215 3b068f6553 [compiler] Do not inline IIFEs in value blocks (#33548)
As discussed in chat, this is a simple fix to stop introducing labels
inside expressions.

The useMemo-with-optional test was added in
https://github.com/facebook/react/commit/d70b2c2c4e85c2a7061214c15a8ff13167d10422
and crashes for the same reason- an unexpected label as a value block
terminal.

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

DiffTrain build for [90bee81902](https://github.com/facebook/react/commit/90bee819028bfecb724df298da798607b6a76abf)
2025-06-16 19:01:37 -07:00
kassens 126148e8ca Remove feature flag enableDO_NOT_USE_disableStrictPassiveEffect (#33524)
DiffTrain build for [5d24c64cc9](https://github.com/facebook/react/commit/5d24c64cc9c019fc644c4c6f0da640131b80ba18)
2025-06-16 09:32:35 -07:00
kassens 86066e82d0 Stringify context as SomeContext instead of SomeContext.Provider (#33507)
This matches the change in React 19 to use `<SomeContext>` as the
preferred way to provide a context.

DiffTrain build for [b7e2de632b](https://github.com/facebook/react/commit/b7e2de632b2a160bc09edda1fbb9b8f85a6914e8)
2025-06-11 09:14:54 -07:00
kassens 512c9fb930 Remove feature flag enableRenderableContext (#33505)
The flag is fully rolled out.

DiffTrain build for [6c86e56a0f](https://github.com/facebook/react/commit/6c86e56a0fa3c8f253da133330cd5b7d1d20e7e5)
2025-06-11 08:59:57 -07:00
07f9b02426 [Fiber] Fix hydration of useId in SuspenseList (#33491)
Includes #31412.

The issue is that `pushTreeFork` stores some global state when reconcile
children. This gets popped by `popTreeContext` in `completeWork`.
Normally `completeWork` returns its own `Fiber` again if it wants to do
a second pass which will call `pushTreeFork` again in the next pass.
However, `SuspenseList` doesn't return itself, it returns the next child
to work on.

The fix is to keep track of the count and push it again it when we
return the next child to attempt.

There are still some outstanding issues with hydration. Like the
backwards test still has the wrong behavior in it because it hydrates
backwards and so it picks up the DOM nodes in reverse order.
`tail="hidden"` also doesn't work correctly.

There's also another issue with `useId` and `AsyncIterable` in
SuspenseList when there's an unknown number of children. We don't
support those showing one at a time yet though so it's not an issue yet.
To fix it we need to add variable total count to the `useId` algorithm.
E.g. by falling back to varint encoding.

---------

Co-authored-by: Rick Hanlon <rickhanlonii@fb.com>
Co-authored-by: Ricky <rickhanlonii@gmail.com>

DiffTrain build for [c38e268978](https://github.com/facebook/react/commit/c38e26897848374c34ac6b651fce4a9088ed4dd0)
2025-06-09 16:47:18 -07:00
jbrown215 8b8eae7c2b [compiler] Don't include useEffectEvent values in autodeps (#33450)
Summary: useEffectEvent values are not meant to be added to the dep
array

DiffTrain build for [4df098c4c2](https://github.com/facebook/react/commit/4df098c4c2c51a033592ebc84abc47cc49a6bfb2)
2025-06-09 06:38:10 -07:00
javache a93b8dbee9 feat(ReactNative): prioritize attribute config process function to allow processing function props (#32119)
## Summary

In react-native props that are passed as function get converted to a
boolean (`true`). This is the default pattern for event handlers in
react-native.
However, there are reasons for why you might want to opt-out of this
behavior, and instead, pass along the actual function as the prop.
Right now, there is no way to do this, and props that are functions
always get set to `true`.
The `ViewConfig` attributes already have the API for a `process`
function. I simply moved the check for the process function up, so if a
ViewConfig's prop attribute configured a process function this is always
called first.
This provides an API to opt out of the default behavior.

This is the accompanied PR for react-native:

- https://github.com/facebook/react-native/pull/48777

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

I modified the code manually in a template react-native app and
confirmed its working. This is a code path you only need in very special
cases, thus it's a bit hard to provide a test for this. I recorded a
video where you can see that the changes are active and the prop is
being passed as native value.

For this I created a custom native component with a view config that
looked like this:

```js
const viewConfig = {
  uiViewClassName: 'CustomView',
  bubblingEventTypes: {},
  directEventTypes: {},
  validAttributes: {
    nativeProp: {
      process: (nativeProp) => {
		// Identity function that simply returns the prop function callback
        // to opt out of this prop being set to `true` as its a function
        return nativeProp
      },
    },
  },
}
```

https://github.com/user-attachments/assets/493534b2-a508-4142-a760-0b1b24419e19

Additionally I made sure that this doesn't conflict with any existing
view configs in react native. In general, this shouldn't be a breaking
change, as for existing view configs it didn't made a difference if you
simply set `myProp: true` or `myProp: { process: () => {...} }` because
as soon as it was detected that the prop is a function the config
wouldn't be used (which is what this PR fixes).
Probably everyone, including the react-native core components use
`myProp: true` for callback props, so this change should be fine.

DiffTrain build for [911dbd9e34](https://github.com/facebook/react/commit/911dbd9e34048b21e96f24acb837b926687aa939)
2025-06-09 03:03:13 -07:00
sebmarkbage fa02f0ef85 Replace Implicit Options on SuspenseList with Explicit Options (#33424)
We want to change the defaults for `revealOrder` and `tail` on
SuspenseList. This is an intermediate step to allow experimental users
to upgrade.

To explicitly specify these options I added `revealOrder="independent"`
and `tail="visible"`.

I then added warnings if `undefined` or `null` is passed. You must now
always explicitly specify them. However, semantics are still preserved
for now until the next step.

We also want to change the rendering order of the `children` prop for
`revealOrder="backwards"`. As an intermediate step I first added
`revealOrder="unstable_legacy-backwards"` option. This will only be
temporary until all users can switch to the new `"backwards"` semantics
once we flip it in the next step.

I also clarified the types that the directional props requires iterable
children but not iterable inside of those. Rows with multiple items can
be modeled as explicit fragments.

DiffTrain build for [d742611ce4](https://github.com/facebook/react/commit/d742611ce40545127032f4e221c78bf9f70eb437)
2025-06-03 14:48:24 -07:00
sebmarkbage 2bb1f667a3 Use underscore instead of « » for useId algorithm (#33422)
Alternative to #33421. The difference is that this also adds an
underscore between the "R" and the ID.

The reason we wanted to use special characters is because we use the
full spectrum of A-Z 0-9 in our ID generation so we can basically
collide with any common word (or anyone using a similar algorithm,
base64 or even base16). It's a little less likely that someone would put
`_R_` specifically unless you generate like two IDs separated by
underscore.

![9w2ogt](https://github.com/user-attachments/assets/21b2d2ac-1a3a-4657-ba0b-1616e49dfdee)

DiffTrain build for [1ae0a845bd](https://github.com/facebook/react/commit/1ae0a845bde5b95dfc319cadf366cb7b3fb1ca92)
2025-06-03 08:38:09 -07:00
mofeiZ bd2cf53c3b [compiler][patch] Emit unary expressions instead of negative numbers (#33383)
This is a babel bug + edge case.

Babel compact mode produces invalid JavaScript (i.e. parse error) when
given a `NumericLiteral` with a negative value.

See https://codesandbox.io/p/devbox/5d47fr for repro.

DiffTrain build for [526dd340b3](https://github.com/facebook/react/commit/526dd340b3e77193846fe5eed02b9bb89d7c2d15)
2025-06-02 08:53:55 -07:00
javache 57bfa90fe3 Cleanup props diffing experiments (#33381)
## Summary

We completed testing on these internally, so can cleanup the separate
fast and slow paths and remove the `enableShallowPropDiffing` flag which
we're not pursuing.

## How did you test this change?

```
yarn test ReactNativeAttributePayloadFabric
```

DiffTrain build for [8b55eb4e72](https://github.com/facebook/react/commit/8b55eb4e724271206bd5dec7dba0a35aedc74493)
2025-05-30 09:27:12 -07:00
eps1lon 919208f846 [react-dom] Enforce small gap between completed navigation and default Transition indicator (#33354)
DiffTrain build for [5717f1933f](https://github.com/facebook/react/commit/5717f1933f2e8b10406fde1043c3047cbfbddc82)
2025-05-28 10:53:14 -07:00
mofeiZ e35cb5e59e [compiler][gating] Custom opt out directives (experimental option) (#33328)
Adding an experimental / unstable compiler config to enable custom
opt-out directives

DiffTrain build for [f9ae0a4c2e](https://github.com/facebook/react/commit/f9ae0a4c2edc9ad93507b550f2aeb60119955336)
2025-05-27 09:09:23 -07:00
jbrown215 9b5001edaf [eslint] Add an option to require dependencies on effect hooks (#33344)
Summary:

To prepare for automatic effect dependencies, some codebases may want to
codemod
existing useEffect calls with no deps to include an explicit undefined
second argument
in order to preserve the "run on every render" behavior. In sufficiently
large codebases,
this may require a temporary enforcement period where all effects
provide an explicit
dependencies argument.

Outside of migration, relying on a component to render can lead to real
bugs,
especially when working with memoization.

DiffTrain build for [99efc627a5](https://github.com/facebook/react/commit/99efc627a5a8cb56f50cfffee544c86c49572b6f)
2025-05-23 07:16:54 -07:00
sophiebits 556b910114 Fix incorrect use of NoLanes in executionContext check (#33170)
## Summary

This PR fixes a likely incorrect condition in the
`scheduleUpdateOnFiber` function inside `ReactFiberWorkLoop.js`.

Previously, the code checked:

```js
(executionContext & RenderContext) !== NoLanes
````

However, `NoLanes` is part of the lane priority system, not the
execution context flags. The intent here seems to be to detect whether
the current execution context includes `RenderContext`, which should be
compared against `NoContext`, not `NoLanes`.

This fix replaces `NoLanes` with `NoContext` for semantic correctness
and consistency with other checks throughout the codebase.

**Fixes
[[#33169](https://github.com/facebook/react/issues/33169)](https://github.com/facebook/react/issues/33169)**

---

## How did you test this change?

I ran the following commands to validate correctness and ensure nothing
was broken:

* `yarn lint`
* `yarn linc`
* `yarn test`
* `yarn test --prod`
* `yarn flow`
* `yarn prettier`

All checks passed. Since this is a minor internal logic fix and doesn't
change public behavior or APIs, no additional tests are necessary at
this time.

DiffTrain build for [bfaeb4a461](https://github.com/facebook/react/commit/bfaeb4a46175fa0f4edf2eba58349d5029e5e86e)
2025-05-22 19:10:04 -07:00
kassens 509acba3d9 Fix typo in error message. (#33313)
## Summary

I am writing code that isn't so good, so I saw this error message many
times. It appears to have a typo. This PR fixes the typo.

## How did you test this change?

Ran the tests

DiffTrain build for [3e9db65fc3](https://github.com/facebook/react/commit/3e9db65fc3341148a5248b3ffc6bc68c0640fd3f)
2025-05-22 13:25:12 -07:00
mofeiZ eed66bfa2c [compiler] Prepare HIRBuilder to be used by later passes (#32286)
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/32286).
* #33326
* #33325
* __->__ #32286

DiffTrain build for [13f20044f3](https://github.com/facebook/react/commit/13f20044f3a5a9433eb4c6ef4c6577b8f0d13350)
2025-05-22 13:20:39 -07:00
mofeiZ 27e38b43c9 [compiler][gating] Experimental directive based gating (#33149)
Adds `dynamicGating` as an experimental option for testing rollout DX at
Meta. If specified, this enables dynamic gating which matches `use memo
if(...)` directives.

#### Example usage
Input file
```js
// @dynamicGating:{"source":"myModule"}
export function MyComponent() {
  'use memo if(isEnabled)';
   return <div>...</div>;
}
```
Compiler output
```js
import {isEnabled} from 'myModule';
export const MyComponent = isEnabled()
  ? <optimized version>
  : <original version>;
```
---
[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/facebook/react/pull/33149).
* __->__ #33149
* #33148

DiffTrain build for [459a2c4298](https://github.com/facebook/react/commit/459a2c4298187cb0ee45605e2575ff35f4a81183)
2025-05-21 14:30:02 -07:00
jackpope b850e17e7b New children notify fragment instances in Fabric (#33093)
When a new child of a fragment instance is inserted, we need to notify
the instance to keep any relevant tracking up to date. For example, we
automatically observe the new child with any active
IntersectionObserver.

For mutable renderers (DOM), we reuse the existing traversal in
`commitPlacement` that does the insertions for HostComponents. Immutable
renderers (Fabric) exit this path before the traversal though, so
currently we can't notify the fragment instances.

Here I've created a separate traversal in `commitPlacement`,
specifically for immutable renders when `enableFragmentRefs` is on.

DiffTrain build for [1835b3f7d9](https://github.com/facebook/react/commit/1835b3f7d9c0541259a8812c5dfaf3d77f0721eb)
2025-05-21 12:54:11 -07:00
sebmarkbage e76c45254e [Fiber] Support AsyncIterable children in SuspenseList (#33299)
We support AsyncIterable (more so when it's a cached form like in coming
from Flight) as children.

This fixes some warnings and bugs when passed to SuspenseList.

Ideally SuspenseList with `tail="hidden"` should support unblocking
before the full result has resolved but that's an optimization on top.
We also might want to change semantics for this for
`revealOrder="backwards"` so it becomes possible to stream items in
reverse order.

DiffTrain build for [4c6967be29](https://github.com/facebook/react/commit/4c6967be290fc31182c61cfdac19915fdb16aa60)
2025-05-20 06:46:21 -07:00
josephsavona d4ef296f8a [compiler] Fix error message for custom hooks (#33310)
We were printing "Custom" instead of "hook".

DiffTrain build for [c6c2a52ad8](https://github.com/facebook/react/commit/c6c2a52ad8fb1894b03a3bb618eb57e5deca5aa0)
2025-05-19 15:36:47 -07:00
kassens bbd4a494c7 [eslint-plugin-react-hooks] add experimental_autoDependenciesHooks option (#33294)
DiffTrain build for [a3abf5f2f8](https://github.com/facebook/react/commit/a3abf5f2f835ad0c61e2325f5cbac2d1d9045517)
2025-05-19 12:19:59 -07:00
kassens 129579cd4e [eslint-plugin-react-hooks] fix exhaustive deps lint rule with component syntax (#33182)
DiffTrain build for [4448b18760](https://github.com/facebook/react/commit/4448b18760d867f9e009e810571e7a3b8930bb19)
2025-05-15 09:57:33 -07:00