Commit Graph
15963 Commits
Author SHA1 Message Date
sebmarkbage 0602001f3a Move Hydration Warnings from the DOM Config into the Fiber reconciliation (#28476)
Stacked on #28458.

This doesn't actually really change the messages yet, it's just a
refactor.

Hydration warnings can be presented either as HTML or React JSX format.
If presented as HTML it makes more sense to make that a DOM specific
concept, however, I think it's actually better to present it in terms of
React JSX.

Most of the time the errors aren't going to be something messing with
them at the HTML/HTTP layer. It's because the JS code does something
different. Most of the time you're working in just React. People don't
necessarily even know what the HTML form of it looks like. So this takes
the approach that the warnings are presented in React JSX in their rich
object form.

Therefore, I'm moving the approach to yield diff data to the reconciler
but it's the reconciler that's actually printing all the warnings.

DiffTrain build for [4b8dfd6215](https://github.com/facebook/react/commit/4b8dfd6215bf855402ae1a94cb0ae4f467afca9a)
2024-03-26 23:09:12 +00:00
jackpope 34ee899fef Use concurrent root in RTR (#28498)
Based on
- https://github.com/facebook/react/pull/28497
- https://github.com/facebook/react/pull/28419

Reusing the disableLegacyMode flag, we set ReactTestRenderer to always
render with concurrent root where legacy APIs are no longer available.
If disableLegacyMode is false, we continue to allow the
unstable_isConcurrent option determine the root type.

Also checking a global `IS_REACT_NATIVE_TEST_ENVIRONMENT` so we can
maintain the existing behavior for RN until we remove legacy root
support there.

DiffTrain build for [bb66aa3cef](https://github.com/facebook/react/commit/bb66aa3cef4e42aee790200d03cf7a82659da121)
2024-03-26 22:57:58 +00:00
sebmarkbage 71cc6ab810 Remove enableClientRenderFallbackOnTextMismatch flag (#28458)
Build on top of #28440.

This lets us remove the path where updates are tracked on differences in
text.

DiffTrain build for [84c84d72f1](https://github.com/facebook/react/commit/84c84d72f11ff1961a103b3cd59919876e48f759)
2024-03-26 22:00:41 +00:00
sebmarkbage 8ee89e3444 Remove legacy hydration mode (#28440)
While Meta is still using legacy mode and we can't remove completely,
Meta is not using legacy hydration so we should be able to remove that.

This is just the first step. Once removed, we can vastly simplify the
DOMConfig for hydration.

This will have to be rebased when tests are upgraded.

DiffTrain build for [670d61bea2](https://github.com/facebook/react/commit/670d61bea23470e980ba13c1c8441e375779b0b8)
2024-03-26 21:46:39 +00:00
rickhanlonii eb7de0442f Update error messages (#28652)
## Overview

The error messages that say:

> ReactDOM.hydrate is no longer supported in React 18

Don't make sense in the React 19 release. Instead, they should say:

> ReactDOM.hydrate was removed in React 19.

For legacy mode, they should say:

> ReactDOM.hydrate has not been supported since React 18.

DiffTrain build for [dbfbfb3312](https://github.com/facebook/react/commit/dbfbfb3312db019183ef92fd2ef110cc7d807e80)
2024-03-26 21:30:55 +00:00
sebmarkbage 17f0c67368 Remove zoom from special cases list (#26631)
Looks like [it's getting removed
anyway](https://groups.google.com/a/chromium.org/g/blink-dev/c/V7q43bgutbo/m/-7jneTl8CQAJ?pli=1).

Maybe should wait for a major though.

DiffTrain build for [f24cf4a1af](https://github.com/facebook/react/commit/f24cf4a1af4e677dd85fce66001eee42b75b1cf7)
2024-03-26 21:23:47 +00:00
rickhanlonii 66f3d77750 Remove unmountComponentAtNode outside of legacy mode (#28650)
DiffTrain build for [1a6d36b1a3](https://github.com/facebook/react/commit/1a6d36b1a3ec43cb5700e28d7315b3aa2822365d)
2024-03-26 20:37:28 +00:00
acdlite a6c58b8c4a Bump canary versions to v19-canary (#28646)
This bumps the canary versions to v19 to communicate that the next
release will be a major. Once this lands, we can start merging breaking
changes into `main`.

DiffTrain build for [56efb2e227](https://github.com/facebook/react/commit/56efb2e2271492288b1ba37c247df2a65d9046b7)
2024-03-26 19:35:48 +00:00
yungsters ed3c6afae1 Cleanup alwaysThrottleDisappearingFallbacks Flag (#28639)
## Summary

After realizing that this feature flag is entangled with
`alwaysThrottleRetries`, we're going to undo
https://github.com/facebook/react/pull/28550

## How did you test this change?

```
$ yarn test
$ yarn flow dom-browser
$ yarn flow dom-fb
$ yarn flow fabric
```

DiffTrain build for [6fd0cb9a9f](https://github.com/facebook/react/commit/6fd0cb9a9feeccea2f70d993dc2d53f11cab0b5d)
2024-03-26 17:06:43 +00:00
kassens fc5d9dbf94 Switch facebook-www build version to file content hash (#28633)
Unifies the React version string pattern with RN just to simplify the
build script a tiny bit and not have 2 mechanisms for the Meta-internal
build.

DiffTrain build for [95319ab5af](https://github.com/facebook/react/commit/95319ab5afd384f5858f7c080573b9736e6b2f9c)
2024-03-26 16:18:51 +00:00
kassens 07e6503fe1 Make enableBigIntSupport a dynamic flag for Meta (#28617)
Make enableBigIntSupport a dynamic flag for Meta

Should be an easy launch, but let's make this a dynamic flag to be safe.

DiffTrain build for [5a75f9e785](https://github.com/facebook/react/commit/5a75f9e78544fa6d052aff7fe99607e48f35b979)
2024-03-25 17:55:21 +00:00
kassens 97218a1e39 Cleanup enableFormActions flag (#28614)
Cleanup enableFormActions flag

DiffTrain build for [527ed72bfd](https://github.com/facebook/react/commit/527ed72bfd9f5c0045da468ad01db968a9961ad7)
2024-03-25 17:30:23 +00:00
rickhanlonii 01f55b75d9 Add React.useActionState (#28491)
## Overview

_Depends on https://github.com/facebook/react/pull/28514_

This PR adds a new React hook called `useActionState` to replace and
improve the ReactDOM `useFormState` hook.

## Motivation

This hook intends to fix some of the confusion and limitations of the
`useFormState` hook.

The `useFormState` hook is only exported from the `ReactDOM` package and
implies that it is used only for the state of `<form>` actions, similar
to `useFormStatus` (which is only for `<form>` element status). This
leads to understandable confusion about why `useFormState` does not
provide a `pending` state value like `useFormStatus` does.

The key insight is that the `useFormState` hook does not actually return
the state of any particular form at all. Instead, it returns the state
of the _action_ passed to the hook, wrapping it and returning a
trackable action to add to a form, and returning the last returned value
of the action given. In fact, `useFormState` doesn't need to be used in
a `<form>` at all.

Thus, adding a `pending` value to `useFormState` as-is would thus be
confusing because it would only return the pending state of the _action_
given, not the `<form>` the action is passed to. Even if we wanted to
tie them together, the returned `action` can be passed to multiple
forms, creating confusing and conflicting pending states during multiple
form submissions.

Additionally, since the action is not related to any particular
`<form>`, the hook can be used in any renderer - not only `react-dom`.
For example, React Native could use the hook to wrap an action, pass it
to a component that will unwrap it, and return the form result state and
pending state. It's renderer agnostic.

To fix these issues, this PR:
- Renames `useFormState` to `useActionState`
- Adds a `pending` state to the returned tuple
- Moves the hook to the `'react'` package

## Reference

The `useFormState` hook allows you to track the pending state and return
value of a function (called an "action"). The function passed can be a
plain JavaScript client function, or a bound server action to a
reference on the server. It accepts an optional `initialState` value
used for the initial render, and an optional `permalink` argument for
renderer specific pre-hydration handling (such as a URL to support
progressive hydration in `react-dom`).

Type:

```ts
function useActionState<State>(
        action: (state: Awaited<State>) => State | Promise<State>,
        initialState: Awaited<State>,
        permalink?: string,
    ): [state: Awaited<State>, dispatch: () => void, boolean];
```

The hook returns a tuple with:
- `state`: the last state the action returned
- `dispatch`: the method to call to dispatch the wrapped action
- `pending`: the pending state of the action and any state updates
contained

Notably, state updates inside of the action dispatched are wrapped in a
transition to keep the page responsive while the action is completing
and the UI is updated based on the result.

## Usage

The `useActionState` hook can be used similar to `useFormState`:

```js
import { useActionState } from "react"; // not react-dom

function Form({ formAction }) {
  const [state, action, isPending] = useActionState(formAction);

  return (
    <form action={action}>
      <input type="email" name="email" disabled={isPending} />
      <button type="submit" disabled={isPending}>
        Submit
      </button>
      {state.errorMessage && <p>{state.errorMessage}</p>}
    </form>
  );
}
```

But it doesn't need to be used with a `<form/>` (neither did
`useFormState`, hence the confusion):

```js
import { useActionState, useRef } from "react";

function Form({ someAction }) {
  const ref = useRef(null);
  const [state, action, isPending] = useActionState(someAction);

  async function handleSubmit() {
    // See caveats below
    await action({ email: ref.current.value });
  }

  return (
    <div>
      <input ref={ref} type="email" name="email" disabled={isPending} />
      <button onClick={handleSubmit} disabled={isPending}>
        Submit
      </button>
      {state.errorMessage && <p>{state.errorMessage}</p>}
    </div>
  );
}
```

## Benefits

One of the benefits of using this hook is the automatic tracking of the
return value and pending states of the wrapped function. For example,
the above example could be accomplished via:

```js
import { useActionState, useRef } from "react";

function Form({ someAction }) {
  const ref = useRef(null);
  const [state, setState] = useState(null);
  const [isPending, setIsPending] = useTransition();

  function handleSubmit() {
    startTransition(async () => {
      const response = await someAction({ email: ref.current.value });
      setState(response);
    });
  }

  return (
    <div>
      <input ref={ref} type="email" name="email" disabled={isPending} />
      <button onClick={handleSubmit} disabled={isPending}>
        Submit
      </button>
      {state.errorMessage && <p>{state.errorMessage}</p>}
    </div>
  );
}
```

However, this hook adds more benefits when used with render specific
elements like react-dom `<form>` elements and Server Action. With
`<form>` elements, React will automatically support replay actions on
the form if it is submitted before hydration has completed, providing a
form of partial progressive enhancement: enhancement for when javascript
is enabled but not ready.

Additionally, with the `permalink` argument and Server Actions,
frameworks can provide full progressive enhancement support, submitting
the form to the URL provided along with the FormData from the form. On
submission, the Server Action will be called during the MPA navigation,
similar to any raw HTML app, server rendered, and the result returned to
the client without any JavaScript on the client.

## Caveats
There are a few Caveats to this new hook:
**Additional state update**: Since we cannot know whether you use the
pending state value returned by the hook, the hook will always set the
`isPending` state at the beginning of the first chained action,
resulting in an additional state update similar to `useTransition`. In
the future a type-aware compiler could optimize this for when the
pending state is not accessed.

**Pending state is for the action, not the handler**: The difference is
subtle but important, the pending state begins when the return action is
dispatched and will revert back after all actions and transitions have
settled. The mechanism for this under the hook is the same as
useOptimisitic.

Concretely, what this means is that the pending state of
`useActionState` will not represent any actions or sync work performed
before dispatching the action returned by `useActionState`. Hopefully
this is obvious based on the name and shape of the API, but there may be
some temporary confusion.

As an example, let's take the above example and await another action
inside of it:

```js
import { useActionState, useRef } from "react";

function Form({ someAction, someOtherAction }) {
  const ref = useRef(null);
  const [state, action, isPending] = useActionState(someAction);

  async function handleSubmit() {
    await someOtherAction();

    // The pending state does not start until this call.
    await action({ email: ref.current.value });
  }

  return (
    <div>
      <input ref={ref} type="email" name="email" disabled={isPending} />
      <button onClick={handleSubmit} disabled={isPending}>
        Submit
      </button>
      {state.errorMessage && <p>{state.errorMessage}</p>}
    </div>
  );
}

```

Since the pending state is related to the action, and not the handler or
form it's attached to, the pending state only changes when the action is
dispatched. To solve, there are two options.

First (recommended): place the other function call inside of the action
passed to `useActionState`:

```js
import { useActionState, useRef } from "react";

function Form({ someAction, someOtherAction }) {
  const ref = useRef(null);
  const [state, action, isPending] = useActionState(async (data) => {
    // Pending state is true already.
    await someOtherAction();
    return someAction(data);
  });

  async function handleSubmit() {
    // The pending state starts at this call.
    await action({ email: ref.current.value });
  }

  return (
    <div>
      <input ref={ref} type="email" name="email" disabled={isPending} />
      <button onClick={handleSubmit} disabled={isPending}>
        Submit
      </button>
      {state.errorMessage && <p>{state.errorMessage}</p>}
    </div>
  );
}
```

For greater control, you can also wrap both in a transition and use the
`isPending` state of the transition:

```js
import { useActionState, useTransition, useRef } from "react";

function Form({ someAction, someOtherAction }) {
  const ref = useRef(null);

  // isPending is used from the transition wrapping both action calls.
  const [isPending, startTransition] = useTransition();

  // isPending not used from the individual action.
  const [state, action] = useActionState(someAction);

  async function handleSubmit() {
    startTransition(async () => {
      // The transition pending state has begun.
      await someOtherAction();
      await action({ email: ref.current.value });
    });
  }

  return (
    <div>
      <input ref={ref} type="email" name="email" disabled={isPending} />
      <button onClick={handleSubmit} disabled={isPending}>
        Submit
      </button>
      {state.errorMessage && <p>{state.errorMessage}</p>}
    </div>
  );
}
```

A similar technique using `useOptimistic` is preferred over using
`useTransition` directly, and is left as an exercise to the reader.

## Thanks

Thanks to @ryanflorence @mjackson @wesbos
(https://github.com/facebook/react/issues/27980#issuecomment-1960685940)
and [Allan
Lasser](https://allanlasser.com/posts/2024-01-26-avoid-using-reacts-useformstatus)
for their feedback and suggestions on `useFormStatus` hook.

DiffTrain build for [5c65b27587](https://github.com/facebook/react/commit/5c65b27587c0507d66a84e055de948fc62d471d4)
2024-03-22 17:08:27 +00:00
kassens 417f54eed6 Cleanup enableFloat flag (#28613)
Cleanup enableFloat flag

DiffTrain build for [208ceeb46c](https://github.com/facebook/react/commit/208ceeb46ca2838c9bf24cd341435f87b2d50569)
2024-03-22 16:27:43 +00:00
sebmarkbage 361d5a6d50 [Fizz] Recover from errors thrown by progressive enhancement form generation (#28611)
This a follow up to #28564. It's alternative to #28609 which takes
#28610 into account.

It used to be possible to return JSX from an action with
`useActionState`.

```js
async function action(errors, payload) {
  "use server";
  try {
    ...
  } catch (x) {
    return <div>Error message</div>;
  }
}
```

```js
const [errors, formAction] = useActionState(action);
return <div>{errors}</div>;
```

Returning JSX from an action is itself not anything problematic. It's
that it also has to return the previous state to the action reducer
again that's the problem. When this happens we accidentally could
serialize an Element back to the server.

I fixed this in #28564 so it's now blocked if you don't have a temporary
reference set.

However, you can't have that for the progressive enhancement case. The
reply is eagerly encoded as part of the SSR render. Typically you
wouldn't have these in the initial state so the common case is that they
show up after the first POST back that yields an error and it's only in
the no-JS case where this happens so it's hard to discover.

As noted in #28609 there's a security implication with allowing elements
to be sent across this kind of payload, so we can't just make it work.

When an error happens during SSR our general policy is to try to recover
on the client instead. After all, SSR is mainly a perf optimization in
React terms and it's not primarily intended for a no JS solution.

This PR takes the approach that if we fail to generate the progressive
enhancement payload. I.e. if the serialization of previous state /
closures throw. Then we fallback to the replaying semantics just client
actions instead which will succeed.

The effect of this is that this pattern mostly just works:

- First render in the typical case doesn't have any JSX in it so it just
renders a progressive enhanced form.
- If JS fails to hydrate or you click early we do a form POST. If that
hits an error and it tries to render it using JSX, then the new page
will render successfully - however this time with a Replaying form
instead.
- If you try to submit the form again it'll have to be using JS.

Meaning if you use JSX as the error return value of form state and you
make a first attempt that fails, then no JS won't work because either
the first or second attempt has to hydrate.

We have ideas for potentially optimizing away serializing unused
arguments like if you don't actually use previous state which would also
solve it but it wouldn't cover all cases such as if it was deeply nested
in complex state.

Another approach that I considered was to poison the prev state if you
passed an element back but let it through to the action but if you try
to render the poisoned value, it wouldn't work. The downside of this is
when to error. Because in the progressive enhancement case it wouldn't
error early but when you actually try to invoke it at which point it
would be too late to fallback to client replaying. It would probably
have to always error even on the client which is unfortunate since this
mostly just works as long as it hydrates.

DiffTrain build for [fee786a057](https://github.com/facebook/react/commit/fee786a057774ab687aff765345dd86fce534ab2)
2024-03-21 23:56:39 +00:00
eps1lonandAndrew Clark 6e5eaa6c92 Ensure dispatch from useFormState works in StrictMode (#28557)
Co-authored-by: Andrew Clark <git@andrewclark.io>

DiffTrain build for [8ef14cf242](https://github.com/facebook/react/commit/8ef14cf24219addedca3607dabb3bef37fb2e013)
2024-03-20 15:20:09 +00:00
sebmarkbage cc0b6cd97a [Flight] Encode React Elements in Replies as Temporary References (#28564)
Currently you can accidentally pass React Element to a Server Action. It
warns but in prod it actually works because we can encode the symbol and
otherwise it's mostly a plain object. It only works if you only pass
host components and no function props etc. which makes it potentially
error later. The first thing this does it just early hard error for
elements.

I made Lazy work by unwrapping though since that will be replaced by
Promises later which works.

Our protocol is not fully symmetric in that elements flow from Server ->
Client. Only the Server can resolve Components and only the client
should really be able to receive host components. It's not intended that
a Server can actually do something with them other than passing them to
the client.

In the case of a Reply, we expect the client to be stateful. It's
waiting for a response. So anything we can't serialize we can still pass
by reference to an in memory object. So I introduce the concept of a
TemporaryReferenceSet which is an opaque object that you create before
encoding the reply. This then stashes any unserializable values in this
set and encode the slot by id. When a new response from the Action then
returns we pass the same temporary set into the parser which can then
restore the objects. This lets you pass a value by reference to the
server and back into another slot.

For example it can be used to render children inside a parent tree from
a server action:

```
export async function Component({ children }) {
  "use server";
  return <div>{children}</div>;
}
```

(You wouldn't normally do this due to the waterfalls but for advanced
cases.)

A common scenario where this comes up accidentally today is in
`useActionState`.

```
export function action(state, formData) {
  "use server";
   if (errored) {
     return <div>This action <strong>errored</strong></div>;
   }
   return null;
}
```

```
const [errors, formAction] = useActionState(action);
return <div>{errors}<div>;
```

It feels like I'm just passing the JSX from server to client. However,
because `useActionState` also sends the previous state *back* to the
server this should not actually be valid. Before this PR this actually
worked accidentally. You get a DEV warning but it used to work in prod.
Once you do something like pass a client reference it won't work tho. We
could perhaps make client references work by stashing where we got them
from but it wouldn't work with all possible JSX.

By adding temporary references to the action implementation this will
work again - on the client. It'll also be more efficient since we don't
send back the JSX content that you shouldn't introspect on the server
anyway.

However, a flaw here is that the progressive enhancement of this case
won't work because we can't use temporary references for progressive
enhancement since there's no in memory stash. What is worse is that it
won't error if you hydrate. ~It also will error late in the example
above because the first state is "undefined" so invoking the form once
works - it errors on the second attempt when it tries to send the error
state back again.~ It actually errors on the first invocation because we
need to eagerly serialize "previous state" into the form. So at least
that's better.

I think maybe the solution to this particular pattern would be to allow
JSX to serialize if you have no temporary reference set, and remember
client references so that client references can be returned back to the
server as client references. That way anything you could send from the
server could also be returned to the server. But it would only deopt to
serializing it for progressive enhancement. The consequence of that
would be that there's a lot of JSX that might accidentally seem like it
should work but it's only if you've gotten it from the server before
that it works. This would have to have pair them somehow though since
you can't take a client reference from one implementation of Flight and
use it with another.

DiffTrain build for [83409a1fdd](https://github.com/facebook/react/commit/83409a1fdd14b2e5b33c587935a7ef552607780f)
2024-03-19 21:04:50 +00:00
yungsters 8cc2b728f0 Add alwaysThrottleDisappearingFallbacks Flag (#28550)
## Summary

Creates a new `alwaysThrottleDisappearingFallbacks` feature flag that
gates the changes from https://github.com/facebook/react/pull/26802
(instead of being controlled by `alwaysThrottleRetries`). The values of
this new flag mirror the current values of `alwaysThrottleRetries` such
that there is no behavior difference.

This additional feature flag allows us to incrementally validate the
change (arguably bug fix) from
https://github.com/facebook/react/pull/26802 independently from
`alwaysThrottleRetries`.

## How did you test this change?

```
$ yarn test
$ yarn flow dom-browser
$ yarn flow dom-fb
$ yarn flow fabric
```

DiffTrain build for [0aab065eb3](https://github.com/facebook/react/commit/0aab065eb3250a9714a62dc05587cbb571da7f71)
2024-03-18 18:20:35 +00:00
kassens 187dc167cd Performance: avoid triggering map deopt in V8 (#28569)
The shape of the objects changed by this PR are both created in 2
locations with 2 different shapes, which most JS engines won't like.
I've noticed this in particular in V8 while benchmarking production
code.

https://github.com/facebook/react/blob/1293047d6063f3508af15e68cca916660ded791e/packages/react-reconciler/src/ReactFiberCacheComponent.js#L66-L77

https://github.com/facebook/react/blob/1293047d6063f3508af15e68cca916660ded791e/packages/react-reconciler/src/ReactFiberHostContext.js#L47-L54

https://github.com/facebook/react/blob/1293047d6063f3508af15e68cca916660ded791e/packages/react-reconciler/src/ReactFiberHooks.js#L3530-L3531

https://github.com/facebook/react/blob/1293047d6063f3508af15e68cca916660ded791e/packages/react-reconciler/src/ReactFiberHooks.js#L3492-L3493

DiffTrain build for [4d686a2da1](https://github.com/facebook/react/commit/4d686a2da138cad9e76c7de9feadd81ca2aa29e5)
2024-03-18 15:58:28 +00:00
jackpope 0ef0a51c6c Update isConcurrent RTR option usage (#28546)
Reverting some of https://github.com/facebook/react/pull/27804 which
renamed this option to stable. This PR just replaces internal usage to
make upcoming PRs cleaner.

Keeping isConcurrent unstable for the next major release in order to
enable a broader deprecation of RTR and be consistent with concurrent
rendering everywhere for next major.
(https://github.com/facebook/react/pull/28498)
- Next major will use concurrent root
- The old behavior (legacy root by default, concurrent root with
unstable option) will be preserved for React Native until new
architecture is fully shipped.
- Flag and legacy root usage can be removed after RN dependency is
unblocked without an additional breaking change

DiffTrain build for [38327309a4](https://github.com/facebook/react/commit/38327309a4172a52cf94e8e264990bedafc1df6e)
2024-03-18 15:39:12 +00:00
gnoff d06d633cdb [Fizz] Prevent uncloned large precomputed chunks without relying on render-time assertions (#28568)
A while back we implemented a heuristic that if a chunk was large it was
assumed to be produced by the render and thus was safe to stream which
results in transferring the underlying object memory. Later we ran into
an issue where a precomputed chunk grew large enough to trigger this
hueristic and it started causing renders to fail because once a second
render had occurred the precomputed chunk would not have an underlying
buffer of bytes to send and these bytes would be omitted from the
stream. We implemented a technique to detect large precomputed chunks
and we enforced that these always be cloned before writing.
Unfortunately our test coverage was not perfect and there has been for a
very long time now a usage pattern where if you complete a boundary in
one flush and then complete a boundary that has stylehsheet dependencies
in another flush you can get a large precomputed chunk that was not
being cloned to be sent twice causing streaming errors.

I've thought about why we even went with this solution in the first
place and I think it was a mistake. It relies on a dev only check to
catch paired with potentially version specific order of operations on
the streaming side. This is too unreliable. Additionally the low limit
of view size for Edge is not used in Node.js but there is not real
justification for this.

In this change I updated the view size for edge streaming to match Node
at 2048 bytes which is still relatively small and we have no data one
way or another to preference 512 over this. Then I updated the assertion
logic to error anytime a precomputed chunk exceeds the size. This
eliminates the need to clone these chunks by just making sure our view
size is always larger than the largest precomputed chunk we can possibly
write. I'm generally in favor of this for a few reasons.

First, we'll always know during testing whether we've violated the limit
as long as we exercise each stream config because the precomputed chunks
are created in module scope. Second, we can always split up large chunks
so making sure the precomptued chunk is smaller than whatever view size
we actually desire is relatively trivial.

DiffTrain build for [b09e102ff1](https://github.com/facebook/react/commit/b09e102ff1e2aaaf5eb6585b04609ac7ff54a5c8)
2024-03-16 19:43:36 +00:00
jackpope cb7bf992ee Make enableNewBooleanProps www dynamic (#28559)
Feature: https://github.com/facebook/react/pull/24730

DiffTrain build for [a870b2d549](https://github.com/facebook/react/commit/a870b2d5494351d75b68c3d9baf03a52fd40a8ef)
2024-03-14 15:54:04 +00:00
kassens 809d7d488a Fix a spelling mistake. (#28555)
DiffTrain build for [9ffe9102ff](https://github.com/facebook/react/commit/9ffe9102ffd08ca7a56c60aa6952208890d213ce)
2024-03-14 14:08:59 +00:00
eps1lon b18936efc1 React DOM: Support boolean values for inert prop (#24730)
DiffTrain build for [bbc571aee4](https://github.com/facebook/react/commit/bbc571aee431d44799ae6a70832ea834325a5af9)
2024-03-13 22:14:51 +00:00
rickhanlonii 8e12d48171 Add pending state to useFormState (#28514)
## Overview

Adds a `pending` state to useFormState, which will be replaced by
`useActionState` in the next diff. We will keep `useFormState` around
for backwards compatibility, but functionally it will work the same as
`useActionState`, which has an `isPending` state returned.

DiffTrain build for [17eaacaac1](https://github.com/facebook/react/commit/17eaacaac167addf0c4358b4983f054073a0626d)
2024-03-12 19:54:22 +00:00
kassens 43ce284c19 Revert "Land enableClientRenderFallbackOnTextMismatch for www" (#28548)
We're looking to run further experiments on this.

Reverts facebook/react#28538

DiffTrain build for [3e6bc7d2d7](https://github.com/facebook/react/commit/3e6bc7d2d7098d9c8a30ba6e7a877df70f4d8d34)
2024-03-12 19:33:26 +00:00
kassens 7826bab7de Remove renderSubtreeIntoContainer_DO_NOT_USE (#28526)
Since D54648741 we no longer need this shim.

NOTE: There is still some work left to remove the
`unstable_renderSubtreeIntoContainer` export.

DiffTrain build for [eb33bd7477](https://github.com/facebook/react/commit/eb33bd74779df6e91c54a47e8f07b22b72a073c7)
2024-03-12 15:35:35 +00:00
sebmarkbage 43874233ca Remove invokeGuardedCallback and replay trick (#28515)
We broke the ability to "break on uncaught exceptions" by adding a
try/catch higher up in the scheduling. We're giving up on fixing that so
we can remove the replay trick inside an event handler.

The issue with that approach is that we end up double logging a lot of
errors in DEV since they get reported to the page.

It's also a lot of complexity around this feature.

DiffTrain build for [89021fb4ec](https://github.com/facebook/react/commit/89021fb4ec9aa82194b0788566e736a4cedfc0e4)
2024-03-12 00:20:53 +00:00
rickhanlonii 7f3682cb12 Land enableClientRenderFallbackOnTextMismatch for www (#28538)
This is landed, we can hardcode the flag

DiffTrain build for [56e20051c3](https://github.com/facebook/react/commit/56e20051c3c1611f9495081d01f1946184332c6b)
2024-03-11 15:44:29 +00:00
noahlemen eaaebddcb7 cleanup enableProfilerNestedUpdateScheduledHook feature flag (#28509)
## Summary

Looks like this was added years ago for instrumentation at meta that
never ended up rolling out. Should be safe to clean up.

## How did you test this change?
`yarn test`

DiffTrain build for [0d1ae5d753](https://github.com/facebook/react/commit/0d1ae5d753044fae99bc37a7815aa947447de3f8)
2024-03-11 15:41:11 +00:00
kassens 8506f82a4b Remove unused returnFiber (#28504)
There is no use of `returnFiber` here, it can be removed.

DiffTrain build for [64f354cf27](https://github.com/facebook/react/commit/64f354cf27a17c4e5b0dfcd908e47940cf947771)
2024-03-06 19:06:30 +00:00
sebmarkbage 401192f5a4 Move tail hydration mismatch back to hydration context (#28501)
In #23176 we added a special case in completeWork for SuspenseBoundaries
if they still have trailing children. However, that misses a case
because it doesn't log a recoverable error for the hydration mismatch.
So we get an error that we rerendered.

I think this special case was done to avoid contexts getting out of
sync. I don't know why we didn't just move where the pop happens though
so that's what I did here and let the regular pass throw instead. Seems
to be pass the tests.

DiffTrain build for [c11b196ae3](https://github.com/facebook/react/commit/c11b196ae3e2e3c5d143d9102b35a6b6fa97c849)
2024-03-06 01:58:04 +00:00
gnoff 6cf536e74c [Flight][Fizz][Fiber] Chain HostDispatcher implementations (#28488)
The idea here is that host dispatchers are not bound to renders so we
need to be able to dispatch to them at any time. This updates the
implementation to chain these dispatchers so that each renderer can
respond to the dispatch. Semantically we don't always want every
renderer to do this for instance if Fizz handles a float method we don't
want Fiber to as well so each dispatcher implementation can decide if it
makes sense to forward the call or not. For float methods server
disaptchers will handle the call if they can resolve a Request otherwise
they will forward. For client dispatchers they will handle the call and
always forward. The choice needs to be made for each dispatcher method
and may have implications on correct renderer import order. For now we
just live with the restriction that if you want to use server and client
together (such as renderToString in the browser) you need to import the
server renderer after the client renderer.

DiffTrain build for [113ab9af08](https://github.com/facebook/react/commit/113ab9af08c46e8a548a397154f5c9dfeb96ab6a)
2024-03-04 20:31:03 +00:00
gnoff 54b3557007 [DOM] disable legacy mode behind flag (#28468)
Adds a flag to disable legacy mode. Currently this flag is used to cause
legacy mode apis like render and hydrate to throw. This change also
removes render, hydrate, unmountComponentAtNode, and
unstable_renderSubtreeIntoContainer from the experiemntal entrypoint.
Right now for Meta builds this flag is off (legacy mode is still
supported). In OSS builds this flag matches __NEXT_MAJOR__ which means
it currently is on in experiemental. This means that after merging
legacy mode is effectively removed from experimental builds. While this
is a breaking change, experimental builds are not stable and users can
pin to older versions or update their use of react-dom to no longer use
legacy mode APIs.

DiffTrain build for [1c02b9d2bd](https://github.com/facebook/react/commit/1c02b9d2bdc18091cc6afec810fc1b361f00abdd)
2024-03-04 16:23:02 +00:00
rickhanlonii fb789a0c0f Fix Broken Links In Documentation (#28321)
## Summary

I used [link-inspector](https://github.com/justindhillon/link-inspector)
to find a bunch of broken links in this projects documentation. Here is
what I fixed:

https://www.html5rocks.com/en/tutorials/canvas/hidpi/ -->
https://web.dev/articles/canvas-hidipi

https://w3c.github.io/webcomponents/spec/custom/#custom-elements-core-concepts
--> https://www.w3.org/TR/custom-elements/

https://github.com/facebookarchive/fixed-data-table/blob/main/src/vendor_upstream/dom/normalizeWheel.js
-->
https://github.com/facebookarchive/fixed-data-table/blob/master/src/vendor_upstream/dom/normalizeWheel.js

https://upload.wikimedia.org/wikipedia/commons/e/ee/Atom_%282%29.png -->
https://upload.wikimedia.org/wikipedia/commons/1/1b/Atom.png

## Support my work

I used [link-inspector](https://github.com/justindhillon/link-inspector)
to find and fix this issue. If you find this PR useful, give the repo a


DiffTrain build for [034130c02f](https://github.com/facebook/react/commit/034130c02ffb47b0026059b57d17e9b080976ff3)
2024-03-03 22:48:08 +00:00
rickhanlonii a8b2c8234f Update /link URLs to react.dev (#28477)
Depends on https://github.com/reactjs/react.dev/pull/6670 [merged]

DiffTrain build for [1940cb27b2](https://github.com/facebook/react/commit/1940cb27b260c2eab79c76763d1151ba18353ff8)
2024-03-03 22:39:44 +00:00
acdlite 6e4aad30ee Move ref type check to receiver (#28464)
The runtime contains a type check to determine if a user-provided ref is
a valid type — a function or object (or a string, when
`disableStringRefs` is off). This currently happens during child
reconciliation. This changes it to happen only when the ref is passed to
the component that the ref is being attached to.

This is a continuation of the "ref as prop" change — until you actually
pass a ref to a HostComponent, class, etc, ref is a normal prop that has
no special behavior.

DiffTrain build for [2f8f776022](https://github.com/facebook/react/commit/2f8f7760223241665f472a2a9be16650473bce39)
2024-03-01 02:30:27 +00:00
rickhanlonii df4b99cde1 Clean up empty string special cases (#28475)
This was fixed in https://github.com/facebook/react/pull/22807 so we
don't need these special cases anymore.

DiffTrain build for [bb4b147da9](https://github.com/facebook/react/commit/bb4b147da9a892529995f55f15f19f46a00cf4f6)
2024-03-01 01:31:25 +00:00
eps1lon b45dfdeccb Remove ReactTestUtils from ReactJSXElementValidator (#28335)
DiffTrain build for [e7849b50bc](https://github.com/facebook/react/commit/e7849b50bcefc0742ca342d70284d82cfcf990e5)
2024-02-27 23:15:49 +00:00
acdlite d76cf6bbfe Remove string refs (behind flag) (#28322)
Depends on:

- https://github.com/facebook/react/pull/28398

---

This removes string refs, which has been deprecated in Strict Mode for
seven years.

I've left them behind a flag for Meta, but in open source this fully
removes the feature.

DiffTrain build for [c9798954e2](https://github.com/facebook/react/commit/c9798954e26a2354a951cc65607f2901a45bf035)
2024-02-27 16:46:52 +00:00
noahlemen 9509de9485 clean up isInputPending in Scheduler (#28444)
## Summary

`isInputPending` is not in use. This PR cleans up the flags controlling
its gating and parameters to simplify Scheduler.

Makes `frameYieldMs` feature flag static, set to 10ms in www, which we
found built on the wins provided by a broader yield interval via
`isInputPending`. Flag remains set to 5ms in OSS builds.

## How did you test this change?
`yarn test Scheduler`

DiffTrain build for [3bcd2de01b](https://github.com/facebook/react/commit/3bcd2de01b5716202eabe8faa338f51bdc59ce26)
2024-02-27 15:43:42 +00:00
eps1lon b29a80f506 Add support for rendering BigInt (#24580)
DiffTrain build for [2f240c91ed](https://github.com/facebook/react/commit/2f240c91ed54900adee213565cb2039e161629e9)
2024-02-26 18:23:44 +00:00
rickhanlonii 1c19e014bb Turn on enableRenderableContext for www (#28438)
We can land for www now

DiffTrain build for [6c3b8dbfed](https://github.com/facebook/react/commit/6c3b8dbfed6f879440f484bd0bf801fac67ec684)
2024-02-26 15:13:53 +00:00
rickhanlonii d303b62c2f Make enableClientRenderFallbackOnText dynamic (#28436)
DiffTrain build for [239d06e2b8](https://github.com/facebook/react/commit/239d06e2b8b0f2dabd6bc154e5f24d594ac5840d)
2024-02-25 18:25:43 +00:00
eps1lon 4f260c3698 devtools: Use context displayName for context hook name (#25954)
DiffTrain build for [aed00dacfb](https://github.com/facebook/react/commit/aed00dacfb79d17c53218404c52b1c7aa59c4a89)
2024-02-24 10:59:18 +00:00
acdlite 28fcf2f1c7 Delete use of source in JSX runtime (#28433)
Only remaining place it was being used was in a warning message.

DiffTrain build for [16d3f7833d](https://github.com/facebook/react/commit/16d3f7833d25b1ea026add83dd109601b60f138e)
2024-02-23 21:56:58 +00:00
sebmarkbage d7e7f6ccbf Remove method name prefix from warnings and errors (#28432)
This pattern is a petpeeve of mine. I don't consider this best practice
and so most don't have these prefixes. Very inconsistent.

At best this is useless and noisey that you have to parse because the
information is also in the stack trace.

At worse these are misleading because they're highlighting something
internal (like validateDOMNesting) which even suggests an internal bug.
Even the ones public to React aren't necessarily what you called because
you might be calling a wrapper around it.

That would be properly reflected in a stack trace - which can also
properly ignore list so that the first stack you see is your callsite,

Which might be like `render()` in react-testing-library rather than
`createRoot()` for example.

DiffTrain build for [d579e77482](https://github.com/facebook/react/commit/d579e7748218920331252b0528850943d5e2dd31)
2024-02-23 20:21:58 +00:00
sebmarkbage 6535b044d2 Include server component names in the componentStack in DEV (#28415)
I'm a bit ambivalent about this one because it's not the main strategy
that I plan on pursuing. I plan on replacing most DEV-only specific
stacks like `console.error` stacks with a new take on owner stacks and
native stacks. The future owner stacks may or may not be exposed to
error boundaries in DEV but if they are they'd be a new errorInfo
property since they're owner based and not available in prod.

The use case in `console.error` mostly goes away in the future so this
PR is mainly for error boundaries. It doesn't hurt to have it in there
while I'm working on the better stacks though.

The `componentStack` property exposed to error boundaries is more like
production behavior similar to `new Error().stack` (which even in DEV
won't ever expose owner stacks because `console.createTask` doesn't
affect these). I'm not sure it's worth adding server components in DEV
(this PR) because then you have forked behavior between dev and prod.

However, since even in the future there won't be any other place to get
the *parent* stack, maybe this can be useful information even if it's
only dev. We could expose a third property on errorInfo that's DEV only
and parent stack but including server components. That doesn't seem
worth it over just having the stack differ in dev and prod.

I don't plan on adding line/column number to these particular stacks.

A follow up could be to add this to Fizz prerender too but only in DEV.

DiffTrain build for [8fb0233a84](https://github.com/facebook/react/commit/8fb0233a845974b4b1049e54b6c25dc54d6dd173)
2024-02-23 17:10:11 +00:00
jackpope edd8fbef41 [RTR] Add usage warning behind flag (#27903)
## Summary

Moving towards deprecation of ReactTestRenderer. Log a warning on each
render so we can remove the exports in a future major version.

We can enable this flag in web RTR without disrupting RN tests by
flipping the flag in
`packages/shared/forks/ReactFeatureFlags.test-renderer.js`

## How did you test this change?

`yarn test
packages/react-test-renderer/src/__tests__/ReactTestRenderer-test.js`

DiffTrain build for [66c8346401](https://github.com/facebook/react/commit/66c8346401d271588e4c400921c5dab5478fc623)
2024-02-23 16:38:05 +00:00
rickhanlonii ec5b61a29b Make enableRefAsProp www dynamic (#28423)
Going to start rolling this out

DiffTrain build for [aaf85f3af8](https://github.com/facebook/react/commit/aaf85f3af8c30252edaab5c24975cd086937b2a4)
2024-02-22 20:40:32 +00:00