Commit Graph
636 Commits
Author SHA1 Message Date
gnoff ffde2c00a9 [Fiber] Move updatePriority tracking to renderers (#28751)
Currently updatePriority is tracked in the reconciler. `flushSync` is
going to be implemented reconciler agnostic soon and we need to move the
tracking of this state to the renderer and out of reconciler. This
change implements new renderer bin dings for getCurrentUpdatePriority
and setCurrentUpdatePriority.

I was originally going to have the getter also do the event priority
defaulting using window.event so we eliminate getCur rentEventPriority
but this makes all the callsites where we store the true current
updatePriority on the stack harder to work with so for now they remain
separate.

I also moved runWithPriority to the renderer since it really belongs
whereever the state is being managed and it is only currently exposed in
the DOM renderer.

Additionally the current update priority is not stored on
ReactDOMSharedInternals. While not particularly meaningful in this
change it opens the door to implementing `flushSync` outside of the
reconciler

DiffTrain build for [8e1462e8c4](https://github.com/facebook/react/commit/8e1462e8c471fbec98aac2b3e1326498d0ff7139)
2024-04-08 15:58:13 +00:00
acdlite aabb356a7e jsx: Remove unnecessary hasOwnProperty check (#28775)
Follow up to #28768.

The modern JSX runtime (`jsx`) does not need to check if each prop is a
direct property with `hasOwnProperty` because the compiler always passes
a plain object.

I'll leave the check in the old JSX runtime (`createElement`) since that
one can be called manually with any kind of object, and if there were
old user code that relied on this for some reason, it would be using
that runtime.

DiffTrain build for [0b3b8a6a35](https://github.com/facebook/react/commit/0b3b8a6a354b90fe76a9d82bb34487e5d2f71203)
2024-04-08 15:18:01 +00:00
sebmarkbage c093e5beb3 [Flight] Support FormData from Server to Client (#28754)
We currently support FormData for Replies mainly for Form Actions. This
supports it in the other direction too which lets you return it from an
action as the response. Mainly for parity.

We don't really recommend that you just pass the original form data back
because the action is supposed to be able to clear fields and such but
you could potentially at least use this as the format and could clear
some fields.

We could potentially optimize this with a temporary reference if the
same object was passed to a reply in case you use it as a round trip to
avoid serializing it back again. That way the action has the ability to
override it to clear fields but if it doesn't you get back the same as
you sent.

#28755 adds support for Blobs when the `enableBinaryFlight` is enabled
which allows them to be used inside FormData too.

DiffTrain build for [2acfb7b609](https://github.com/facebook/react/commit/2acfb7b60922bdc8376dd144ca7bc532df78254b)
2024-04-05 18:37:15 +00:00
acdlite 2cfe8d32dd Fast JSX: Don't clone props object (#28768)
(Unless "key" is spread onto the element.)

Historically, the JSX runtime clones the props object that is passed in.
We've done this for two reasons.

One reason is that there are certain prop names that are reserved by
React, like `key` and (before React 19) `ref`. These are not actual
props and are not observable by the target component; React uses them
internally but removes them from the props object before passing them to
userspace.

The second reason is that the classic JSX runtime, `createElement`, is
both a compiler target _and_ a public API that can be called manually.
Therefore, we can't assume that the props object that is passed into
`createElement` won't be mutated by userspace code after it is passed
in.

However, the new JSX runtime, `jsx`, is not a public API — it's solely a
compiler target, and the compiler _will_ always pass a fresh, inline
object. So the only reason to clone the props is if a reserved prop name
is used.

In React 19, `ref` is no longer a reserved prop name, and `key` will
only appear in the props object if it is spread onto the element.
(Because if `key` is statically defined, the compiler will pass it as a
separate argument to the `jsx` function.) So the only remaining reason
to clone the props object is if `key` is spread onto the element, which
is a rare case, and also triggers a warning in development.

In a future release, we will not remove a spread key from the props
object. (But we'll still warn.) We'll always pass the object straight
through.

The expected impact is much faster JSX element creation, which in many
apps is a significant slice of the overall runtime cost of rendering.

DiffTrain build for [d1547defe3](https://github.com/facebook/react/commit/d1547defe34cee6326a61059148afc83228d8ecf)
2024-04-05 17:30:21 +00:00
acdlite c7d55de717 Make class prop resolution faster (#28766)
`delete` causes an object (in V8, and maybe other engines) to deopt to a
dictionary instead of a class. Instead of `assign` + `delete`, manually
iterate over all the properties, like the JSX runtime does.

To avoid copying the object twice I moved the `ref` prop removal to come
before handling default props. If we already cloned the props to remove
`ref`, then we can skip cloning again to handle default props.

DiffTrain build for [bfd8da807c](https://github.com/facebook/react/commit/bfd8da807c75a2d123627415f9eaf2d36ac3ed6a)
2024-04-05 17:11:28 +00:00
sebmarkbage 1d8cde0408 [Flight] Support Blobs from Server to Client (#28755)
We currently support Blobs when passing from Client to Server so this
adds it in the other direction for parity - when `enableFlightBinary` is
enabled.

We intentionally only support the `Blob` type to pass-through, not
subtype `File`. That's because passing additional meta data like
filename might be an accidental leak. You can still pass a `File`
through but it'll appear as a `Blob` on the other side. It's also not
possible to create a faithful File subclass in all environments without
it actually being backed by a file.

This implementation isn't great but at least it works. It creates a few
indirections. This is because we need to be able to asynchronously emit
the buffers but we have to "block" the parent object from resolving
while it's loading.

Ideally, we should be able to create the Blob on the client early and
then stream in it lazily. Because the Blob API doesn't guarantee that
the data is available synchronously. Unfortunately, the native APIs
doesn't have this. We could implement custom versions of all the data
read APIs but then the blobs still wouldn't work with native APIs. So we
just have to wait until Blob accepts a stream in the constructor.

We should be able to stream each chunk early in the protocol though even
though we can't unblock the parent until they've all loaded. I didn't do
this yet mostly because of code structure and I'm lazy.

DiffTrain build for [cbb6f2b546](https://github.com/facebook/react/commit/cbb6f2b5461cdce282c7e47b9c68a0897d393383)
2024-04-05 16:54:31 +00:00
sebmarkbage 75004cde87 Track Owner for Server Components in DEV (#28753)
This implements the concept of a DEV-only "owner" for Server Components.
The owner concept isn't really super useful. We barely use it anymore,
but we do have it as a concept in DevTools in a couple of cases so this
adds it for parity. However, this is mainly interesting because it could
be used to wire up future owner-based stacks.

I do this by outlining the DebugInfo for a Server Component
(ReactComponentInfo). Then I just rely on Flight deduping to refer to
that. I refer to the same thing by referential equality so that we can
associate a Server Component parent in DebugInfo with an owner.

If you suspend and replay a Server Component, we have to restore the
same owner. To do that, I did a little ugly hack and stashed it on the
thenable state object. Felt unnecessarily complicated to add a stateful
wrapper for this one dev-only case.

The owner could really be anything since it could be coming from a
different implementation. Because this is the first time we have an
owner other than Fiber, I have to fix up a bunch of places that assumes
Fiber. I mainly did the `typeof owner.tag === 'number'` to assume it's a
Fiber for now.

This also doesn't actually add it to DevTools / RN Inspector yet. I just
ignore them there for now.

Because Server Components can be async the owner isn't tracked after an
await. We need per-component AsyncLocalStorage for that. This can be
done in a follow up.

DiffTrain build for [f33a6b69c6](https://github.com/facebook/react/commit/f33a6b69c6cb406ea0cc51d07bc4d3fd2d8d8744)
2024-04-05 16:53:53 +00:00
acdlite e6ea24b07b Move string ref coercion to JSX runtime (#28473)
Based on:

- #28464

---

This moves the entire string ref implementation out Fiber and into the
JSX runtime. The string is converted to a callback ref during element
creation. This is a subtle change in behavior, because it will have
already been converted to a callback ref if you access element.prop.ref
or element.ref. But this is only for Meta, because string refs are
disabled entirely in open source. And if it leads to an issue in
practice, the solution is to switch to a different ref type, which Meta
is going to do regardless.

DiffTrain build for [e3ebcd54b9](https://github.com/facebook/react/commit/e3ebcd54b98a4f8f5a9f7e63982fa75578b648ed)
2024-04-05 14:58:03 +00:00
acdlite 769be695f5 Remove defaultProps support (except for classes) (#28733)
This removes defaultProps support for all component types except for
classes. We've chosen to continue supporting defaultProps for classes
because lots of older code relies on it, and unlike function components,
(which can use default params), there's no straightforward alternative.

By implication, it also removes support for setting defaultProps on
`React.lazy` wrapper. So this will not work:

```js
const MyClassComponent = React.lazy(() => import('./MyClassComponent'));
// MyClassComponent is not actually a class; it's a lazy wrapper. So
// defaultProps does not work.
MyClassComponent.defaultProps = { foo: 'bar' };
```

However, if you set the default props on the class itself, then it's
fine.

For classes, this change also moves where defaultProps are resolved.
Previously, defaultProps were resolved by the JSX runtime. This change
is only observable if you introspect a JSX element, which is relatively
rare but does happen.

In other words, previously `<ClassWithDefaultProp />.props.aDefaultProp`
would resolve to the default prop value, but now it does not.

DiffTrain build for [48b4ecc901](https://github.com/facebook/react/commit/48b4ecc9012638ed51b275aad24b2086b8215e32)
2024-04-04 15:04:09 +00:00
sebmarkbage e0fc90e076 Use a Wrapper Error for onRecoverableError with a "cause" Field for the real Error (#28736)
We basically have four kinds of recoverable errors:

- Hydration mismatches.
- Server errored but client didn't.
- Hydration render errored but client render didn't (in Root or Suspense
boundary).
- Concurrent render errored but synchronous render didn't.

For the first three we log an additional error that the root or Suspense
boundary didn't error. This provides some context about what happened.
However, the problem is that for hydration mismatches that's unnecessary
extra context that is confusing. We also don't log any additional
context for concurrent render errors that could recover. This used to be
the only recoverable error so it didn't need extra context but now we
need to distinguish them. When we log these to `reportError` it's
confusing to just see the error because you didn't see anything error on
the page. It's also hard to group them together as one.

In this PR, I remove the unnecessary context for hydration mismatches.

For hydration and concurrent errors, I now wrap them in an error that
describes that what happened but then use the new `cause` field to link
the original error so we can keep that as the cause. The error that
happened was that hydration client rendered or you deopted to sync
render, the cause of that error is some other error.

For server errors, we control the Error object so I already had added
some context to that error object's message. Since we hide the message
in prod, it's nice not to have the raw message in DEV neither. We could
potentially split these into two errors for parity though.

DiffTrain build for [6090cab099](https://github.com/facebook/react/commit/6090cab099a8f7f373e04c7eb2937425a8f80f80)
2024-04-04 01:58:18 +00:00
sebmarkbage 2d934393d1 Emit Server Error Prefix in the .stack Property Too (#28738)
Follow up to #28684.

V8 includes the message in the stack and printed errors include just the
stack property which is assumed to contain the message. Without this,
the prefix doesn't get printed in the console.

<img width="578" alt="Screenshot 2024-04-03 at 6 32 04 PM"
src="https://github.com/facebook/react/assets/63648/d98a2db4-6ebc-4805-b669-59f449dfd21f">

A possible alternative would be to use a nested error with a `cause`
like #28736 but that would need some more involved serializing since
this prefix is coming from the server. Perhaps as a separate attribute.

DiffTrain build for [583eb6770d](https://github.com/facebook/react/commit/583eb6770d56e9793d3660bd9c6782fdebc93729)
2024-04-04 01:57:39 +00:00
kassens ce3ba22cf3 Cleanup enableUseRefAccessWarning flag (#28699)
Cleanup enableUseRefAccessWarning flag

I don't think this flag has a path forward in the current
implementation. The detection by stack trace is too brittle to detect
the lazy initialization pattern reliably (see e.g. some internal tests
that expect the warning because they use lazy intialization, but a
slightly different pattern then the expected pattern.

I think a new version of this could be to fully ban ref access during
render with an alternative API for the exceptional cases that today
require ref access during render.

DiffTrain build for [20e710aeab](https://github.com/facebook/react/commit/20e710aeab3e03809c82d134171986ea270026a0)
2024-04-03 17:40:38 +00:00
acdlite a491103917 Classes consume ref prop during SSR, too (#28731)
Same as #28719 but for SSR.

DiffTrain build for [3761acb42b](https://github.com/facebook/react/commit/3761acb42bf9979314fff130d4d9505408bcb651)
2024-04-03 17:00:46 +00:00
kassens 6cdcf5b723 Cleanup enableBigIntSupport flag (#28711)
Cleanup enableBigIntSupport flag

DiffTrain build for [7a2609eedc](https://github.com/facebook/react/commit/7a2609eedc571049a3272e60d5f7d84601ffca3f)
2024-04-03 13:30:33 +00:00
gnoff 3d513cacac [FB] use modern entrypoint in tests (#28724)
Removes the entrypoint hack in tests since we gate legacy mode tests now

DiffTrain build for [cb6dc7a6a0](https://github.com/facebook/react/commit/cb6dc7a6a03ea10a38b84e9e5737739e0d468435)
2024-04-03 05:30:00 +00:00
acdliteandJan Kassens dceb5b2168 Fix: Class components should "consume" ref prop (#28719)
When a ref is passed to a class component, the class instance is
attached to the ref's current property automatically. This different
from function components, where you have to do something extra to attach
a ref to an instance, like passing the ref to `useImperativeHandle`.

Existing class component code is written with the assumption that a ref
will not be passed through as a prop. For example, class components that
act as indirections often spread `this.props` onto a child component. To
maintain this expectation, we should remove the ref from the props
object ("consume" it) before passing it to lifecycle methods. Without
this change, much existing code will break because the ref will attach
to the inner component instead of the outer one.

This is not an issue for function components because we used to warn if
you passed a ref to a function component. Instead, you had to use
`forwardRef`, which also implements this "consuming" behavior.

There are a few places in the reconciler where we modify the fiber's
internal props object before passing it to userspace. The trickiest one
is class components, because the props object gets exposed in many
different places, including as a property on the class instance.

This was already accounted for when we added support for setting default
props on a lazy wrapper (i.e. `React.lazy` that resolves to a class
component).

In all of these same places, we will also need to remove the ref prop
when `enableRefAsProp` is on.

Closes #28602

---------

Co-authored-by: Jan Kassens <jan@kassens.net>

DiffTrain build for [dc545c8d6e](https://github.com/facebook/react/commit/dc545c8d6eaca87c8d5cabfab6e1c768ecafe426)
2024-04-03 03:19:53 +00:00
sebmarkbageandJosh Story 2a92b785ac Move ReactDOMLegacy implementation into RootFB (#28656)
Only the FB entry point has legacy mode now so we can move the remaining
code in there.

Also enable disableLegacyMode in modern www builds since it doesn't
expose those entry points.

Now dependent on #28709.

---------

Co-authored-by: Josh Story <story@hey.com>

DiffTrain build for [8f55a6aa57](https://github.com/facebook/react/commit/8f55a6aa5739ed8ca80c3066fb54f4ea4cfe600a)
2024-04-03 02:01:04 +00:00
sebmarkbage 72e3e579fe Use the disableLegacyMode where ever we check the ConcurrentMode mode (#28657)
Saves some bytes and ensures that we're actually disabling it.

Turns out this flag wasn't disabling React Native/Fabric, React Noop and
React ART legacy modes so those are updated too.

Should be rebased on #28681.

DiffTrain build for [5de8703646](https://github.com/facebook/react/commit/5de8703646cdd3838cb1686f761b10c0692743aa)
2024-04-03 01:12:10 +00:00
gnoff 8d925e23b7 Reland #28672: Remove IndeterminateComponent (#28681)
This PR relands #28672 on top of the flag removal and the test
demonstrating a breakage in Suspense for legacy mode.

React has deprecated module pattern Function Components for many years
at this point. Supporting this pattern required React to have a concept
of an indeterminate component so that when a component first renders it
can turn into either a ClassComponent or a FunctionComponent depending
on what it returns. While this feature was deprecated and put behind a
flag it is still in stable. This change remvoes the flag, removes the
warnings, and removes the concept of IndeterminateComponent from the
React codebase.

While removing IndeterminateComponent type Seb and I discovered that we
needed a concept of IncompleteFunctionComponent to support Suspense in
legacy mode. This new work tag is only needed as long as legacy mode is
around and ideally any code that considers this tag will be excludable
from OSS builds once we land extra gates using `disableLegacyMode` flag.

DiffTrain build for [5998a77519](https://github.com/facebook/react/commit/5998a775194f491afa5d3badd9afe9ceaf12845e)
2024-04-03 00:48:04 +00:00
sebmarkbage 89feb7e2bc Make ART Concurrent if Legacy Mode is disabled (#28662)
Pulling this out of #28657.

This runs react-art in concurrent mode if disableLegacyMode is true.
Effectively this means that the OSS version will be in concurrent mode
and the `.modern.js` version for Meta will be in concurrent mode, once
the flag flips for modern, but the `.classic.js` version for Meta will
be in legacy mode.

Updates flowing in from above flush synchronously so that they commit as
a unit. This also ensures that refs are resolved before the parent life
cycles. setStates deep in the tree will now be batched using "discrete"
priority but should still happen same task.

DiffTrain build for [5fcaa0a832](https://github.com/facebook/react/commit/5fcaa0a832db9573364cb73738e0a3b4cf2d27f2)
2024-04-02 19:05:34 +00:00
josephsavona 8a319a658f [be] Remove unused, experimental getCacheSignal API (#28706)
Similar to #28698, this removes the `unstable_getCacheSignal()` API
since we don't intend to ship this to stable.

DiffTrain build for [8cb6a1c034](https://github.com/facebook/react/commit/8cb6a1c0347a69ad4c580c5cf5f28d8be544d6d4)
2024-04-02 18:00:11 +00:00
sebmarkbage 385c181896 Differentiate null and undefined in Custom Elements - removing sets to undefined (#28716)
In React DOM, in general, we don't differentiate between `null` and
`undefined` because we expect to target DOM APIs. When we're setting a
property on a Custom Element, in the new heuristic, the goal is to allow
passing whatever data type instead of normalizing it. Switching between
`undefined` and `null` as an explicit value should therefore be
respected.

However, in this mode if `undefined` is used for the initial value, we
don't actually set the property at all. If passing `null` we will now
initialize it to the value `null`. Meaning `undefined` kind of
represents the default.

### Removing Properties

There is a pretty complex edge case which is what should happen when a
prop used to exist but was removed from the props object. This doesn't
have any kind of defined semantics. It really should mean - return to
"default". Because in the declarative world it means the same as if it
was just created - i.e. we can't just leave it as it was.

The closest might be `delete object.property` but that's not really the
intended way that properties on custom elements / classes are supposed
to operate. Additionally, for a property to even hit our heuristic it
must pass the `in` test and must exist to being with so the default must
have a value.

Since the point of these properties is to contain any kind of type,
there isn't really a conceptual default value. E.g. a numeric default
value might be zero `0` while a default string might be empty `""` and
default object might `null`. Additionally, the conceptual default can
really be initialized to anything. There's also varied precedence in the
ecosystem here and really no consensus. Anything we pick would be kind
of wrong, so we used to just pick `null`.

_The safest way to consume a Custom Element is to always pass the same
set of props._

JS does have a concept of a "default value" though and that is described
as the value `undefined`. That's why default argument / object property
initializers are initialized if the value is `undefined`.

The problem with using `undefined` as value is that [you shouldn't
actually ever set the value of a class property to
`undefined`](https://twitter.com/sebmarkbage/status/1774082540296388752).
A property should always be initialized to some value. It can't be left
missing and shouldn't be initialized to the value `undefined` for hidden
class optimizations. If we just mutate it to be `undefined` it would be
potentially bad for perf and shouldn't really be the value after
removing property - it should be returned to default.

Every property should really have a setter to be useful since it is what
is used to trigger reactivity when it changes. Sometimes you can just
use the properties passively when something else happens but most of the
time it should be a setter but to reach parity with DOM it should really
be always so that the active value can be normalized.

Those setters can have default argument initializers to represent what
the default value should be. Therefore Custom Element properties should
be used like this:

```js
class CustomElement extends HTMLElement {
  _textLabel = '';
  _price = 0;
  _items = null;

  constructor() {
    super();
  }
  set textLabel(value = '') {
    this._textLabel = value;
  }
  get textLabel() {
    return this._textLabel;
  }
  set price(value = 0) {
    this._price = value;
  }
  get price() {
    return this._price;
  }
  set items(value = null) {
    this._items = value;
  }
  get items() {
    return this._items;
  }
}
```

The default initializer can be used to initialize a value back to its
original default when `undefined` is passed to it. Therefore, we pass
`undefined`, not because we expect that to be the value of a property
but because that's the value that represents "return to default".

This fixes #28203 but not really for the reason specified in the issue.
We don't expect you to actually store the `undefined` value but to use a
setter to set the property to something else that represents the
default. When we initialize the element the first time, we won't set
anything if it's the value `undefined` so we assume that the property
initializers running in the constructor is going to set the same default
value as if we set the property to `undefined`.

cc @josepharhar

DiffTrain build for [48ec17b865](https://github.com/facebook/react/commit/48ec17b865f439754fcdaa289ef0aa98f15a05c2)
2024-04-02 15:53:29 +00:00
kassens 9350ce4976 Hardcode enableLegacyFBSupport flag (#28701)
Hardcode enableLegacyFBSupport flag

DiffTrain build for [ba5496d411](https://github.com/facebook/react/commit/ba5496d411a2d3067b5aae58b882aa2041807e77)
2024-04-02 15:40:00 +00:00
eps1lon 04e21650d0 Cleanup enableNewBooleanProps (#28712)
DiffTrain build for [28fc980ef2](https://github.com/facebook/react/commit/28fc980ef2c563e3086ae5b0b2e6293de48ae0d4)
2024-04-02 15:14:28 +00:00
kassens f21dee59c3 Remove dynamic www flag for disableInputAttributeSyncing (#28703)
Remove dynamic www flag for disableInputAttributeSyncing

DiffTrain build for [7659c4d9e0](https://github.com/facebook/react/commit/7659c4d9e0e4de2ec758c9a03ad7cbf07fc696d0)
2024-04-02 15:02:21 +00:00
josephsavona 4af8db7341 [be] Remove unshipped experimental <Cache> element type (#28698)
Removes the `<Cache />` element type since we're going with a simpler
caching strategy.

DiffTrain build for [7319c61b18](https://github.com/facebook/react/commit/7319c61b18274ee7e7c20bd2e533b93c922d8fe0)
2024-04-02 15:01:58 +00:00
rickhanlonii 58f641328e Land useModernStrictMode in www (#28696)
this has landed

DiffTrain build for [5ab97b7345](https://github.com/facebook/react/commit/5ab97b73457e2da72749322a1925a970a967f3bc)
2024-04-01 17:09:53 +00:00
sebmarkbage b50214b699 [Flight] Update stale blocked values in createModelResolver (#28669)
Alternative to #28620.

Instead of emitting lazy references to not-yet-emitted models in the
Flight Server, this fixes the observed issue in
https://github.com/unstubbable/ai-rsc-test/pull/1 by adjusting the lazy
model resolution in the Flight Client to update stale blocked root
models, before assigning them as chunk values. In addition, the element
props are not outlined anymore in the Flight Server to avoid having to
also handle their staleness in blocked elements.

fixes #28595

DiffTrain build for [93f91795a0](https://github.com/facebook/react/commit/93f91795a0c71bae4aadd7f082b91de0068a0f91)
2024-04-01 16:42:10 +00:00
sebmarkbage b1ac5c17c3 Finish cleaning up digest from onRecoverableError (#28686)
Don't need to track it separately on the captured value anymore.

Shouldn't be in the types.

I used a getter for the warning instead because Proxies are kind of
heavy weight options for this kind of warning. We typically use getters.

DiffTrain build for [df95577db0](https://github.com/facebook/react/commit/df95577db0d1d7ca383f281bc1d9e6ba5579bef2)
2024-03-30 22:37:02 +00:00
sebmarkbage 904602b276 Include regular stack trace in serialized errors from Fizz (#28684)
We previously only included the component stack.

Cleaned up the fields in Fizz server that wasn't using consistent hidden
classes in dev vs prod.

Added a prefix to errors serialized from server rendering. It can be a
bit confusing to see where this error came from otherwise since it
didn't come from elsewhere on the client. It's really kind of confusing
with other recoverable errors that happen on the client too.

DiffTrain build for [b9149cc6e6](https://github.com/facebook/react/commit/b9149cc6e6442389accf1f7c34a77ba2e6e52b5e)
2024-03-30 15:13:53 +00:00
sebmarkbage a180cdd8bf Don't let error boundaries catch errors during hydration (#28675)
When an error boundary catches an error during hydration it'll try to
render the error state which will then try to hydrate that state,
causing hydration warnings.

When an error happens inside a Suspense boundary during hydration, we
instead let the boundary catch it and restart a client render from
there. However, when it's in the root we instead let it fail the root
and do the sync recovery pass. This didn't consider that we might hit an
error boundary first so this just skips the error boundary in that case.

We should probably instead let the root do a concurrent client render in
this same pass instead to unify with Suspense boundaries.

DiffTrain build for [5d4b7587da](https://github.com/facebook/react/commit/5d4b7587da52dd81bc5c366b909c4511e2970cd1)
2024-03-29 20:48:18 +00:00
kassens 120239fa77 Remove React.createFactory (#27798)
`React.createFactory` has been long deprecated. This removes it for the
next release.

DiffTrain build for [2aed507a76](https://github.com/facebook/react/commit/2aed507a76a0b1524426c398897cbe47d80c51e5)
2024-03-29 20:34:34 +00:00
jackpope 2d29da831d Land enableNewBooleanProps everywhere (#28676)
Rolled out internally. Removing flag.

DiffTrain build for [6cd6ba703d](https://github.com/facebook/react/commit/6cd6ba703de77e332ab201518b6e30e47cd49aaf)
2024-03-29 20:07:15 +00:00
rickhanlonii fc94889933 Warn when using useFormState (#28668)
## Overview

useFormState has been replaced with useActionState. Warn when it's used.

Also removes the `experimental_useFormState` warnings.

DiffTrain build for [18812b645c](https://github.com/facebook/react/commit/18812b645c93a9c42f931fae57bbbab9c1f402b8)
2024-03-29 17:45:34 +00:00
sophiebits aa4213fc9b Revert "Remove zoom from special cases list" (#28673)
Reverts facebook/react#26631

This got specced: https://github.com/w3c/csswg-drafts/pull/9699

I left msZoom because it seems plausible someone will still be using it
for backwards compat.

DiffTrain build for [19c7c2929b](https://github.com/facebook/react/commit/19c7c2929be68f87cfa6b7947c4ab9ffc5608e48)
2024-03-29 17:44:00 +00:00
rickhanloniiandRicky Hanlon b34287d736 Land enableCustomElementPropertySupport for React 19 (#27450)
We've rolled out this flag internally on WWW. This PR removed flag
`enableCustomElementPropertySupport`

Test plan:
 -- `yarn test`

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

DiffTrain build for [eb510a3304](https://github.com/facebook/react/commit/eb510a33048fabd95d272b1c0b65f941e2909240)
2024-03-29 17:12:58 +00:00
kassens 9f9e660ceb Remove module pattern function component support (flag only) (#28671)
Remove module pattern function component support (flag only)

> This is a redo of #27742, but only including the flag removal,
excluding further simplifications.

The module pattern

```
function MyComponent() {
  return {
    render() {
      return this.state.foo
    }
  }
}
```

has been deprecated for approximately 5 years now. This PR removes
support for this pattern.

DiffTrain build for [a73c3450e1](https://github.com/facebook/react/commit/a73c3450e1b528fa6cb3e94fa4d4359c7a4b61f1)
2024-03-29 15:20:18 +00:00
rickhanlonii 87edb8c159 Revert "Remove module pattern function component support" (#28670)
This breaks internal tests, so must be something in the refactor. Since
it's the top commit let's revert and split into two PRs, one that
removes the flag and one that does the refactor, so we can find the bug.

DiffTrain build for [f269074723](https://github.com/facebook/react/commit/f2690747239533fa266612d2d4dd9ae88ea92fbc)
2024-03-29 14:15:23 +00:00
gnoff 60fecf15dd Remove module pattern function component support (#27742)
The module pattern

```
function MyComponent() {
  return {
    render() {
      return this.state.foo
    }
  }
}
```

has been deprecated for approximately 5 years now. This PR removes
support for this pattern. It also simplifies a number of code paths in
particular related to the concept of `IndeterminateComponent` types.

DiffTrain build for [cc56bed38c](https://github.com/facebook/react/commit/cc56bed38cbe5a5c76dfdc4e9c642fab4884a3fc)
2024-03-28 20:13:12 +00:00
rickhanlonii 69b2f2deb2 Noop unstable_batchedUpdates (#28120)
## Overview

`unstable_batchedUpdates` is effectively a no-op outside of legacy mode,
this PR makes it an actual no-op outside legacy mode.

DiffTrain build for [63651c49e0](https://github.com/facebook/react/commit/63651c49e068a04cdc6ee1e2fa9c6125167987d2)
2024-03-28 18:20:41 +00:00
gnoff 9d23ab1211 Add support for preload media to ReactDOM (#28635)
This PR adds support for `media` option to `ReactDOM.preload()`, which
is needed when images differ between screen sizes (for example mobile vs
desktop)

DiffTrain build for [78328c0c4d](https://github.com/facebook/react/commit/78328c0c4d70c9b9ee4ad2d6a2319c95e628dd2d)
2024-03-28 17:09:49 +00:00
rickhanlonii 66062f02d8 s/form state/action state (#28631)
Rename internals from "form state" to "action state"

DiffTrain build for [05797ccebd](https://github.com/facebook/react/commit/05797ccebd285999343ab4fb94eb542f84be23b1)
2024-03-28 15:42:51 +00:00
gnoff 2d8f86fbb4 [Fiber] Remove the digest property from errorInfo passed to onRecoverableError (#28222)
Removes the digest property from errorInfo passed to onRecoverableError
when handling an error propagated from the server. Previously we warned
in Dev but still provided the digest on the errorInfo object. This
change removes digest from error info but continues to warn if it is
accessed. The reason for retaining the warning is the version with the
warning was not released as stable but we will include this deprecated
removal in our next major so we should communicate this change at
runtime.

DiffTrain build for [299a9c0598](https://github.com/facebook/react/commit/299a9c0598576f7dba170771b1c0b821281b1e15)
2024-03-28 15:07:04 +00:00
sebmarkbage dec75c4f84 Don't log onRecoverableError if the current commit fail (#28665)
We didn't recover after all.

Currently we might log a recoverable error in the recovery pass. E.g.
the SSR server had an error. Then the client component fails to render
which errors again. This ends up double logging.

So if we fail to actually complete a fully successful commit, we ignore
any recoverable errors because we'll get real errors logged.

It's possible that this might cover up some other error that happened at
the same time.

DiffTrain build for [e10a7b5cd5](https://github.com/facebook/react/commit/e10a7b5cd541882a78ff659147c1a0294413ccb0)
2024-03-28 14:44:35 +00:00
sebmarkbage 3c7faae3ba Remove errorHydratingContainer (#28664)
I originally added this in #21021 but I didn't mention why and I don't
quite remember why. Maybe because there were no other message? However
at the time the recoverable errors mechanism didn't exist.

Today I believe all cases where this happens will trigger another
recoverable error. Namely these two:

https://github.com/facebook/react/blob/9f33f699e4f832971dc0f2047129f832655a3b6d/packages/react-reconciler/src/ReactFiberBeginWork.js#L1442-L1446

https://github.com/facebook/react/blob/9f33f699e4f832971dc0f2047129f832655a3b6d/packages/react-reconciler/src/ReactFiberBeginWork.js#L2962-L2965

Therefore this is just an extra unnecessary log.

DiffTrain build for [323b6e98a7](https://github.com/facebook/react/commit/323b6e98a76fe6ee721f10d327a9a682334d1a97)
2024-03-28 03:52:59 +00:00
rickhanlonii ab2961cf4d Dymanic favorSafetyOverHydrationPerf (#28663)
For rollout

DiffTrain build for [9f33f699e4](https://github.com/facebook/react/commit/9f33f699e4f832971dc0f2047129f832655a3b6d)
2024-03-27 21:49:44 +00:00
gnoff d78c623922 [react-dom] Remove findDOMNode from OSS builds (#28267)
In the next major `findDOMNode` is being removed. This PR removes the
API from the react-dom entrypoints for OSS builds and re-exposes the
implementation as part of internals.

`findDOMNode` is being retained for Meta builds and so all tests that
currently use it will continue to do so by accessing it from internals.
Once the replacement API ships in an upcoming minor any tests that were
using this API incidentally can be updated to use the new API and any
tests asserting `findDOMNode`'s behavior directly can stick around until
we remove it entirely (once Meta has moved away from it)

DiffTrain build for [9ad40b1440](https://github.com/facebook/react/commit/9ad40b1440a2c0b61530f3710e5dae3847611b9c)
2024-03-27 21:48:08 +00:00
gnoff a0d5dab6f7 [Fizz][Legacy] Remove renderToNodeStream (#28607)
Stacked on #28606

renderToNodeStream has been deprecated since React 18 with a warning
indicating users should upgrade to renderToPipeableStream. This change
removes renderToNodeStream

DiffTrain build for [8436bcca62](https://github.com/facebook/react/commit/8436bcca6287077a5409b3c9180f8af0361b16a5)
2024-03-27 19:07:24 +00:00
eps1lon 28afafe589 Deprecate act from react-dom/test-utils in favor of act from react (#28597)
DiffTrain build for [2b036d3f1f](https://github.com/facebook/react/commit/2b036d3f1f016fbe8b121d223d96f09e785b97e1)
2024-03-27 15:32:48 +00:00
sebmarkbage b758998431 Make onUncaughtError and onCaughtError Configurable (#28641)
Stacked on #28627.

This makes error logging configurable using these
`createRoot`/`hydrateRoot` options:

```
onUncaughtError(error: mixed, errorInfo: {componentStack?: ?string}) => void
onCaughtError(error: mixed, errorInfo: {componentStack?: ?string, errorBoundary?: ?React.Component<any, any>}) => void
onRecoverableError(error: mixed, errorInfo: {digest?: ?string, componentStack?: ?string}) => void
```

We already have the `onRecoverableError` option since before.

Overriding these can be used to implement custom error dialogs (with
access to the `componentStack`).

It can also be used to silence caught errors when testing an error
boundary or if you prefer not getting logs for caught errors that you've
already handled in an error boundary.

I currently expose the error boundary instance but I think we should
probably remove that since it doesn't make sense for non-class error
boundaries and isn't very useful anyway. It's also unclear what it
should do when an error is rethrown from one boundary to another.

Since these are public APIs now we can implement the
ReactFiberErrorDialog forks using these options at the roots of the
builds. So I unforked those files and instead passed a custom option for
the native and www builds.

To do this I had to fork the ReactDOMLegacy file into ReactDOMRootFB
which is a duplication but that will go away as soon as the FB fork is
the only legacy root.

DiffTrain build for [a053716077](https://github.com/facebook/react/commit/a0537160771bafae90c6fd3154eeead2f2c903e7)
2024-03-27 04:56:36 +00:00